Horde3D

Next-Generation Graphics Engine
It is currently 24.11.2024, 22:04

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Nitpicking
PostPosted: 04.10.2007, 20:26 
Offline

Joined: 03.10.2007, 23:09
Posts: 10
Just some small things that could be better:
1) All functions in the API which takes const char* crash when called with the null pointer, this is a problem for me because i expose Horde functions to lua scripts and I don't want it to be possible to crash the program no matter what you type in the script files. So for example setNodeName(myModel, 0) should check for null and return false instead of assigning the pointer to a std::string (which crashes in strlen in msvc8).

2) (not in the actual engine) Shadows should not have any components of specularity in them, that looks weird. Fix to lightingUtils_frag.txt:
Code:
vec3 doLighting( const vec3 pos, const vec3 normal, const vec3 albedo, const float specMask, const float viewDist)
{
   vec3 light = lightPos.xyz - pos;
   
   // Distance attenuation
   float lightDist = length( light ) / lightPos.w;
   float att = 1.0 - lightDist * lightDist;
   light = normalize( light );
   
   // Spotlight falloff
   float angle = dot( lightDir, -light );
   if( angle > lightCosCutoff )
      att *= (angle - lightCosCutoff) / 0.2;
   else
      att = 0.0;
      
   // Half lambert lighting
   float NdotL = dot( normal, light );
   float diffuse = NdotL * 0.5 + 0.5;
   diffuse = diffuse * diffuse;      
   
   // Final color
   vec3 col = albedo * lightColor * (diffuse + 0.3)*att;     // (Diffuse & ambient) color
   
   // Shadow
   if( NdotL > 0.0 && att > 0.0 )
   {   
      mat4 lightMat;
      if( viewDist < shadowSplitDists.x ) lightMat = shadowMats[0];
      else if( viewDist < shadowSplitDists.y ) lightMat = shadowMats[1];
      else if( viewDist < shadowSplitDists.z ) lightMat = shadowMats[2];
      else lightMat = shadowMats[3];
      
      vec4 projShadow = lightMat * vec4( pos, 1.0 );
      projShadow.z = lightDist;
      projShadow.xy /= projShadow.w;
      
      float shade = PCF( projShadow );
      
      // Specular
      vec3 eye = normalize( viewer - pos );
      vec3 refl = reflect( -light, normal );
      float spec = pow( clamp( dot( refl, eye ), 0.0, 1.0 ), 8.0 ) * specMask;
      col += vec3( 0.3, 0.3, 0.4 ) * spec * att * shade;

      col *= max( 0.5, shade );
   }
   
   return col;
}


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: 06.10.2007, 11:34 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Thanks for your feedback.

1) This thing is already on my TODO list and will be realized for the next release. Should be quite easy to do.

2) Yes right, specular needs to be masked off for shadowed fragments. Thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group