reduce redundant calcs for the dampen method.

remove overemphasized normal infleunce on groundcover foliage
This commit is contained in:
AzaezelX 2025-02-25 15:46:41 -06:00
parent e7dfcc1fe3
commit 41133624e3
4 changed files with 20 additions and 43 deletions

View file

@ -124,7 +124,7 @@ void foliageProcessVert( inout float3 position,
in float3 eyePos )
{
// Assign the normal and tagent values.
//normal = float3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
normal = float3( 0, 0, 1 );
T = gc_camRight;
// Pull out local vars we need for work.
@ -166,15 +166,6 @@ void foliageProcessVert( inout float3 position,
texCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
// Animate the normal to get lighting changes
// across the the wind swept foliage.
//
// TODO: Expose the 10x as a factor to control
// how much the wind effects the lighting on the grass.
//
normal.xy += wind.xy * ( 10.0 * texCoord.w );
normal = normalize( normal );
// Get the alpha fade value.
float fadeStart = gc_fadeParams.x;

View file

@ -124,7 +124,7 @@ void foliageProcessVert( inout vec3 position,
in vec3 eyePos )
{
// Assign the normal and tagent values.
//normal = vec3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
normal = vec3( 0, 0, 1 );
T = gc_camRight;
// Pull out local vars we need for work.
@ -166,15 +166,6 @@ void foliageProcessVert( inout vec3 position,
texCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
// Animate the normal to get lighting changes
// across the the wind swept foliage.
//
// TODO: Expose the 10x as a factor to control
// how much the wind effects the lighting on the grass.
//
normal.xy += wind.xy * ( 10.0 * texCoord.w );
normal = normalize( normal );
// Get the alpha fade value.
float fadeStart = gc_fadeParams.x;

View file

@ -393,21 +393,18 @@ void dampen(inout Surface surface, sampler2D WetnessTexture, float accumTime, fl
{
if (degree<=0.0) return;
vec3 n = abs(surface.N);
float ang = dot(float3(0,0,-1),surface.N);
float grav = 2.0-pow(ang,3);
if (grav<0) grav*=-1.0;
float ang = clamp(n.z, 0.04, 0.96);
float speed = accumTime*(1.0-surface.roughness)*grav;
vec2 wetoffset = vec2(speed,speed/2)*0.1;
float speed = accumTime*(1.0-surface.roughness)*ang;
vec2 wetoffset = vec2(speed,speed/2);
float wetness = texture(WetnessTexture, vec2(surface.P.xy*0.2+wetoffset)).b;
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zx*0.2+wetoffset)).b,n.y);
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zy*0.2+wetoffset)).b,n.x);
wetness = pow(wetness,3)*degree;
float wetness = texture(WetnessTexture, vec2(surface.P.xy*0.1+wetoffset)).b;
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zx*0.1+wetoffset)).b,n.y);
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zy*0.1+wetoffset)).b,n.x);
wetness = pow(wetness*ang*degree,3);
surface.roughness = lerp(surface.roughness,(1.0-wetness*surface.roughness)*0.92f+0.04f,ang);
surface.baseColor.rgb = lerp(surface.baseColor.rgb*(2.0-wetness),surface.baseColor.rgb,ang*surface.roughness);
surface.roughness = lerp(surface.roughness, 0.04f, wetness);
surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.96+vec3(0.04,0.04,0.04), pow(wetness,5));
updateSurface(surface);
}

View file

@ -396,20 +396,18 @@ void dampen(inout Surface surface, TORQUE_SAMPLER2D(WetnessTexture), float accum
{
if (degree<=0.0) return;
float3 n = abs(surface.N);
float ang = dot(float3(0,0,-1),surface.N);
float grav = 2.0-pow(ang,3);
if (grav<0) grav*=-1.0;
float ang = clamp(n.z, 0.04, 0.96);
float speed = accumTime*(1.0-surface.roughness)*grav;
float2 wetoffset = float2(speed,speed/2)*0.1;
float speed = accumTime*(1.0-surface.roughness)*ang;
float2 wetoffset = float2(speed,speed/2);
float wetness = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.2+wetoffset)).b;
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zx*0.2+wetoffset)).b,n.y);
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.2+wetoffset)).b,n.x);
wetness = pow(wetness,3)*degree;
float wetness = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.1+wetoffset)).b;
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zx*0.1+wetoffset)).b,n.y);
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.1+wetoffset)).b,n.x);
wetness = pow(wetness*ang*degree,3);
surface.roughness = lerp(surface.roughness,(1.0-wetness*surface.roughness)*0.92f+0.04f,ang);
surface.baseColor.rgb = lerp(surface.baseColor.rgb*(2.0-wetness),surface.baseColor.rgb,ang*surface.roughness);
surface.roughness = lerp(surface.roughness, 0.04f, wetness);
surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.96+float3(0.04,0.04,0.04), pow(wetness,5));
surface.Update();
}