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:
@@ -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;
|
||||
|
||||
21
src/osgTerrain/shaders/terrain_displacement_mapping_frag.cpp
Normal file
21
src/osgTerrain/shaders/terrain_displacement_mapping_frag.cpp
Normal 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";
|
||||
33
src/osgTerrain/shaders/terrain_displacement_mapping_vert.cpp
Normal file
33
src/osgTerrain/shaders/terrain_displacement_mapping_vert.cpp
Normal 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";
|
||||
Reference in New Issue
Block a user