Hi All,

I've been playing around with the random tree generator in an attempt to get 
more realistic looking trees, in particular when lit by the sun.

The patch below changes the shader so the diffuse light element is applied 
based on the co-linearity of the light vector and the viewing vector. I think 
this makes sense, as the tree textures don't represent a surface themselves.

To compare, here's a link a screenshot of the old trees:

http:/www.nanjika.co.uk/flightgear/old_trees.jpg

New trees, also showcasing some improved cloud textures from Argyle on the 
forum: 

http:/www.nanjika.co.uk/flightgear/new_trees.jpg

In both cases, the sun is behind the viewer, so the viewer should be seeing the 
sunlit side of the tree. I think the tree textures themselves are possibly a 
bit too saturated, but this can be easily rectified if the code is committed.

The patch is below.

-Stuart

Index: TreeBin.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/tgdb/TreeBin.cxx,v
retrieving revision 1.7
diff -u -p -r1.7 TreeBin.cxx
--- TreeBin.cxx    30 Jan 2009 10:22:19 -0000    1.7
+++ TreeBin.cxx    18 Apr 2009 15:20:29 -0000
@@ -149,14 +149,12 @@ osg::Geometry* createOrthQuads(float w, 
     "  vec3 position = gl_Vertex.xyz * gl_Color.w + gl_Color.xyz;\n"
     "  gl_Position   = gl_ModelViewProjectionMatrix * vec4(position,1.0);\n"
     "  vec3 ecPosition = vec3(gl_ModelViewMatrix * vec4(position, 1.0));\n"
-    "  vec3 N = normalize(gl_NormalMatrix * gl_Normal);\n"
-    "  vec3 diffuse = gl_FrontMaterial.diffuse.rgb * max(0.0, dot(N, 
gl_LightSource[0].position.xyz));\n"
-    "  vec3 backDiffuse = gl_FrontMaterial.diffuse.rgb * max(0.0, dot(-N, 
gl_LightSource[0].position.xyz));\n"
-    " vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + 
gl_LightSource[0].ambient * gl_FrontMaterial.ambient;\n"
-    " gl_FrontColor = ambientColor + gl_LightSource[0].diffuse * vec4(diffuse, 
1.0);\n"
-    " gl_BackColor = ambientColor + gl_LightSource[0].diffuse * 
vec4(backDiffuse, 1.0)\n;"
-//    "  gl_TexCoord[0] = gl_MultiTexCoord0;\n"
-    " float fogCoord = abs(ecPosition.z);\n"
+    "  float n = dot(normalize(gl_LightSource[0].position.xyz), 
normalize(-ecPosition));\n"
+    "  vec3 diffuse = gl_FrontMaterial.diffuse.rgb * max(0.1, n);\n"
+    "  vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + 
gl_LightSource[0].ambient * gl_FrontMaterial.ambient;\n"
+    "  gl_FrontColor = ambientColor + gl_LightSource[0].diffuse * 
vec4(diffuse, 1.0);\n"
+    "  gl_BackColor = gl_FrontColor;\n"
+    "  float fogCoord = abs(ecPosition.z);\n"
     "  fogFactor = exp( -gl_Fog.density * gl_Fog.density * fogCoord * 
fogCoord);\n"
     "  fogFactor = clamp(fogFactor, 0.0, 1.0);\n"
     "}\n";
@@ -284,9 +282,9 @@ osg::Group* createForest(TreeBin& forest
             // DonĀ“t track vertex color
             material->setColorMode(Material::OFF);
             material->setAmbient(Material::FRONT_AND_BACK,
-                                 Vec4(.8f, .8f, .8f, 1.0f));
+                                 Vec4(1.0f, 1.0f, 1.0f, 1.0f));
             material->setDiffuse(Material::FRONT_AND_BACK,
-                                 Vec4(.2f, .2f, .2f, 1.0f));
+                                 Vec4(1.0f, 1.0f, 1.0f, 1.0f));
         }
         stateset->setAttributeAndModes(alphaFunc.get());
         stateset->setAttribute(program.get());


      

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to