Hi.

These two patches allow use of external shaders as the tree and 3d cloud
shaders. The shaders are Shaders/3dcloud.{frag|vert} and
Shaders/tree.{frag|vert}. If the shader files are not found, the
original shaders included in the source are used.

This makes testing modifications to the shaders easier and faster. End
users should see no difference when using this.

Also attached are the original shaders to be put into Shaders/.


Lauri Peltonen (Zan)
-- 
Lauri Peltonen <lauri.pelto...@gmail.com>
--- simgear/scene/sky/newcloud.cxx.old	2009-09-26 22:42:37.000000000 +0300
+++ simgear/scene/sky/newcloud.cxx	2009-09-27 13:56:48.000000000 +0300
@@ -171,6 +171,8 @@
         osg::Texture2D *tex = new osg::Texture2D;
         tex->setWrap( osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP );
         tex->setWrap( osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP );
+        tex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
+        tex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
         tex->setImage(osgDB::readImageFile(texture, options.get()));
                 
         StateAttributeFactory* attribFactory = StateAttributeFactory::instance();
@@ -199,11 +201,19 @@
             alphaFunc->setFunction(AlphaFunc::GREATER,0.05f);
             program  = new Program;
             baseTextureSampler = new osg::Uniform("baseTexture", 0);
-            Shader* vertex_shader = new Shader(Shader::VERTEX, vertexShaderSource);
+
+            Shader* vertex_shader = new Shader(Shader::VERTEX);
+            string source = osgDB::findDataFile("Shaders/3dcloud.vert");
+            if(source == "") vertex_shader->setShaderSource(vertexShaderSource);
+            else vertex_shader->loadShaderSourceFromFile(source);
             program->addShader(vertex_shader);
             program->addBindAttribLocation("usrAttr1", CloudShaderGeometry::USR_ATTR_1);
             program->addBindAttribLocation("usrAttr2", CloudShaderGeometry::USR_ATTR_2);
-            Shader* fragment_shader = new Shader(Shader::FRAGMENT, fragmentShaderSource);
+
+            Shader* fragment_shader = new Shader(Shader::FRAGMENT);
+            source = osgDB::findDataFile("Shaders/3dcloud.frag");
+            if(source == "") fragment_shader->setShaderSource(fragmentShaderSource);
+            else fragment_shader->loadShaderSourceFromFile(source);
             program->addShader(fragment_shader);
             material = new Material;
             // Don´t track vertex color
--- simgear/scene/tgdb/TreeBin.cxx.orig	2009-09-26 22:46:33.000000000 +0300
+++ simgear/scene/tgdb/TreeBin.cxx	2009-09-26 20:37:33.000000000 +0300
@@ -338,12 +338,21 @@
             alphaFunc->setFunction(AlphaFunc::GEQUAL,0.33f);
             program  = new Program;
             baseTextureSampler = new osg::Uniform("baseTexture", 0);
-            Shader* vertex_shader = new Shader(Shader::VERTEX,
-                                               vertexShaderSource);
+
+            Shader* vertex_shader = new Shader(Shader::VERTEX);
+            string source = osgDB::findDataFile("Shaders/tree.vert");
+            if(source == "") vertex_shader->setShaderSource(vertexShaderSource);
+            else vertex_shader->loadShaderSourceFromFile(source);
+            
             program->addShader(vertex_shader);
-            Shader* fragment_shader = new Shader(Shader::FRAGMENT,
-                                                 fragmentShaderSource);
+
+            Shader* fragment_shader = new Shader(Shader::FRAGMENT);
+            source = osgDB::findDataFile("Shaders/tree.frag");
+            if(source == "") fragment_shader->setShaderSource(fragmentShaderSource);
+            else fragment_shader->loadShaderSourceFromFile(source);
+
             program->addShader(fragment_shader);
+
             material = new Material;
             // Don´t track vertex color
             material->setColorMode(Material::OFF);
uniform sampler2D baseTexture;
varying float fogFactor;

void main(void)
{
      vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);
      vec4 finalColor = base * gl_Color;
      gl_FragColor.rgb = mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor );
      gl_FragColor.a = finalColor.a;
}

Attachment: 3dcloud.vert
Description: application/fluid

uniform sampler2D baseTexture; 
varying float fogFactor;

void main(void) 
{ 
  vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);
  vec4 finalColor = base * gl_Color;
  gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor );
}
varying float fogFactor;

void main(void)
{
  float numVarieties = gl_Normal.z;
  float texFract = floor(fract(gl_MultiTexCoord0.x) * numVarieties) / 
numVarieties;
  texFract += floor(gl_MultiTexCoord0.x) / numVarieties;
  float sr = sin(gl_FogCoord);
  float cr = cos(gl_FogCoord);
  gl_TexCoord[0] = vec4(texFract, gl_MultiTexCoord0.y, 0.0, 0.0);

  // scaling
  vec3 position = gl_Vertex.xyz * gl_Normal.xxy;

  // Rotation of the generic quad to specific one for the tree.
  position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, 
cr)));
  position = position + gl_Color.xyz;
  gl_Position   = gl_ModelViewProjectionMatrix * vec4(position,1.0);
  vec3 ecPosition = vec3(gl_ModelViewMatrix * vec4(position, 1.0));

  float n = dot(normalize(gl_LightSource[0].position.xyz), 
normalize(-ecPosition));

  vec3 diffuse = gl_FrontMaterial.diffuse.rgb * max(0.1, n);
  vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + 
gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
  gl_FrontColor = ambientColor + gl_LightSource[0].diffuse * vec4(diffuse, 1.0);
  gl_BackColor = gl_FrontColor;

  float fogCoord = abs(ecPosition.z);
  fogFactor = exp( -gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
  fogFactor = clamp(fogFactor, 0.0, 1.0);
}
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to