Added hardwired geometry shaders

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14666 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-01-20 17:58:56 +00:00
parent a0f1442aae
commit 51afa2c1df
3 changed files with 42 additions and 6 deletions

View File

@@ -599,7 +599,7 @@ osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTyp
#endif
bool useLighting = true;
bool useTextures = true;
bool useTextures = false;
osg::ref_ptr<osg::Program> program = new osg::Program;
_programMap[layerTypes] = program;
@@ -635,7 +635,9 @@ osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTyp
if (_useGeometryShader)
{
program->addShader(osgDB::readShaderFile("shaders/terrain_displacement_mapping.geom"));
#include "shaders/terrain_displacement_mapping_geom.cpp"
osg::ref_ptr<osg::Shader> shader = osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.geom", terrain_displacement_mapping_geom);
program->addShader(shader.get());
program->setParameter( GL_GEOMETRY_VERTICES_OUT_EXT, 4 );
program->setParameter( GL_GEOMETRY_INPUT_TYPE_EXT, GL_LINES_ADJACENCY );
@@ -715,8 +717,8 @@ void GeometryPool::applyLayers(osgTerrain::TerrainTile* tile, osg::StateSet* sta
texture2D->setImage(image.get());
texture2D->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
texture2D->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
texture2D->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP);
texture2D->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP);
texture2D->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
texture2D->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
texture2D->setBorderColor(osg::Vec4d(0.0,0.0,0.0,0.0));
texture2D->setResizeNonPowerOfTwoHint(false);

View File

@@ -0,0 +1,33 @@
char terrain_displacement_mapping_geom[] = "#version 120\n"
"#extension GL_EXT_geometry_shader4 : enable\n"
"\n"
"varying in vec3 normals_in[4];\n"
"varying in vec2 texcoord_in[4];\n"
"varying in vec4 basecolor_in[4];\n"
"\n"
"varying out vec2 texcoord;\n"
"varying out vec4 basecolor;\n"
"\n"
"void main(void)\n"
"{\n"
" float delta_02 = dot(normals_in[2],normals_in[0]);\n"
" float delta_13 = dot(normals_in[3],normals_in[1]);\n"
"\n"
" if (delta_02>delta_13)\n"
" {\n"
" gl_Position = gl_PositionIn[3]; texcoord = texcoord_in[3]; basecolor = basecolor_in[3]; EmitVertex();\n"
" gl_Position = gl_PositionIn[2]; texcoord = texcoord_in[2]; basecolor = basecolor_in[2]; EmitVertex();\n"
" gl_Position = gl_PositionIn[0]; texcoord = texcoord_in[0]; basecolor = basecolor_in[0]; EmitVertex();\n"
" gl_Position = gl_PositionIn[1]; texcoord = texcoord_in[1]; basecolor = basecolor_in[1]; EmitVertex();\n"
" EndPrimitive();\n"
" }\n"
" else\n"
" {\n"
" gl_Position = gl_PositionIn[0]; texcoord = texcoord_in[0]; basecolor = basecolor_in[0]; EmitVertex();\n"
" gl_Position = gl_PositionIn[3]; texcoord = texcoord_in[3]; basecolor = basecolor_in[3]; EmitVertex();\n"
" gl_Position = gl_PositionIn[1]; texcoord = texcoord_in[1]; basecolor = basecolor_in[1]; EmitVertex();\n"
" gl_Position = gl_PositionIn[2]; texcoord = texcoord_in[2]; basecolor = basecolor_in[2]; EmitVertex();\n"
" EndPrimitive();\n"
" }\n"
"}\n"
"\n";

View File

@@ -7,7 +7,7 @@ char terrain_displacement_mapping_vert[] = "#version 120\n"
"\n"
"#ifdef COMPUTE_DIAGONALS\n"
"varying vec2 texcoord_in;\n"
"varying float heights_in;\n"
"varying vec3 normals_in;\n"
"varying vec4 basecolor_in;\n"
"#else\n"
"varying vec2 texcoord;\n"
@@ -95,12 +95,13 @@ char terrain_displacement_mapping_vert[] = "#version 120\n"
" directionalLight( 0, normal, color);\n"
"\n"
"#else\n"
" vec3 normal = gl_Normal.xyz;\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"
" normals_in = normal;\n"
" texcoord_in = texcoord_center;\n"
" basecolor_in = color;\n"
"#else\n"