Revision: 8923
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8923&view=rev
Author:   natepak
Date:     2010-09-29 15:43:52 +0000 (Wed, 29 Sep 2010)

Log Message:
-----------
Improved shadows

Modified Paths:
--------------
    code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt
    
code/gazebo/branches/wx/Media/materials/programs/directional_shadow_receiver_vp.glsl
    
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_fp.glsl
    
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_vp.glsl
    code/gazebo/branches/wx/Media/materials/scripts/Gazebo.material
    code/gazebo/branches/wx/Media/materials/scripts/shadow_receiver.material
    code/gazebo/branches/wx/server/rendering/Light.cc
    code/gazebo/branches/wx/worlds/empty.world

Added Paths:
-----------
    code/gazebo/branches/wx/Media/materials/programs/perpixel_fp.glsl
    code/gazebo/branches/wx/Media/materials/programs/perpixel_vp.glsl

Modified: code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt     
2010-09-28 23:23:25 UTC (rev 8922)
+++ code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt     
2010-09-29 15:43:52 UTC (rev 8923)
@@ -8,6 +8,8 @@
            point_receiver_fp.glsl
            ambient_one_texture_vp.glsl
            blur.glsl
+           perpixel_vp.glsl
+           perpixel_fp.glsl
 ) 
 
 INSTALL(FILES ${files} DESTINATION 
${CMAKE_INSTALL_PREFIX}/share/gazebo/Media/materials/programs/)

Modified: 
code/gazebo/branches/wx/Media/materials/programs/directional_shadow_receiver_vp.glsl
===================================================================
--- 
code/gazebo/branches/wx/Media/materials/programs/directional_shadow_receiver_vp.glsl
        2010-09-28 23:23:25 UTC (rev 8922)
+++ 
code/gazebo/branches/wx/Media/materials/programs/directional_shadow_receiver_vp.glsl
        2010-09-29 15:43:52 UTC (rev 8923)
@@ -18,10 +18,10 @@
   gl_Position = world_view_proj_mat * gl_Vertex;
 
   // Vertex in world space
-  vertex_world_view_pos = (world_view_mat * gl_Vertex).xyz;
+  //vertex_world_view_pos = (world_view_mat * gl_Vertex).xyz;
 
   // Vertex normal in world space
-  vertex_world_norm = (inv_trans_world_view_mat * vec4(gl_Normal, 1.0)).xyz;
+  //vertex_world_norm = (inv_trans_world_view_mat * vec4(gl_Normal, 1.0)).xyz;
 
   shadow_distance = gl_Position.z;
 

Added: code/gazebo/branches/wx/Media/materials/programs/perpixel_fp.glsl
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/perpixel_fp.glsl           
                (rev 0)
+++ code/gazebo/branches/wx/Media/materials/programs/perpixel_fp.glsl   
2010-09-29 15:43:52 UTC (rev 8923)
@@ -0,0 +1,75 @@
+uniform vec3 derived_light_diffuse_color;
+uniform vec4 derived_light_specular_color;
+uniform float surface_shininess;
+
+uniform vec4 light_position_view_space;
+uniform vec4 light_direction_view_space;
+uniform vec4 light_attenuation;
+uniform vec4 spotlight_params;
+
+uniform sampler2D diffuse_map;
+
+varying vec3 vertex_world_view_pos;
+varying vec3 vertex_world_norm;
+
+void main()
+{
+  float spot = 1.0;
+  float specular = 0.0;
+
+  // Normalized fragment normal
+  vec3 norm = normalize(vertex_world_norm);
+
+  // Direction from the fragment to the light 
+  vec3 light_dir_view = light_position_view_space.xyz - 
+                        vertex_world_view_pos.xyz * 
light_position_view_space.w;
+
+  // light_position_view_space.w == 0 for directional lights
+  float light_dist = length(light_dir_view);
+  light_dir_view = normalize(light_dir_view);
+
+  float lambert_term = max( dot(norm, light_dir_view), 0.0 );
+
+  
//////////////////////////////////////////////////////////////////////////////
+  // COMPUTE DIFFUSE CONTRIBUTION
+  vec4 diffuse_tex = texture2D(diffuse_map, gl_TexCoord[0].st);
+  vec4 diffuse_contrib = vec4(derived_light_diffuse_color * 
+                              diffuse_tex.rgb * lambert_term,1.0);
+
+
+  
//////////////////////////////////////////////////////////////////////////////
+  // COMPUTE SPOT AND SPECULAR COMPONENTS
+  if (lambert_term > 0.0) 
+  {
+    vec3 view = -normalize(vertex_world_view_pos.xyz);
+    vec3 halfway = normalize( view + light_dir_view );
+    float nDotH = dot(norm, halfway);
+
+    float fAtten = 1.0 / (light_attenuation.y + 
+                          light_attenuation.z*light_dist + 
+                          light_attenuation.w*light_dist*light_dist);    
+
+    float fSpotT = 1.0;
+
+    if (!(spotlight_params.x == 1.0 && spotlight_params.y == 0.0 && 
+          spotlight_params.z == 0.0 && spotlight_params.w == 1.0))
+    {
+      float rho = dot(-light_direction_view_space.xyz, light_dir_view);
+
+      float fSpotE  = clamp((rho - spotlight_params.y) / 
+          (spotlight_params.x - spotlight_params.y),0.0,1.0);
+
+      float fSpotT  = pow(fSpotE, spotlight_params.z);
+
+
+      spot = lambert_term * fAtten * fSpotT;
+    }
+
+    // Works for all light types
+    specular = pow(clamp(nDotH, 0.0, 1.0), surface_shininess) * fAtten * 
fSpotT;
+  }
+
+  vec4 specular_contrib = specular * derived_light_specular_color;
+
+  gl_FragColor = (diffuse_contrib + specular_contrib) * spot;
+}

Added: code/gazebo/branches/wx/Media/materials/programs/perpixel_vp.glsl
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/perpixel_vp.glsl           
                (rev 0)
+++ code/gazebo/branches/wx/Media/materials/programs/perpixel_vp.glsl   
2010-09-29 15:43:52 UTC (rev 8923)
@@ -0,0 +1,20 @@
+uniform mat4 world_view_mat;
+uniform mat4 world_view_proj_mat;
+uniform mat4 inv_trans_world_view_mat;
+
+varying vec3 vertex_world_view_pos;
+varying vec3 vertex_world_norm;
+
+void main()
+{
+  gl_Position = world_view_proj_mat * gl_Vertex;
+
+  // Vertex in world space
+  vertex_world_view_pos = (world_view_mat * gl_Vertex).xyz;
+
+  // Vertex normal in world space
+  vertex_world_norm = (inv_trans_world_view_mat * vec4(gl_Normal, 1.0)).xyz;
+
+  // Pass through the diffuse component
+  gl_TexCoord[0] = gl_MultiTexCoord0;
+}

Modified: 
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_fp.glsl
===================================================================
--- 
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_fp.glsl   
    2010-09-28 23:23:25 UTC (rev 8922)
+++ 
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_fp.glsl   
    2010-09-29 15:43:52 UTC (rev 8923)
@@ -62,8 +62,9 @@
 
 void main()
 {
+  float shadow_factor = 1.0;
+
   float spot = 1.0;
-  float shadow_factor = 1.0;
   float specular = 0.0;
 
   // Normalized fragment normal
@@ -116,8 +117,9 @@
   //shadow_factor = ShadowPCF();
   //if (light_casts_shadows)
   shadow_factor = ShadowPCF(shadow_map, vertex_light_pos, 
inv_shadow_map_size.xy);
+  //gl_FragColor = vec4(shadow_factor, shadow_factor, shadow_factor, 1.0);
 
+
   vec4 specular_contrib = specular * derived_light_specular_color;
-
   gl_FragColor = (diffuse_contrib + specular_contrib) * spot * shadow_factor;
 }

Modified: 
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_vp.glsl
===================================================================
--- 
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_vp.glsl   
    2010-09-28 23:23:25 UTC (rev 8922)
+++ 
code/gazebo/branches/wx/Media/materials/programs/spot_shadow_receiver_vp.glsl   
    2010-09-29 15:43:52 UTC (rev 8923)
@@ -27,4 +27,6 @@
 
   // Pass through the diffuse component
   gl_TexCoord[0] = gl_MultiTexCoord0;
+
+  gl_FrontColor = gl_Color;
 }

Modified: code/gazebo/branches/wx/Media/materials/scripts/Gazebo.material
===================================================================
--- code/gazebo/branches/wx/Media/materials/scripts/Gazebo.material     
2010-09-28 23:23:25 UTC (rev 8922)
+++ code/gazebo/branches/wx/Media/materials/scripts/Gazebo.material     
2010-09-29 15:43:52 UTC (rev 8923)
@@ -39,21 +39,6 @@
        }
 }
 
-material Gazebo/Grey
-{
-  receive_shadows on
-
-       technique
-       {
-               pass
-               {
-                       ambient 0.3 0.3 0.3 1.0
-      diffuse 0.5 0.5 0.5 1.0
-      specular 0.8 0.8 0.8 1
-               }
-       }
-}
-
 material Gazebo/Eyes
 {
   receive_shadows on

Modified: 
code/gazebo/branches/wx/Media/materials/scripts/shadow_receiver.material
===================================================================
--- code/gazebo/branches/wx/Media/materials/scripts/shadow_receiver.material    
2010-09-28 23:23:25 UTC (rev 8922)
+++ code/gazebo/branches/wx/Media/materials/scripts/shadow_receiver.material    
2010-09-29 15:43:52 UTC (rev 8923)
@@ -1,3 +1,34 @@
+//vertex_program perpixel_vp_glsl glsl
+//{
+//  source perpixel_vp.glsl
+//
+//  default_params
+//  {
+//    param_named_auto world_view_mat worldview_matrix
+//    param_named_auto world_view_proj_mat worldviewproj_matrix
+//    param_named_auto inv_trans_world_view_mat 
inverse_transpose_worldview_matrix
+//  }
+//}
+//
+//fragment_program perpixel_fp_glsl glsl
+//{
+//  source perpixel_fp.glsl
+//
+//  default_params
+//  {
+//    param_named_auto derived_light_diffuse_color 
derived_light_diffuse_colour 0
+//    param_named_auto derived_light_specular_color 
derived_light_specular_colour 0
+//    param_named_auto surface_shininess surface_shininess
+//
+//    param_named_auto light_position_view_space light_position_view_space 0
+//    param_named_auto light_direction_view_space light_direction_view_space 0
+//    param_named_auto light_attenuation light_attenuation 0
+//    param_named_auto spotlight_params spotlight_params 0
+//
+//    param_named diffuse_map int 0
+//  }
+//}
+
 vertex_program spot_receiver_vp_glsl glsl
 {
   source spot_shadow_receiver_vp.glsl
@@ -117,6 +148,8 @@
     param_named diffuse_map int 0
   }
 }
+
+
 abstract material receiver_template
 {
   technique
@@ -136,15 +169,14 @@
       //{
       //}
 
-      texture_unit ambient_tex
-      {
-      }
+      texture_unit ambient_tex 
+      { }
     }
 
     pass spot
     {
       max_lights 4
-      scene_blend add
+      scene_blend add 
       iteration once_per_light spot
 
       ambient  0 0 0
@@ -249,3 +281,18 @@
     }
   }
 }
+
+material Gazebo/Grey : receiver_template
+{
+       technique
+       {
+               pass ambient
+               {
+                       ambient 0.3 0.3 0.3 1.0
+      diffuse 0.5 0.5 0.5 1.0
+      specular 0.8 0.8 0.8 1
+               }
+       }
+}
+
+

Modified: code/gazebo/branches/wx/server/rendering/Light.cc
===================================================================
--- code/gazebo/branches/wx/server/rendering/Light.cc   2010-09-28 23:23:25 UTC 
(rev 8922)
+++ code/gazebo/branches/wx/server/rendering/Light.cc   2010-09-29 15:43:52 UTC 
(rev 8923)
@@ -397,16 +397,15 @@
 /// Set cast shadowsj
 void Light::SetCastShadows(const bool &cast)
 {
-  /*if (this->light->getType() == Ogre::Light::LT_POINT)
+  if (this->light->getType() == Ogre::Light::LT_POINT)
     this->light->setCastShadows(false);
   else
   {
-  */
     if (**this->castShadowsP != cast)
       this->castShadowsP->SetValue( cast );
 
     this->light->setCastShadows(cast);
-  //}
+  }
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/gazebo/branches/wx/worlds/empty.world
===================================================================
--- code/gazebo/branches/wx/worlds/empty.world  2010-09-28 23:23:25 UTC (rev 
8922)
+++ code/gazebo/branches/wx/worlds/empty.world  2010-09-29 15:43:52 UTC (rev 
8923)
@@ -181,14 +181,14 @@
     <rpy>0 0 0</rpy>
     <static>true</static>
     <light>
-      <type>directional</type>
+      <type>spot</type>
       <diffuseColor>0.6 0.6 0.6 1.0</diffuseColor>
       <specularColor>1 1 1 1.0</specularColor>
       <attenuation>.1 0.2 0.001</attenuation>
       <innerAngle>10</innerAngle>
       <outerAngle>60</outerAngle>
-      <falloff>0.1</falloff>
-      <range>10</range>
+      <falloff>1.0</falloff>
+      <range>50</range>
       <direction>0 0 -1.0</direction>
       <castShadows>true</castShadows>
     </light>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to