Updated volume shaders to use the GL_LIGHT 0 values to control the direction of the light source

This commit is contained in:
Robert Osfield
2011-10-27 16:33:18 +00:00
parent 3a64805d20
commit 98d50250ff
5 changed files with 25 additions and 9 deletions

View File

@@ -5,13 +5,13 @@ char volume_iso_frag[] = "uniform sampler3D baseTexture;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
"varying vec3 lightDirection;\n"
"varying mat4 texgen;\n"
"\n"
"void main(void)\n"
"{ \n"
" vec4 t0 = vertexPos;\n"
" vec4 te = cameraPos;\n"
" vec3 eyeDirection = normalize((te-t0).xyz);\n"
"\n"
" if (te.x>=0.0 && te.x<=1.0 &&\n"
" te.y>=0.0 && te.y<=1.0 &&\n"
@@ -103,13 +103,14 @@ char volume_iso_frag[] = "uniform sampler3D baseTexture;\n"
" if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0)\n"
" {\n"
" vec3 normal = normalize(grad);\n"
" float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection))*0.9;\n"
" float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9;\n"
"\n"
" color.x = lightScale;\n"
" color.y = lightScale;\n"
" color.z = lightScale;\n"
" }\n"
"\n"
"\n"
" color.a = 1.0;\n"
"\n"
" gl_FragColor = color;\n"

View File

@@ -5,6 +5,7 @@ char volume_lit_frag[] = "uniform sampler3D baseTexture;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
"varying vec3 lightDirection;\n"
"varying mat4 texgen;\n"
"\n"
"void main(void)\n"
@@ -60,8 +61,6 @@ char volume_lit_frag[] = "uniform sampler3D baseTexture;\n"
" t0 = t0 * texgen;\n"
" te = te * texgen;\n"
"\n"
" vec3 eyeDirection = normalize((te-t0).xyz);\n"
"\n"
" const float max_iteratrions = 2048.0;\n"
" float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n"
" if (num_iterations<2.0) num_iterations = 2.0;\n"
@@ -97,7 +96,7 @@ char volume_lit_frag[] = "uniform sampler3D baseTexture;\n"
" if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0)\n"
" {\n"
" vec3 normal = normalize(grad);\n"
" float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection))*0.9;\n"
" float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9;\n"
"\n"
" color.x *= lightScale;\n"
" color.y *= lightScale;\n"

View File

@@ -10,6 +10,7 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
"varying vec3 lightDirection;\n"
"varying mat4 texgen;\n"
"\n"
"void main(void)\n"
@@ -103,7 +104,7 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n"
" if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0)\n"
" {\n"
" vec3 normal = normalize(grad);\n"
" float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection))*0.9;\n"
" float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9;\n"
"\n"
" color.x *= lightScale;\n"
" color.y *= lightScale;\n"

View File

@@ -10,13 +10,13 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n"
"\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
"varying vec3 lightDirection;\n"
"varying mat4 texgen;\n"
"\n"
"void main(void)\n"
"{ \n"
" vec4 t0 = vertexPos;\n"
" vec4 te = cameraPos;\n"
" vec3 eyeDirection = normalize((te-t0).xyz);\n"
"\n"
" if (te.x>=0.0 && te.x<=1.0 &&\n"
" te.y>=0.0 && te.y<=1.0 &&\n"
@@ -110,7 +110,7 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n"
" if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0)\n"
" {\n"
" vec3 normal = normalize(grad);\n"
" float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection))*0.9;\n"
" float lightScale = 0.1 + max(0.0, dot(normal.xyz, lightDirection))*0.9;\n"
"\n"
" color.x *= lightScale;\n"
" color.y *= lightScale;\n"

View File

@@ -1,15 +1,30 @@
char volume_vert[] = "#version 110\n"
"varying vec4 cameraPos;\n"
"varying vec4 vertexPos;\n"
"varying vec3 lightDirection;\n"
"varying mat4 texgen;\n"
"\n"
"\n"
"void main(void)\n"
"{\n"
" gl_Position = ftransform();\n"
"\n"
" cameraPos = gl_ModelViewMatrixInverse*vec4(0,0,0,1);\n"
" cameraPos = gl_ModelViewMatrixInverse * vec4(0,0,0,1);\n"
" vertexPos = gl_Vertex;\n"
"\n"
" vec4 lightPosition = gl_ModelViewMatrixInverse * gl_LightSource[0].position;\n"
" if (lightPosition[3]==0.0)\n"
" {\n"
" // directional light source\n"
" lightDirection = -normalize(lightPosition.xyz);\n"
" }\n"
" else\n"
" {\n"
" // positional light source\n"
" lightDirection = normalize((lightPosition-vertexPos).xyz);\n"
" }\n"
"\n"
"\n"
" texgen = mat4(gl_ObjectPlaneS[0], \n"
" gl_ObjectPlaneT[0],\n"
" gl_ObjectPlaneR[0],\n"