mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-26 14:55:39 +00:00
Merge pull request #1394 from Azaezel/alpha41/wetWipes
reduce redundant calcs for the dampen method.
This commit is contained in:
commit
7d431e48a2
4 changed files with 20 additions and 43 deletions
|
|
@ -124,7 +124,7 @@ void foliageProcessVert( inout float3 position,
|
||||||
in float3 eyePos )
|
in float3 eyePos )
|
||||||
{
|
{
|
||||||
// Assign the normal and tagent values.
|
// Assign the normal and tagent values.
|
||||||
//normal = float3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
|
normal = float3( 0, 0, 1 );
|
||||||
T = gc_camRight;
|
T = gc_camRight;
|
||||||
|
|
||||||
// Pull out local vars we need for work.
|
// 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.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||||
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
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.
|
// Get the alpha fade value.
|
||||||
|
|
||||||
float fadeStart = gc_fadeParams.x;
|
float fadeStart = gc_fadeParams.x;
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ void foliageProcessVert( inout vec3 position,
|
||||||
in vec3 eyePos )
|
in vec3 eyePos )
|
||||||
{
|
{
|
||||||
// Assign the normal and tagent values.
|
// Assign the normal and tagent values.
|
||||||
//normal = vec3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
|
normal = vec3( 0, 0, 1 );
|
||||||
T = gc_camRight;
|
T = gc_camRight;
|
||||||
|
|
||||||
// Pull out local vars we need for work.
|
// 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.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||||
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
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.
|
// Get the alpha fade value.
|
||||||
|
|
||||||
float fadeStart = gc_fadeParams.x;
|
float fadeStart = gc_fadeParams.x;
|
||||||
|
|
|
||||||
|
|
@ -393,21 +393,18 @@ void dampen(inout Surface surface, sampler2D WetnessTexture, float accumTime, fl
|
||||||
{
|
{
|
||||||
if (degree<=0.0) return;
|
if (degree<=0.0) return;
|
||||||
vec3 n = abs(surface.N);
|
vec3 n = abs(surface.N);
|
||||||
|
float ang = clamp(n.z, 0.04, 0.96);
|
||||||
float ang = dot(float3(0,0,-1),surface.N);
|
|
||||||
float grav = 2.0-pow(ang,3);
|
|
||||||
if (grav<0) grav*=-1.0;
|
|
||||||
|
|
||||||
float speed = accumTime*(1.0-surface.roughness)*grav;
|
float speed = accumTime*(1.0-surface.roughness)*ang;
|
||||||
vec2 wetoffset = vec2(speed,speed/2)*0.1;
|
vec2 wetoffset = vec2(speed,speed/2);
|
||||||
|
|
||||||
float wetness = texture(WetnessTexture, vec2(surface.P.xy*0.2+wetoffset)).b;
|
float wetness = texture(WetnessTexture, vec2(surface.P.xy*0.1+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.zx*0.1+wetoffset)).b,n.y);
|
||||||
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zy*0.2+wetoffset)).b,n.x);
|
wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zy*0.1+wetoffset)).b,n.x);
|
||||||
wetness = pow(wetness,3)*degree;
|
wetness = pow(wetness*ang*degree,3);
|
||||||
|
|
||||||
surface.roughness = lerp(surface.roughness,(1.0-wetness*surface.roughness)*0.92f+0.04f,ang);
|
surface.roughness = lerp(surface.roughness, 0.04f, wetness);
|
||||||
surface.baseColor.rgb = lerp(surface.baseColor.rgb*(2.0-wetness),surface.baseColor.rgb,ang*surface.roughness);
|
surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.96+vec3(0.04,0.04,0.04), pow(wetness,5));
|
||||||
updateSurface(surface);
|
updateSurface(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -396,20 +396,18 @@ void dampen(inout Surface surface, TORQUE_SAMPLER2D(WetnessTexture), float accum
|
||||||
{
|
{
|
||||||
if (degree<=0.0) return;
|
if (degree<=0.0) return;
|
||||||
float3 n = abs(surface.N);
|
float3 n = abs(surface.N);
|
||||||
float ang = dot(float3(0,0,-1),surface.N);
|
float ang = clamp(n.z, 0.04, 0.96);
|
||||||
float grav = 2.0-pow(ang,3);
|
|
||||||
if (grav<0) grav*=-1.0;
|
|
||||||
|
|
||||||
float speed = accumTime*(1.0-surface.roughness)*grav;
|
float speed = accumTime*(1.0-surface.roughness)*ang;
|
||||||
float2 wetoffset = float2(speed,speed/2)*0.1;
|
float2 wetoffset = float2(speed,speed/2);
|
||||||
|
|
||||||
float wetness = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.2+wetoffset)).b;
|
float wetness = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.1+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.zx*0.1+wetoffset)).b,n.y);
|
||||||
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.2+wetoffset)).b,n.x);
|
wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.1+wetoffset)).b,n.x);
|
||||||
wetness = pow(wetness,3)*degree;
|
wetness = pow(wetness*ang*degree,3);
|
||||||
|
|
||||||
surface.roughness = lerp(surface.roughness,(1.0-wetness*surface.roughness)*0.92f+0.04f,ang);
|
surface.roughness = lerp(surface.roughness, 0.04f, wetness);
|
||||||
surface.baseColor.rgb = lerp(surface.baseColor.rgb*(2.0-wetness),surface.baseColor.rgb,ang*surface.roughness);
|
surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.96+float3(0.04,0.04,0.04), pow(wetness,5));
|
||||||
surface.Update();
|
surface.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue