Changeset 10442
- Timestamp:
- 07/02/09 20:49:09 (4 years ago)
- Location:
- OpenSceneGraph-Data/trunk/shaders
- Files:
-
- 7 modified
-
volume.frag (modified) (3 diffs)
-
volume_iso.frag (modified) (3 diffs)
-
volume_lit.frag (modified) (3 diffs)
-
volume_lit_tf.frag (modified) (4 diffs)
-
volume_mip.frag (modified) (3 diffs)
-
volume_tf.frag (modified) (3 diffs)
-
volume_tf_iso.frag (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph-Data/trunk/shaders/volume.frag
r9517 r10442 10 10 void main(void) 11 11 { 12 vec 3 t0 = (texgen * vertexPos).xyz;13 vec 3 te = (texgen * cameraPos).xyz;12 vec4 t0 = vertexPos; 13 vec4 te = cameraPos; 14 14 15 15 if (te.x>=0.0 && te.x<=1.0 && … … 58 58 } 59 59 60 t0 = t0 * texgen; 61 te = te * texgen; 62 60 63 const float max_iteratrions = 2048.0; 61 float num_iterations = ceil(length( te-t0)/SampleDensityValue);64 float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue); 62 65 if (num_iterations<2.0) num_iterations = 2.0; 63 66 … … 67 70 } 68 71 69 vec3 deltaTexCoord=(te-t0) /float(num_iterations-1.0);70 vec3 texcoord = t0 ;72 vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0); 73 vec3 texcoord = t0.xyz; 71 74 72 75 vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); -
OpenSceneGraph-Data/trunk/shaders/volume_iso.frag
r10118 r10442 10 10 void main(void) 11 11 { 12 13 vec3 t0 = (texgen * vertexPos).xyz; 14 vec3 te = (texgen * cameraPos).xyz; 15 16 vec3 eyeDirection = normalize(te-t0); 12 vec4 t0 = vertexPos; 13 vec4 te = cameraPos; 14 vec3 eyeDirection = normalize((te-t0).xyz); 17 15 18 16 if (te.x>=0.0 && te.x<=1.0 && … … 61 59 } 62 60 61 t0 = t0 * texgen; 62 te = te * texgen; 63 63 64 const float max_iteratrions = 2048.0; 64 float num_iterations = ceil(length( te-t0)/SampleDensityValue);65 float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue); 65 66 if (num_iterations<2.0) num_iterations = 2.0; 66 67 … … 70 71 } 71 72 72 vec3 deltaTexCoord=(t0-te) /float(num_iterations-1.0);73 vec3 texcoord = te ;73 vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-1.0); 74 vec3 texcoord = te.xyz; 74 75 75 76 vec4 previousColor = texture3D( baseTexture, texcoord); -
OpenSceneGraph-Data/trunk/shaders/volume_lit.frag
r9611 r10442 10 10 void main(void) 11 11 { 12 vec3 t0 = (texgen * vertexPos).xyz; 13 vec3 te = (texgen * cameraPos).xyz; 14 15 vec3 eyeDirection = normalize(te-t0); 12 vec4 t0 = vertexPos; 13 vec4 te = cameraPos; 16 14 17 15 if (te.x>=0.0 && te.x<=1.0 && … … 60 58 } 61 59 60 t0 = t0 * texgen; 61 te = te * texgen; 62 63 vec3 eyeDirection = normalize((te-t0).xyz); 64 62 65 const float max_iteratrions = 2048.0; 63 float num_iterations = ceil(length( te-t0)/SampleDensityValue);66 float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue); 64 67 if (num_iterations<2.0) num_iterations = 2.0; 65 68 … … 69 72 } 70 73 71 vec3 deltaTexCoord=(te-t0) /float(num_iterations-1.0);72 vec3 texcoord = t0 ;74 vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0); 75 vec3 texcoord = t0.xyz; 73 76 74 77 float normalSampleDistance = 1.0/512.0; -
OpenSceneGraph-Data/trunk/shaders/volume_lit_tf.frag
r9611 r10442 11 11 void main(void) 12 12 { 13 vec3 t0 = (texgen * vertexPos).xyz; 14 vec3 te = (texgen * cameraPos).xyz; 15 16 vec3 eyeDirection = normalize(te-t0); 13 vec4 t0 = vertexPos; 14 vec4 te = cameraPos; 17 15 18 16 if (te.x>=0.0 && te.x<=1.0 && … … 61 59 } 62 60 61 t0 = t0 * texgen; 62 te = te * texgen; 63 64 vec3 eyeDirection = normalize((te-t0).xyz); 65 63 66 const float max_iteratrions = 2048.0; 64 float num_iterations = ceil(length( te-t0)/SampleDensityValue);67 float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue); 65 68 if (num_iterations<2.0) num_iterations = 2.0; 66 69 … … 70 73 } 71 74 72 vec3 deltaTexCoord=(te-t0) /float(num_iterations-1.0);73 vec3 texcoord = t0 ;75 vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0); 76 vec3 texcoord = t0.xyz; 74 77 75 78 float normalSampleDistance = 1.0/512.0; … … 77 80 vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0); 78 81 vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance); 79 82 80 83 vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); 81 84 while(num_iterations>0.0) -
OpenSceneGraph-Data/trunk/shaders/volume_mip.frag
r9517 r10442 10 10 void main(void) 11 11 { 12 vec 3 t0 = (texgen * vertexPos).xyz;13 vec 3 te = (texgen * cameraPos).xyz;12 vec4 t0 = vertexPos; 13 vec4 te = cameraPos; 14 14 15 15 if (te.x>=0.0 && te.x<=1.0 && … … 58 58 } 59 59 60 t0 = t0 * texgen; 61 te = te * texgen; 62 60 63 const float max_iteratrions = 2048.0; 61 float num_iterations = ceil(length( te-t0)/SampleDensityValue);64 float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue); 62 65 if (num_iterations<2.0) num_iterations = 2.0; 63 66 … … 67 70 } 68 71 69 vec3 deltaTexCoord=(te-t0) /float(num_iterations-1.0);70 vec3 texcoord = t0 ;72 vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0); 73 vec3 texcoord = t0.xyz; 71 74 72 75 vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); -
OpenSceneGraph-Data/trunk/shaders/volume_tf.frag
r9517 r10442 11 11 void main(void) 12 12 { 13 vec 3 t0 = (texgen * vertexPos).xyz;14 vec 3 te = (texgen * cameraPos).xyz;13 vec4 t0 = vertexPos; 14 vec4 te = cameraPos; 15 15 16 16 if (te.x>=0.0 && te.x<=1.0 && … … 59 59 } 60 60 61 t0 = t0 * texgen; 62 te = te * texgen; 63 61 64 const float max_iteratrions = 2048.0; 62 float num_iterations = ceil(length( te-t0)/SampleDensityValue);65 float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue); 63 66 if (num_iterations<2.0) num_iterations = 2.0; 64 67 … … 68 71 } 69 72 70 vec3 deltaTexCoord=(te-t0) /float(num_iterations-1.0);71 vec3 texcoord = t0 ;73 vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0); 74 vec3 texcoord = t0.xyz; 72 75 73 76 vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); -
OpenSceneGraph-Data/trunk/shaders/volume_tf_iso.frag
r9608 r10442 11 11 void main(void) 12 12 { 13 vec3 t0 = (texgen * vertexPos).xyz; 14 vec3 te = (texgen * cameraPos).xyz; 13 vec4 t0 = vertexPos; 14 vec4 te = cameraPos; 15 vec3 eyeDirection = normalize((te-t0).xyz); 15 16 16 vec3 eyeDirection = normalize(te-t0); 17 if (te.x>=0.0 && te.x<=1.0 && 18 te.y>=0.0 && te.y<=1.0 && 19 te.z>=0.0 && te.z<=1.0) 20 { 21 // do nothing... te inside volume 22 } 23 else 24 { 25 if (te.x<0.0) 26 { 27 float r = -te.x / (t0.x-te.x); 28 te = te + (t0-te)*r; 29 } 17 30 18 if (te.x>=0.0 && te.x<=1.0 && 19 te.y>=0.0 && te.y<=1.0 && 20 te.z>=0.0 && te.z<=1.0) 21 { 22 // do nothing... te inside volume 23 } 24 else 25 { 26 if (te.x<0.0) 27 { 28 float r = -te.x / (t0.x-te.x); 29 te = te + (t0-te)*r; 30 } 31 if (te.x>1.0) 32 { 33 float r = (1.0-te.x) / (t0.x-te.x); 34 te = te + (t0-te)*r; 35 } 31 36 32 if (te.x>1.0)33 {34 float r = (1.0-te.x) / (t0.x-te.x);35 te = te + (t0-te)*r;36 }37 if (te.y<0.0) 38 { 39 float r = -te.y / (t0.y-te.y); 40 te = te + (t0-te)*r; 41 } 37 42 38 if (te.y<0.0)39 {40 float r = -te.y/ (t0.y-te.y);41 te = te + (t0-te)*r;42 }43 if (te.y>1.0) 44 { 45 float r = (1.0-te.y) / (t0.y-te.y); 46 te = te + (t0-te)*r; 47 } 43 48 44 if (te.y>1.0)45 {46 float r = (1.0-te.y) / (t0.y-te.y);47 te = te + (t0-te)*r;48 }49 if (te.z<0.0) 50 { 51 float r = -te.z / (t0.z-te.z); 52 te = te + (t0-te)*r; 53 } 49 54 50 if (te.z<0.0) 51 { 52 float r = -te.z / (t0.z-te.z); 53 te = te + (t0-te)*r; 54 } 55 if (te.z>1.0) 56 { 57 float r = (1.0-te.z) / (t0.z-te.z); 58 te = te + (t0-te)*r; 59 } 60 } 55 61 56 if (te.z>1.0) 57 { 58 float r = (1.0-te.z) / (t0.z-te.z); 59 te = te + (t0-te)*r; 60 } 61 } 62 t0 = t0 * texgen; 63 te = te * texgen; 62 64 63 const float max_iteratrions = 2048.0;64 float num_iterations = ceil(length(te-t0)/SampleDensityValue);65 if (num_iterations<2.0) num_iterations = 2.0;65 const float max_iteratrions = 2048.0; 66 float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue); 67 if (num_iterations<2.0) num_iterations = 2.0; 66 68 67 if (num_iterations>max_iteratrions)68 {69 num_iterations = max_iteratrions;70 }69 if (num_iterations>max_iteratrions) 70 { 71 num_iterations = max_iteratrions; 72 } 71 73 72 vec3 deltaTexCoord=(t0-te)/float(num_iterations-1.0);73 vec3 texcoord = te;74 float previousV = texture3D( baseTexture, texcoord).a;74 vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-1.0); 75 vec3 texcoord = te.xyz; 76 float previousV = texture3D( baseTexture, texcoord).a; 75 77 76 float normalSampleDistance = 1.0/512.0;77 vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0);78 vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0);79 vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance);78 float normalSampleDistance = 1.0/512.0; 79 vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0); 80 vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0); 81 vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance); 80 82 81 while(num_iterations>0.0)82 {83 while(num_iterations>0.0) 84 { 83 85 84 float v = texture3D( baseTexture, texcoord).a;86 float v = texture3D( baseTexture, texcoord).a; 85 87 86 float m = (previousV-IsoSurfaceValue) * (v-IsoSurfaceValue);87 if (m <= 0.0)88 {89 float r = (IsoSurfaceValue-v)/(previousV-v);90 texcoord = texcoord - r*deltaTexCoord;88 float m = (previousV-IsoSurfaceValue) * (v-IsoSurfaceValue); 89 if (m <= 0.0) 90 { 91 float r = (IsoSurfaceValue-v)/(previousV-v); 92 texcoord = texcoord - r*deltaTexCoord; 91 93 92 v = texture3D( baseTexture, texcoord).a;93 vec4 color = texture1D( tfTexture, v);94 v = texture3D( baseTexture, texcoord).a; 95 vec4 color = texture1D( tfTexture, v); 94 96 95 float px = texture3D( baseTexture, texcoord + deltaX).a;96 float py = texture3D( baseTexture, texcoord + deltaY).a;97 float pz = texture3D( baseTexture, texcoord + deltaZ).a;97 float px = texture3D( baseTexture, texcoord + deltaX).a; 98 float py = texture3D( baseTexture, texcoord + deltaY).a; 99 float pz = texture3D( baseTexture, texcoord + deltaZ).a; 98 100 99 float nx = texture3D( baseTexture, texcoord - deltaX).a;100 float ny = texture3D( baseTexture, texcoord - deltaY).a;101 float nz = texture3D( baseTexture, texcoord - deltaZ).a;101 float nx = texture3D( baseTexture, texcoord - deltaX).a; 102 float ny = texture3D( baseTexture, texcoord - deltaY).a; 103 float nz = texture3D( baseTexture, texcoord - deltaZ).a; 102 104 103 vec3 grad = vec3(px-nx, py-ny, pz-nz);104 if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0)105 {106 vec3 normal = normalize(grad);107 float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection))*0.9;105 vec3 grad = vec3(px-nx, py-ny, pz-nz); 106 if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0) 107 { 108 vec3 normal = normalize(grad); 109 float lightScale = 0.1 + abs(dot(normal.xyz, eyeDirection))*0.9; 108 110 109 color.x *= lightScale;110 color.y *= lightScale;111 color.z *= lightScale;112 }111 color.x *= lightScale; 112 color.y *= lightScale; 113 color.z *= lightScale; 114 } 113 115 114 gl_FragColor = color;116 gl_FragColor = color; 115 117 116 return;117 }118 return; 119 } 118 120 119 previousV = v;121 previousV = v; 120 122 121 texcoord += deltaTexCoord;123 texcoord += deltaTexCoord; 122 124 123 --num_iterations;124 }125 --num_iterations; 126 } 125 127 126 // we didn't find an intersection so just discard fragment127 discard;128 // we didn't find an intersection so just discard fragment 129 discard; 128 130 129 131 }
