Files
tech5/bin/base/generated/decls/renderprog/environmentsinglemodulateadd.decl
2026-08-09 04:23:10 -07:00

89 lines
2.9 KiB
Plaintext

{
// attached environment maps are added on to surfaces at all times, without changing
parms {
stageSort sortTrans
}
state {
blend GL_ONE GL_SRC_ALPHA
depthfunc GL_LEQUAL
depthMask
}
hlsl_vp {
#include "skinning_normals.inc"
result.position.x = dot4( position, $mvpMatrixX );
result.position.y = dot4( position, $mvpMatrixY );
result.position.z = dot4( position, $mvpMatrixZ );
result.position.w = dot4( position, $mvpMatrixW );
// Convert back from 16 bit vertex elements.
float2 texcoord0 = vertex.texcoord0 * $vertexStScaleBias.xy + $vertexStScaleBias.zw;
// texture 1 takes the base coordinates
result.texcoord1 = texcoord0.xyxy;
// texture 0 takes the dir to the viewer
result.texcoord0.x = dot4( position, $modelMatrixX );
result.texcoord0.y = dot4( position, $modelMatrixY );
result.texcoord0.z = dot4( position, $modelMatrixZ );
result.texcoord0.xyz -= $globalViewOrigin.xyz;
result.texcoord0.w = -( clamp( result.position.w - $fogStart.x, 0.0, $fogEnd.x ) * $fogScale.x );
// transform local normal to world space
result.texcoord2.x = dot3( normal, $modelMatrixX );
result.texcoord2.y = dot3( normal, $modelMatrixY );
result.texcoord2.z = dot3( normal, $modelMatrixZ );
result.texcoord2.w = 1.0;
result.color = $color;
}
hlsl_fp {
// sample environment mask and modulate channel
half4 transColor = tex2D( $transMap, fragment.texcoord1.xy );
// normalize the normal
float3 globalNormal = normalize( fragment.texcoord2.xyz );
//-------------------------------------------
// normalize the direction to the viewer
float3 toViewer = normalize( -fragment.texcoord0.xyz );
// calculate the grazing fraction
float graze = saturate( dot3( toViewer, globalNormal ) );
graze = saturate( ( $viewGraze.x - max( graze, -graze ) ) / ( $viewGraze.x + 0.0001 ) );
// the scale factor will be a lerp between envScale and envGrazingScale
graze = lerp( $envScale.x, $envGrazingScale.x, graze );
// calculate the specular reflection vector from viewer and globalNormal
half4 reflection;
reflection.xyz = ( 2.0 * globalNormal * dot3( globalNormal, toViewer ) ) - toViewer;
reflection.w = 0;
// load up the environment value from the reflection vector
half3 color = texCUBElod( $dynamicEnvMap, reflection ).xyz;
// modulate by the environment mask map
color *= transColor.xyz;
color *= $exposure.xyz;
color *= fragment.color.xyz;
// and the combined grazing scale
color *= graze;
// and then premultiply with modulate channel
color *= transColor.w * fragment.color.w;
// figure out fog amount
float fog = saturate( exp2( fragment.texcoord0.w ) );
// lerp towards 0.0 by the fog factor so additive color rgb results in no changes to the backbuffer
result.color.xyz = lerp( _float3( 0.0 ), color.xyz, fog );
// lerp towards 1.0 by the fog factor so that the modulate results in no changes to the backuffer
result.color.w = lerp( 1.0, transColor.w * fragment.color.w, fog );
}
}