|
4 | 4 | #include <vector> |
5 | 5 | #include <math.h> |
6 | 6 | #include <fstream> |
| 7 | +#include <ctime> |
7 | 8 |
|
8 | 9 | #include <glad\glad.h> |
9 | 10 | #include <GLFW\glfw3.h> |
@@ -60,6 +61,7 @@ bool fileExists(string fileName); |
60 | 61 | ostream& operator<<(ostream& out, const glm::vec3 &v); |
61 | 62 | istream& operator>>(istream& in, glm::vec3 &v); |
62 | 63 | void readGradientsFromFile(); |
| 64 | +GLuint GenerateNoiseTexture(); |
63 | 65 |
|
64 | 66 | //settings |
65 | 67 | const unsigned int SCR_WIDTH = 800; |
@@ -145,6 +147,8 @@ int main() |
145 | 147 | GLuint volumeTex = GenerateVolumeTexture(); |
146 | 148 | GLuint gradientTexture = loadGradientTexture(); |
147 | 149 |
|
| 150 | + GLuint noiseTex = GenerateNoiseTexture(); |
| 151 | + |
148 | 152 | cubeTransform.rotQuat = glm::quat(0.0f, 0.0f, 0.0f, 1.0f); |
149 | 153 |
|
150 | 154 | vector<TransferFunctionControlPoint> colorKnots = { |
@@ -332,7 +336,7 @@ int main() |
332 | 336 | //Render to display |
333 | 337 | //Render to the screen, to render to the screen. Use 0 as the second parameter of glBindFramebuffer |
334 | 338 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
335 | | - glClearColor(0.01f, 0.01f, 0.01f, 1.0f); |
| 339 | + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
336 | 340 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
337 | 341 | //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
338 | 342 | //glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); |
@@ -379,11 +383,15 @@ int main() |
379 | 383 | glBindTexture(GL_TEXTURE_1D, transferFuncTexture); |
380 | 384 | glUniform1i(glGetUniformLocation(currentRaycastShader->ID, "transferFuncTex"), 3); |
381 | 385 |
|
| 386 | + glActiveTexture(GL_TEXTURE4); |
| 387 | + glBindTexture(GL_TEXTURE_2D, noiseTex); |
| 388 | + glUniform1i(glGetUniformLocation(currentRaycastShader->ID, "noiseTex"), 4); |
| 389 | + |
382 | 390 | if (currentShaderIndex == 2) |
383 | 391 | { |
384 | | - glActiveTexture(GL_TEXTURE4); |
| 392 | + glActiveTexture(GL_TEXTURE5); |
385 | 393 | glBindTexture(GL_TEXTURE_3D, gradientTexture); |
386 | | - glUniform1i(glGetUniformLocation(currentRaycastShader->ID, "gradientTex"), 4); |
| 394 | + glUniform1i(glGetUniformLocation(currentRaycastShader->ID, "gradientTex"), 5); |
387 | 395 | } |
388 | 396 |
|
389 | 397 | //Draw Scene |
@@ -798,6 +806,32 @@ GLuint setUpEmptyTexture() |
798 | 806 | return textureID; |
799 | 807 | } |
800 | 808 |
|
| 809 | +//Stochastic Jittering Noise Texture |
| 810 | +GLuint GenerateNoiseTexture() |
| 811 | +{ |
| 812 | + GLuint noiseTex; |
| 813 | + int size = 32; |
| 814 | + unsigned char* buffer = new unsigned char[size*size]; |
| 815 | + srand((unsigned)time(NULL)); |
| 816 | + for (int i = 0; i < (size*size); i++) |
| 817 | + buffer[i] = 255.*rand() / (float)RAND_MAX; |
| 818 | + glGenTextures(1, &noiseTex); |
| 819 | + glBindTexture(GL_TEXTURE_2D, noiseTex); |
| 820 | + glTexImage2D( |
| 821 | + GL_TEXTURE_2D, // target |
| 822 | + 0, // level |
| 823 | + GL_RED, // internal |
| 824 | + size, // width |
| 825 | + size, // height |
| 826 | + 0, GL_RED, GL_UNSIGNED_BYTE, buffer); |
| 827 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 828 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 829 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 830 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 831 | + delete buffer; |
| 832 | + |
| 833 | + return noiseTex; |
| 834 | +} |
801 | 835 |
|
802 | 836 | GLuint computeTransferFunction(vector<TransferFunctionControlPoint> colorKnots, vector<TransferFunctionControlPoint> alphaKnots) |
803 | 837 | { |
|
0 commit comments