Aded shaders for various combinations of layers.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14637 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -530,22 +530,6 @@ osg::ref_ptr<osg::MatrixTransform> GeometryPool::getTileSubgraph(osgTerrain::Ter
|
||||
|
||||
osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTypes)
|
||||
{
|
||||
#if 0
|
||||
OSG_NOTICE<<"getOrCreateProgram(";
|
||||
for(LayerTypes::iterator itr = layerTypes.begin();
|
||||
itr != layerTypes.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr!= layerTypes.begin()) OSG_NOTICE<<", ";
|
||||
switch(*itr)
|
||||
{
|
||||
case(HEIGHTFIELD_LAYER): OSG_NOTICE<<"HeightField"; break;
|
||||
case(COLOR_LAYER): OSG_NOTICE<<"Colour"; break;
|
||||
case(CONTOUR_LAYER): OSG_NOTICE<<"Contour"; break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_programMapMutex);
|
||||
ProgramMap::iterator itr = _programMap.find(layerTypes);
|
||||
if (itr!=_programMap.end())
|
||||
@@ -554,27 +538,72 @@ osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTyp
|
||||
return itr->second.get();
|
||||
}
|
||||
|
||||
#if 1
|
||||
unsigned int num_HeightField = 0;
|
||||
unsigned int num_Color = 0;
|
||||
unsigned int num_Contour = 0;
|
||||
for(LayerTypes::iterator itr = layerTypes.begin();
|
||||
itr != layerTypes.end();
|
||||
++itr)
|
||||
{
|
||||
switch(*itr)
|
||||
{
|
||||
case(HEIGHTFIELD_LAYER): ++num_HeightField; break;
|
||||
case(COLOR_LAYER): ++num_Color; break;
|
||||
case(CONTOUR_LAYER): ++num_Contour; break;
|
||||
}
|
||||
}
|
||||
OSG_NOTICE<<"getOrCreateProgram()"<<std::endl;
|
||||
|
||||
OSG_NOTICE<<" HeightField "<<num_HeightField<<std::endl;
|
||||
OSG_NOTICE<<" Color "<<num_Color<<std::endl;
|
||||
OSG_NOTICE<<" Contour "<<num_Contour<<std::endl;
|
||||
|
||||
#endif
|
||||
|
||||
osg::ref_ptr<osg::Program> program = new osg::Program;
|
||||
_programMap[layerTypes] = program;
|
||||
|
||||
// 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)
|
||||
if (num_HeightField>0)
|
||||
{
|
||||
#include "shaders/terrain_displacement_mapping_vert.cpp"
|
||||
vertex_shader = new osg::Shader(osg::Shader::VERTEX, terrain_displacement_mapping_vert);
|
||||
program->addShader(osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.vert", 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)
|
||||
else
|
||||
{
|
||||
#include "shaders/terrain_displacement_mapping_frag.cpp"
|
||||
fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, terrain_displacement_mapping_frag);
|
||||
#include "shaders/terrain_displacement_mapping_flat_vert.cpp"
|
||||
program->addShader(osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.vert", terrain_displacement_mapping_flat_vert));
|
||||
}
|
||||
|
||||
if (num_Contour>0)
|
||||
{
|
||||
OSG_NOTICE<<"No support for Contour yet."<<std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
if (num_Color==0)
|
||||
{
|
||||
#include "shaders/terrain_displacement_mapping_frag.cpp"
|
||||
program->addShader(osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.frag", terrain_displacement_mapping_frag));
|
||||
}
|
||||
else if (num_Color==1)
|
||||
{
|
||||
#include "shaders/terrain_displacement_mapping_C_frag.cpp"
|
||||
program->addShader(osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping_C.frag", terrain_displacement_mapping_C_frag));
|
||||
}
|
||||
else if (num_Color==2)
|
||||
{
|
||||
#include "shaders/terrain_displacement_mapping_CC_frag.cpp"
|
||||
program->addShader(osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping_CC.frag", terrain_displacement_mapping_CC_frag));
|
||||
}
|
||||
else if (num_Color==3)
|
||||
{
|
||||
#include "shaders/terrain_displacement_mapping_CCC_frag.cpp"
|
||||
program->addShader(osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping_CCC.frag", terrain_displacement_mapping_CCC_frag));
|
||||
}
|
||||
|
||||
}
|
||||
program->addShader(fragment_shader.get());
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
char terrain_displacement_mapping_CCC_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"
|
||||
" 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"
|
||||
"}\n"
|
||||
"\n";
|
||||
@@ -0,0 +1,15 @@
|
||||
char terrain_displacement_mapping_CC_frag[] = "uniform sampler2D colorTexture1;\n"
|
||||
"uniform sampler2D colorTexture2;\n"
|
||||
"\n"
|
||||
"varying vec2 texcoord;\n"
|
||||
"varying vec4 basecolor;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\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"
|
||||
"}\n"
|
||||
"\n";
|
||||
@@ -0,0 +1,11 @@
|
||||
char terrain_displacement_mapping_C_frag[] = "uniform sampler2D colorTexture1;\n"
|
||||
"\n"
|
||||
"varying vec2 texcoord;\n"
|
||||
"varying vec4 basecolor;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 color = texture2D( colorTexture1, texcoord);\n"
|
||||
" gl_FragColor = basecolor * color;\n"
|
||||
"}\n"
|
||||
"\n";
|
||||
@@ -0,0 +1,18 @@
|
||||
char terrain_displacement_mapping_flat_vert[] = "varying vec2 texcoord;\n"
|
||||
"varying vec4 basecolor;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" texcoord = gl_MultiTexCoord0.xy;\n"
|
||||
"\n"
|
||||
" float height_center = 0;\n"
|
||||
"\n"
|
||||
" // note, need to introduce a proper lighting computation based on the gl_Normal.xyz\n"
|
||||
" vec3 normal = vec3(0.0, 0.0, 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";
|
||||
@@ -1,21 +1,7 @@
|
||||
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"
|
||||
char terrain_displacement_mapping_frag[] = "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"
|
||||
" gl_FragColor = basecolor;\n"
|
||||
"}\n"
|
||||
"\n";
|
||||
|
||||
Reference in New Issue
Block a user