Statistics: Posted by Franck — 11 Mar 2016, 17:28
/// ComputeLight
///
/// Computes the sun's contribution to the pixel's color given the dot product
/// of the light direction and surface normal. The dot product is precomputed
/// since other portions of the pixel shader might need it (and we need to reuse
/// as many calculations as possible.)
float3 ComputeLight( float dotLightNormal, float attenuation)
{
/// Typical L.N calculation.
float3 light = sunDiffuse * saturate( dotLightNormal ) * attenuation + sunAmbient;
/// The following will "fill in" the shadow color proportional to the absence of light.
/// This considers the absence of light due to shadows and surface normals pointing away from the light.
/// This way all dark areas match (very cool.)
return lightMultiplier * light + ( 1 - light ) * shadowFill;
}
/// UnitFalloffPS
///
/// - Similar to unit shader, with the exception that it uses the diffuse texture alpha
/// channel to mask area's in which the view dependant lookup texture is sampled.
/// Only works in Medium and High fidelity.
///
float4 UnitFalloffPS( NORMALMAPPED_VERTEX vertex, uniform bool hiDefShadows) : COLOR0
{
if ( 1 == mirrored ) clip(vertex.depth.x);
float3x3 rotationMatrix = float3x3( vertex.binormal, vertex.tangent, vertex.normal);
float3 normal = ComputeNormal( normalsSampler, vertex.texcoord0.zw, rotationMatrix);
float dotLightNormal = dot(sunDirection,normal);
float4 diffuse = tex2D( albedoSampler, vertex.texcoord0.xy);
float4 specular = tex2D( specularSampler, vertex.texcoord0.xy);
float3 environment = texCUBE( environmentSampler, reflect( -vertex.viewDirection, normal));
// Calculate lookup into falloff ramp
float NdotV = pow(1 - saturate(dot( normalize(vertex.viewDirection), normal )), 0.6);
float4 fallOff = tex2D( falloffSampler, float2(NdotV,vertex.material.x));
// Calculate specular highlights based on current sun direction
float3 reflection = reflect( sunDirection, normal);
float specularAmount = saturate( dot( reflection, -vertex.viewDirection));
float3 phongAdditive = float3 (0.5,0.6,0.7) * pow( specularAmount, 9) * specular.g;
// Calculate environment map reflection
environment *= specular.r * fallOff.a;
// Calculate lighting and shadows
float shadow = 0; // ComputeShadow( vertex.shadow, hiDefShadows);
float3 light = sunDiffuse * saturate( dotLightNormal ) * shadow + sunAmbient;
light = light + ( 1 - light ) * shadowFill;
// Determine our final output color
float3 color = diffuse.rgb * light;
color += environment + phongAdditive;
color += (fallOff.rgb * diffuse.a);
float alpha = mirrored ? 0.5 : specular.b + glowMinimum;
return float4( color, alpha );
}
Statistics: Posted by Franck — 10 Mar 2016, 21:47
Statistics: Posted by Franck — 09 Mar 2016, 11:05
Statistics: Posted by Franck — 08 Mar 2016, 10:09