Heya people, how you doing?
I was taking a gander on some materials from the Source engine, and came across this line:
$FRESNELWARP "fresnelranges"
From what I understood, it's basically a textures that wraps around the model, but with a Fresnel as it's feed? Although I'm not too sure about it.
I also tried looking for the written shaders, but cannot find them, so if anyone has any idea what I need to do, that would be grand.
Replies
float3 vReflect = reflect( -vEyeDir, vWorldNormal ); // Reflect view through normal float LdotR = saturate(dot( vReflect, vLightDir )); // L.R (use half-angle instead?) specularLighting = pow( LdotR, fSpecularExponent ); // Raise to specular exponent // Optionally warp as function of scalar specular and fresnel if ( bDoSpecularWarp ) specularLighting *= tex2D( specularWarpSampler, float2(specularLighting.x, fFresnel) ); // Sample at { (L.R)^k, fresnel } specularLighting *= saturate(dot( vWorldNormal, vLightDir )); // Mask with N.L specularLighting *= color; // Modulate with light colorI'm not 100% sure though. Test it out!Here is what I mean:
Just to be clear, you code worked perfectly fine with the Fresnel Warping lookup texture, so much kudos for that.
In the document, it's also talking about a warp color texture, which is supposed to be related to the Fresnel Warp, but I have no idea what it is and my google-fu in said terms is coming up empty.
If you (or anyone else) have hints on what it could be, that would be very much appreciated, because I'm honestly lost on what a 3D Texture which looks like a UV Map is supposed to be or if I'm reading too much into it and it's infact a simple XYZ projection.
Cheers!
// fResult is a saturated dot(N, L); // Don't forget half lambert, if needed! saturate(NDotL * 0.5 + 0.5); if ( bDoLightingWarp ) { fResult = 2.0f * tex1D( lightWarpSampler, fResult ); }*edit* a buddy if mine has a cool implementation of this, has a neat trick for smoothing it out. http://blog.legend286.co.uk/lightwarps/
here's how the code should be all-together
float3 DiffuseTerm( float3 worldNormal, float3 lightDir) { float fResult; float NDotL = dot( worldNormal, lightDir ); // Unsaturated dot (-1 to 1 range) if ( bHalfLambert ) { fResult = saturate(NDotL * 0.5 + 0.5); // Scale and bias to 0 to 1 range if ( !bDoLightingWarp ) { fResult *= fResult; // Square } } else { fResult = saturate( NDotL ); // Saturate pure Lambertian term } float3 fOut = float3( fResult, fResult, fResult ); if ( bDoLightingWarp ) { fOut = 2.0f * tex1D( lightWarpSampler, fResult ); } return fOut; }The effect is most likely an artistic accentuation of the silhouette. The mask seems to support both effects, the light warp and the color fresnel term.
vec3 textureColor = tex2d(modelTexture, uv);
float fresnelMask = tex2d(fresnelTexture,uv);
vec3 warpedColor = tex3d(warpTexture, textureColor.rgb);
float fresnelTerm = calculateFresnelTerm(viewVector,normalVector);
float alpha = fresnelTerm * fresnelMask ;
vec3 finalColor = alpha * warpedColor + (1-alpha) * textureColor;
Exact same question I had.
Is it basically to drive the color of the fresnel?
EDIT: Duh... just read valve's pic. lol
proceed.....