Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fixed CalculateSpecular( fixed3 lDir, fixed3 vDir, fixed3 norm, fixed spec, fixed3 tangent )
- {
- float3 halfVector = normalize( lDir + vDir );
- float specDot = saturate( dot( halfVector, norm ) );
- float diffuseDot = saturate( dot( lDir, norm ) );
- float fresnelDot = min( 1.0, dot( vDir, norm ) );
- float dotHTAlphaX = dot( halfVector, tangent ) / _BRDFRoughnessX;
- float dotHBAlphaY = dot( halfVector, cross( norm, tangent ) ) / _BRDFRoughnessY;
- float BRDF = sqrt( saturate( diffuseDot / fresnelDot ) )
- * exp( -2.0 * ( dotHTAlphaX * dotHTAlphaX
- + dotHBAlphaY * dotHBAlphaY ) / ( 1.0 + specDot ) );
- float rimCore = 1.0 - saturate( fresnelDot );
- float rim = rimCore + ( pow( rimCore, _FresnelPower ) * 2.0 );
- rim *= specDot;
- float doubleSpec = ( ( _SecondaryBlob * pow( specDot, _Gloss * 16.0 ) )
- + ( pow( specDot, _Gloss * 128.0 ) * _PrimaryBlob ) ) * 2.5;
- float SpecularCore = lerp( BRDF * 0.75, doubleSpec, _BRDFAmount );
- return spec * ( ( rim * _AmbientRim ) + ( _FresnelMult * rim + _FresnelDilute ) * SpecularCore );
- }
Advertisement
Add Comment
Please, Sign In to add comment