Added in source shaders

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14554 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2014-11-27 15:54:24 +00:00
parent 114ddbb0c6
commit 1c9993dd5d
3 changed files with 65 additions and 0 deletions

View File

@@ -559,10 +559,21 @@ osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTyp
// OSG_NOTICE<<") creating new Program "<<program.get()<<std::endl;
osg::ref_ptr<osg::Shader> vertex_shader = osgDB::readShaderFile("shaders/terrain_displacement_mapping.vert");
if (!vertex_shader)
{
#include "shaders/terrain_displacement_mapping_vert.cpp"
vertex_shader = new osg::Shader(osg::Shader::VERTEX, terrain_displacement_mapping_vert);
}
program->addShader(vertex_shader.get());
osg::ref_ptr<osg::Shader> fragment_shader = osgDB::readShaderFile("shaders/terrain_displacement_mapping.frag");
if (!fragment_shader)
{
#include "shaders/terrain_displacement_mapping_frag.cpp"
fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, terrain_displacement_mapping_frag);
}
program->addShader(fragment_shader.get());
return program;

View File

@@ -0,0 +1,21 @@
char terrain_displacement_mapping_frag[] = "uniform sampler2D colorTexture1;\n"
"uniform sampler2D colorTexture2;\n"
"uniform sampler2D colorTexture3;\n"
"\n"
"varying vec2 texcoord;\n"
"varying vec4 basecolor;\n"
"\n"
"void main(void)\n"
"{\n"
" 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"
"#if 1\n"
" gl_FragColor = basecolor * color;\n"
"#else\n"
" gl_FragColor = basecolor;//basecolor * color;\n"
"#endif\n"
"}\n"
"\n";

View File

@@ -0,0 +1,33 @@
char terrain_displacement_mapping_vert[] = "uniform sampler2D terrainTexture;\n"
"varying vec2 texcoord;\n"
"varying vec4 basecolor;\n"
"\n"
"void main(void)\n"
"{\n"
" texcoord = gl_MultiTexCoord0.xy;\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"
"\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"
"\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"
"\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"
"\n"
" vec3 position = gl_Vertex.xyz + gl_Normal.xyz * height_center ;\n"
" gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);\n"
"\n"
"};\n"
"\n";