From He Sicong, "fixed shader calculation of ray tracing"
This commit is contained in:
parent
eb46608be4
commit
79276b3169
@ -792,13 +792,13 @@ osg::Node* createShaderModel(osg::ref_ptr<osg::Image>& image_3d, osg::ref_ptr<os
|
|||||||
{
|
{
|
||||||
char vertexShaderSource[] =
|
char vertexShaderSource[] =
|
||||||
"varying vec3 texcoord;\n"
|
"varying vec3 texcoord;\n"
|
||||||
"varying vec3 deltaTexCoord;\n"
|
"varying vec3 cameraPos;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" texcoord = gl_MultiTexCoord0.xyz;\n"
|
" texcoord = gl_MultiTexCoord0.xyz;\n"
|
||||||
" gl_Position = ftransform(); \n"
|
" gl_Position = ftransform();\n"
|
||||||
" deltaTexCoord = normalize(gl_ModelViewMatrixInverse * vec4(0,0,0,1) - gl_Vertex);\n"
|
" cameraPos=vec4(gl_ModelViewMatrixInverse*vec4(0,0,0,1)).xyz;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource);
|
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 transparency;\n"
|
||||||
"uniform float alphaCutOff;\n"
|
"uniform float alphaCutOff;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"varying vec3 deltaTexCoord;\n"
|
"varying vec3 cameraPos;\n"
|
||||||
"varying vec3 texcoord;\n"
|
"varying vec3 texcoord;\n"
|
||||||
"void main(void) \n"
|
|
||||||
"{ \n"
|
|
||||||
" vec3 deltaTexCoord2 = normalize(deltaTexCoord)*sampleDensity; \n"
|
|
||||||
"\n"
|
"\n"
|
||||||
" gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
|
"void main(void)\n"
|
||||||
" \n"
|
"{ \n"
|
||||||
" while (texcoord.x>=0.0 && texcoord.x<=1.0 &&\n"
|
" vec3 deltaTexCoord=normalize(cameraPos-texcoord.xyz)*sampleDensity;\n"
|
||||||
" texcoord.y>=0.0 && texcoord.y<=1.0 &&\n"
|
" gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
|
||||||
" texcoord.z>=0.0 && texcoord.z<=1.0)\n"
|
" while (texcoord.x>=0.0 && texcoord.x<=1.0 &&\n"
|
||||||
" {\n"
|
" texcoord.y>=0.0 && texcoord.y<=1.0 &&\n"
|
||||||
" vec4 color = texture3D( baseTexture, texcoord);\n"
|
" texcoord.z>=0.0 && texcoord.z<=1.0)\n"
|
||||||
" float r = color[3]*transparency;\n"
|
" {\n"
|
||||||
" if (r>alphaCutOff)\n"
|
" vec4 color = texture3D( baseTexture, texcoord);\n"
|
||||||
" {\n"
|
" float r = color[3]*transparency;\n"
|
||||||
" gl_FragColor.xyz = gl_FragColor.xyz*(1.0-r)+color.xyz*r;\n"
|
" if (r>alphaCutOff)\n"
|
||||||
" gl_FragColor.w += r;\n"
|
" {\n"
|
||||||
" }\n"
|
" gl_FragColor.xyz = gl_FragColor.xyz*(1.0-r)+color.xyz*r;\n"
|
||||||
" texcoord += deltaTexCoord2; \n"
|
" gl_FragColor.w += r;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
" texcoord += deltaTexCoord; \n"
|
||||||
|
" }\n"
|
||||||
" if (gl_FragColor.w>1.0) gl_FragColor.w = 1.0; \n"
|
" if (gl_FragColor.w>1.0) gl_FragColor.w = 1.0; \n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user