|
不熟悉shader .如何修改?
static const char default_scene_vertex[] =
"// osgOcean Uniforms\n"
"// -----------------\n"
"uniform mat4 osg_ViewMatrixInverse;\n"
"uniform float osgOcean_WaterHeight;\n"
"uniform vec3 osgOcean_Eye;\n"
"uniform vec3 osgOcean_UnderwaterAttenuation;\n"
"uniform vec4 osgOcean_UnderwaterDiffuse;\n"
"uniform bool osgOcean_EnableUnderwaterScattering;\n"
"// -----------------\n"
"\n"
"varying vec3 vExtinction;\n"
"varying vec3 vInScattering;\n"
"\n"
"varying vec3 vNormal;\n"
"varying vec3 vLightDir;\n"
"varying vec3 vEyeVec;\n"
"varying float vWorldHeight;\n"
"\n"
"void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering )\n"
"{\n"
" float viewDist = length(eye-worldVertex);\n"
" \n"
" float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0);\n"
" \n"
" extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0);\n"
"\n"
" // Need to compute accurate kd constant.\n"
" // const vec3 kd = vec3(0.001, 0.001, 0.001);\n"
" inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001)));\n"
"}\n"
"\n"
"void main(void)\n"
"{\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" gl_Position = ftransform();\n"
" gl_FogFragCoord = gl_Position.z;\n"
" gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; // for reflections\n"
"\n"
" vNormal = gl_NormalMatrix * gl_Normal;\n"
" vLightDir = gl_LightSource[osgOcean_LightID].position.xyz;\n"
" vEyeVec = -vec3(gl_ModelViewMatrix*gl_Vertex);\n"
"\n"
" vec4 worldVertex = (osg_ViewMatrixInverse*gl_ModelViewMatrix) * gl_Vertex;\n"
"\n"
" if (osgOcean_EnableUnderwaterScattering)\n"
" computeScattering( osgOcean_Eye, worldVertex.xyz, vExtinction, vInScattering);\n"
"\n"
" vWorldHeight = worldVertex.z;\n"
"}\n";
static const char default_scene_fragment[] =
"// osgOcean Uniforms\n"
"// -----------------\n"
"uniform float osgOcean_DOF_Near;\n"
"uniform float osgOcean_DOF_Focus;\n"
"uniform float osgOcean_DOF_Far;\n"
"uniform float osgOcean_DOF_Clamp;\n"
"\n"
"uniform float osgOcean_UnderwaterFogDensity;\n"
"uniform float osgOcean_AboveWaterFogDensity;\n"
"uniform vec4 osgOcean_UnderwaterFogColor;\n"
"uniform vec4 osgOcean_AboveWaterFogColor;\n"
"\n"
"uniform float osgOcean_WaterHeight;\n"
"\n"
"uniform bool osgOcean_EnableGlare;\n"
"uniform bool osgOcean_EnableDOF;\n"
"uniform bool osgOcean_EyeUnderwater;\n"
"uniform bool osgOcean_EnableUnderwaterScattering;\n"
"// -------------------\n"
"\n"
"uniform sampler2D uTextureMap;\n"
"\n"
"varying vec3 vExtinction;\n"
"varying vec3 vInScattering;\n"
"varying vec3 vNormal;\n"
"varying vec3 vLightDir;\n"
"varying vec3 vEyeVec;\n"
"\n"
"varying float vWorldHeight;\n"
"\n"
"float computeDepthBlur(float depth, float focus, float near, float far, float clampval )\n"
"{\n"
" float f;\n"
" if (depth < focus){\n"
" f = (depth - focus)/(focus - near);\n"
" }\n"
" else{\n"
" f = (depth - focus)/(far - focus);\n"
" f = clamp(f, 0.0, clampval);\n"
" }\n"
" return f * 0.5 + 0.5;\n"
"}\n"
"\n"
"vec4 lighting( vec4 colormap )\n"
"{\n"
" vec4 final_color = gl_LightSource[osgOcean_LightID].ambient * colormap;\n"
"\n"
" vec3 N = normalize(vNormal);\n"
" vec3 L = normalize(vLightDir);\n"
"\n"
" float lambertTerm = dot(N,L);\n"
"\n"
" if(lambertTerm > 0.0)\n"
" {\n"
" final_color += gl_LightSource[osgOcean_LightID].diffuse * lambertTerm * colormap;\n"
"\n"
" vec3 E = normalize(vEyeVec);\n"
" vec3 R = reflect(-L, N);\n"
"\n"
" float specular = pow( max(dot(R, E), 0.0), 2.0 );\n"
"\n"
" final_color += gl_LightSource[osgOcean_LightID].specular * specular;\n"
" }\n"
"\n"
" return final_color;\n"
"}\n"
"\n"
"float computeFogFactor( float density, float fogCoord )\n"
"{\n"
" return exp2(density * fogCoord * fogCoord );\n"
"}\n"
"\n"
"void main(void)\n"
"{\n"
" vec4 textureColor = texture2D( uTextureMap, gl_TexCoord[0].st );\n"
"\n"
" vec4 final_color;\n"
"\n"
" float alpha;\n"
"\n"
" // Underwater\n"
" // +2 tweak here as waves peak above average wave height,\n"
" // and surface fog becomes visible.\n"
" if(osgOcean_EyeUnderwater && vWorldHeight < osgOcean_WaterHeight+2.0 )\n"
" {\n"
" final_color = lighting( textureColor );\n"
"\n"
" // mix in underwater light\n"
" if (osgOcean_EnableUnderwaterScattering)\n"
" final_color.rgb = final_color.rgb * vExtinction + vInScattering;\n"
"\n"
" float fogFactor = computeFogFactor( osgOcean_UnderwaterFogDensity, gl_FogFragCoord );\n"
"\n"
" final_color = mix( osgOcean_UnderwaterFogColor, final_color, fogFactor );\n"
"\n"
" if(osgOcean_EnableDOF)\n"
" {\n"
" final_color.a = computeDepthBlur(gl_FogFragCoord, osgOcean_DOF_Focus, osgOcean_DOF_Near, osgOcean_DOF_Far, osgOcean_DOF_Clamp);\n"
" }\n"
" }\n"
" // Above water\n"
" else\n"
" {\n"
" final_color = lighting( textureColor );\n"
"\n"
" float fogFactor = computeFogFactor( osgOcean_AboveWaterFogDensity, gl_FogFragCoord );\n"
" final_color = mix( osgOcean_AboveWaterFogColor, final_color, fogFactor );\n"
"\n"
" if(osgOcean_EnableGlare)\n"
" {\n"
" final_color.a = 0.0;\n"
" }\n"
" }\n"
"\n"
" gl_FragColor = final_color;\n"
"}\n"; |
|