Updated shaders

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14664 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-01-20 17:40:46 +00:00
parent 98f5fca9c2
commit a0f1442aae
4 changed files with 110 additions and 16 deletions

View File

@@ -7,11 +7,15 @@ char terrain_displacement_mapping_CCC_frag[] = "uniform sampler2D colorTexture1;
"\n"
"void main(void)\n"
"{\n"
"#ifdef GL_TEXTURE_2D\n"
" const float multiplier = 1.0/3.0;\n"
" vec4 color = texture2D( colorTexture1, texcoord)*multiplier +\n"
" texture2D( colorTexture2, texcoord)*multiplier +\n"
" texture2D( colorTexture3, texcoord)*multiplier;\n"
"\n"
" gl_FragColor = basecolor * color;\n"
"#else\n"
" gl_FragColor = basecolor;\n"
"#endif\n"
"}\n"
"\n";

View File

@@ -6,10 +6,14 @@ char terrain_displacement_mapping_CC_frag[] = "uniform sampler2D colorTexture1;\
"\n"
"void main(void)\n"
"{\n"
"#ifdef GL_TEXTURE_2D\n"
" const float multiplier = 1.0/2.0;\n"
" vec4 color = texture2D( colorTexture1, texcoord)*multiplier +\n"
" texture2D( colorTexture2, texcoord)*multiplier;\n"
"\n"
" gl_FragColor = basecolor * color;\n"
"#else\n"
" gl_FragColor = basecolor;\n"
"#endif\n"
"}\n"
"\n";

View File

@@ -5,7 +5,11 @@ char terrain_displacement_mapping_C_frag[] = "uniform sampler2D colorTexture1;\n
"\n"
"void main(void)\n"
"{\n"
"#ifdef GL_TEXTURE_2D\n"
" vec4 color = texture2D( colorTexture1, texcoord);\n"
" gl_FragColor = basecolor * color;\n"
"#else\n"
" gl_FragColor = basecolor;\n"
"#endif\n"
"}\n"
"\n";

View File

@@ -1,32 +1,114 @@
char terrain_displacement_mapping_vert[] = "uniform sampler2D terrainTexture;\n"
char terrain_displacement_mapping_vert[] = "#version 120\n"
"#ifdef COMPUTE_DIAGONALS\n"
"#extension GL_EXT_geometry_shader4 : enable\n"
"#endif\n"
"\n"
"uniform sampler2D terrainTexture;\n"
"\n"
"#ifdef COMPUTE_DIAGONALS\n"
"varying vec2 texcoord_in;\n"
"varying float heights_in;\n"
"varying vec4 basecolor_in;\n"
"#else\n"
"varying vec2 texcoord;\n"
"varying vec4 basecolor;\n"
"#endif\n"
"\n"
"\n"
"#ifdef GL_LIGHTING\n"
"// forward declare lighting computation, provided by lighting.vert shader\n"
"void directionalLight( int lightNum, vec3 normal, inout vec4 color );\n"
"#endif\n"
"\n"
"void main(void)\n"
"{\n"
" texcoord = gl_MultiTexCoord0.xy;\n"
" vec2 texcoord_center = gl_MultiTexCoord0.xy;\n"
"\n"
" float height_center = texture2D(terrainTexture, texcoord_center).r;\n"
"\n"
"#ifdef GL_LIGHTING\n"
" vec2 texelWorldRatio = gl_MultiTexCoord0.zw;\n"
" vec2 texelTexcoordSize = gl_Color.xy;\n"
"\n"
" vec2 texcoord_right = texcoord;\n"
" if (texcoord.x<0.5) texcoord_right.x = texcoord_right.x+texelTexcoordSize.x;\n"
" else texcoord_right.x = texcoord_right.x-texelTexcoordSize.x;\n"
" vec2 texcoord_right = vec2(texcoord_center.x+texelTexcoordSize.x, texcoord_center.y);\n"
" vec2 texcoord_left = vec2(texcoord_center.x-texelTexcoordSize.x, texcoord_center.y);\n"
" vec2 texcoord_up = vec2(texcoord_center.x, texcoord_center.y+texelTexcoordSize.y);\n"
" vec2 texcoord_down = vec2(texcoord_center.x, texcoord_center.y-texelTexcoordSize.y);\n"
"\n"
" vec2 texcoord_up = texcoord;\n"
" if (texcoord.y<0.5) texcoord_up.y = texcoord_up.y+texelTexcoordSize.y;\n"
" else texcoord_up.y = texcoord_up.y-texelTexcoordSize.y;\n"
" float dz_dx = 0.0;\n"
" float dx = 0.0;\n"
" if (texcoord_left.x>=0.0)\n"
" {\n"
" float height = texture2D(terrainTexture, texcoord_left).r;\n"
" dz_dx += (height_center-height)*texelWorldRatio.x;\n"
" dx += 1.0;\n"
" }\n"
"\n"
" if (texcoord_right.x<=1.0)\n"
" {\n"
" float height = texture2D(terrainTexture, texcoord_right).r;\n"
" dz_dx += (height-height_center)*texelWorldRatio.x;\n"
" dx += 1.0;\n"
" }\n"
"\n"
" //dz_dx = 0.0;\n"
"\n"
" float dx_denominator = 1.0 / sqrt(dx*dx + dz_dx*dz_dx);\n"
" float sin_rx = -dz_dx * dx_denominator;\n"
" float cos_rx = 1.0 / (dx * dx_denominator);\n"
"\n"
" mat3 rotate_x_mat = mat3(cos_rx, 0.0, -sin_rx,\n"
" 0.0, 1.0, 0.0,\n"
" sin_rx, 0.0, cos_rx);\n"
"\n"
"\n"
" float height_center = texture2D(terrainTexture, texcoord).r;\n"
" float height_right = texture2D(terrainTexture, texcoord_right).r;\n"
" float height_up = texture2D(terrainTexture, texcoord_up).r;\n"
" float dz_dy = 0.0;\n"
" float dy = 0.0;\n"
" if (texcoord_down.y>=0.0)\n"
" {\n"
" float height = texture2D(terrainTexture, texcoord_down).r;\n"
" dz_dy += (height_center-height)*texelWorldRatio.y;\n"
" dy += 1.0;\n"
" }\n"
"\n"
" vec2 gradient = vec2((height_center-height_right)*texelWorldRatio.x, (height_center-height_up)*texelWorldRatio.y);\n"
" vec3 normal = normalize(vec3(gradient.x, gradient.y, 1.0));\n"
" float intensity = normal.z;\n"
" basecolor = vec4(intensity, intensity, intensity, 1.0);\n"
" if (texcoord_up.y<=1.0)\n"
" {\n"
" float height = texture2D(terrainTexture, texcoord_up).r;\n"
" dz_dy += (height-height_center)*texelWorldRatio.y;\n"
" dy += 1.0;\n"
" }\n"
"\n"
" vec3 position = gl_Vertex.xyz + gl_Normal.xyz * height_center ;\n"
" //dz_dy = 0.0;\n"
"\n"
" float dy_denominator = 1.0 / sqrt(dy*dy + dz_dy*dz_dy);\n"
" float sin_ry = -dz_dy * dy_denominator;\n"
" float cos_ry = 1.0 / (dy_denominator*dy);\n"
"\n"
" mat3 rotate_y_mat = mat3(1.0, 0.0, 0.0,\n"
" 0.0, cos_ry, -sin_ry,\n"
" 0.0, sin_ry, cos_ry);\n"
"\n"
"\n"
" vec3 normal = normalize(rotate_x_mat * (rotate_y_mat * gl_Normal.xyz));\n"
" //vec3 normal = normalize(gl_Normal.xyz);\n"
" vec4 color = vec4(1.0,1.0,1.0,1.0);\n"
" directionalLight( 0, normal, color);\n"
"\n"
"#else\n"
" vec4 color = vec4(1.0, 1.0, 1.0, 1.0);\n"
"#endif\n"
"\n"
"\n"
"#ifdef COMPUTE_DIAGONALS\n"
" heights_in = height_center;\n"
" texcoord_in = texcoord_center;\n"
" basecolor_in = color;\n"
"#else\n"
" texcoord = texcoord_center;\n"
" basecolor = color;\n"
"#endif\n"
"\n"
" vec3 position = gl_Vertex.xyz + gl_Normal.xyz * height_center;\n"
" gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);\n"
"\n"
"};\n"