From He Sicong, "fixed shader calculation of ray tracing"

This commit is contained in:
Robert Osfield 2008-02-28 10:56:03 +00:00
parent eb46608be4
commit 79276b3169

View File

@ -792,13 +792,13 @@ osg::Node* createShaderModel(osg::ref_ptr<osg::Image>& image_3d, osg::ref_ptr<os
{
char vertexShaderSource[] =
"varying vec3 texcoord;\n"
"varying vec3 deltaTexCoord;\n"
"varying vec3 cameraPos;\n"
"\n"
"void main(void)\n"
"{\n"
" texcoord = gl_MultiTexCoord0.xyz;\n"
" gl_Position = ftransform(); \n"
" deltaTexCoord = normalize(gl_ModelViewMatrixInverse * vec4(0,0,0,1) - gl_Vertex);\n"
" texcoord = gl_MultiTexCoord0.xyz;\n"
" gl_Position = ftransform();\n"
" cameraPos=vec4(gl_ModelViewMatrixInverse*vec4(0,0,0,1)).xyz;\n"
"}\n";
osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource);
@ -822,27 +822,26 @@ osg::Node* createShaderModel(osg::ref_ptr<osg::Image>& image_3d, osg::ref_ptr<os
"uniform float transparency;\n"
"uniform float alphaCutOff;\n"
"\n"
"varying vec3 deltaTexCoord;\n"
"varying vec3 cameraPos;\n"
"varying vec3 texcoord;\n"
"void main(void) \n"
"{ \n"
" vec3 deltaTexCoord2 = normalize(deltaTexCoord)*sampleDensity; \n"
"\n"
" gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
" \n"
" while (texcoord.x>=0.0 && texcoord.x<=1.0 &&\n"
" texcoord.y>=0.0 && texcoord.y<=1.0 &&\n"
" texcoord.z>=0.0 && texcoord.z<=1.0)\n"
" {\n"
" vec4 color = texture3D( baseTexture, texcoord);\n"
" float r = color[3]*transparency;\n"
" if (r>alphaCutOff)\n"
" {\n"
" gl_FragColor.xyz = gl_FragColor.xyz*(1.0-r)+color.xyz*r;\n"
" gl_FragColor.w += r;\n"
" }\n"
" texcoord += deltaTexCoord2; \n"
" }\n"
"void main(void)\n"
"{ \n"
" vec3 deltaTexCoord=normalize(cameraPos-texcoord.xyz)*sampleDensity;\n"
" gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
" while (texcoord.x>=0.0 && texcoord.x<=1.0 &&\n"
" texcoord.y>=0.0 && texcoord.y<=1.0 &&\n"
" texcoord.z>=0.0 && texcoord.z<=1.0)\n"
" {\n"
" vec4 color = texture3D( baseTexture, texcoord);\n"
" float r = color[3]*transparency;\n"
" if (r>alphaCutOff)\n"
" {\n"
" gl_FragColor.xyz = gl_FragColor.xyz*(1.0-r)+color.xyz*r;\n"
" gl_FragColor.w += r;\n"
" }\n"
" texcoord += deltaTexCoord; \n"
" }\n"
" if (gl_FragColor.w>1.0) gl_FragColor.w = 1.0; \n"
"}\n";