@property( envprobe_map )
vec3 specDir = 2.0 * dot( viewDir, nNormal ) * nNormal - viewDir;
vec3 diffDir = dot( viewDir, nNormal ) * nNormal;
vec3 envColourSpec = textureLod( texEnvProbeMap, specDir * pass.invViewMatCubemap, ROUGHNESS * 12.0 ).xyz;
vec3 envColourDiff = textureLod( texEnvProbeMap, diffDir * pass.invViewMatCubemap, 10.0 ).xyz;
@property( !hw_gamma_read )//Gamma to linear space
envColourSpec = envColourSpec * envColourSpec;@end
finalColour += cookTorrance( diffDir, viewDir, 10000, envColourDiff, envColourSpec );@end
float fresnel = pow( (1- dot(viewDir,nNormal)), ROUGHNESS*3+4.5 );
fresnel = fresnel * ( 1.0 - ROUGHNESS*0.7 );
(1-(material.kS.xyz @insertpiece( MulSpecularMapValue )))*(material.kD.xyz * lightDiffuse @insertpiece( MulDiffuseMapValue ))
vec3 reflection = (material.kS.xyz * lightSpecular @insertpiece( MulSpecularMapValue ) );
vec3 reflection = (material.kS.xyz * lightSpecular @insertpiece( MulSpecularMapValue ) );
return (reflection + NdotL *( (1-(material.kS.xyz @insertpiece( MulSpecularMapValue )))*(material.kD.xyz * lightDiffuse @insertpiece( MulDiffuseMapValue )) ) + G*fresnel*lightSpecular + material.kS.xyz*brightSpot );
vec3 cookTorrance( vec3 lightDir, vec3 viewDir, float NdotV, vec3 lightDiffuse, vec3 lightSpecular )
{
vec3 halfWay= normalize( lightDir + viewDir );
float NdotL = clamp( dot( nNormal, lightDir ), 0.0, 1.0 );
float NdotH = clamp( dot( nNormal, halfWay ), 0.001, 1.0 );
float VdotH = clamp( dot( viewDir, halfWay ), 0.001, 1.0 );
float sqR = max(0.004,ROUGHNESS * ROUGHNESS);
float roughPow = max( 0.004,pow(ROUGHNESS,5) );
float fresnel = pow( (1- dot(viewDir,nNormal)), ROUGHNESS*3+4.5 );
fresnel = fresnel * ( 1.0 - ROUGHNESS*0.7 );
//Roughness term (Beckmann distribution)
//Formula:
// Where alpha = NdotH and m = roughness
// R = [ 1 / (m^2 x cos(alpha)^4 ] x [ e^( -tan(alpha)^2 / m^2 ) ]
// R = [ 1 / (m^2 x cos(alpha)^4 ] x [ e^( ( cos(alpha)^2 - 1 ) / (m^2 cos(alpha)^2 ) ]
float NdotH_sq = NdotH * NdotH;
float roughness_a = 1.0 / ( 3.141592654 * roughPow * NdotH_sq * NdotH_sq );//( 1 / (m^2 x cos(alpha)^4 )
float roughness_b = NdotH_sq - 1.0; //( cos(alpha)^2 - 1 )
float roughness_c = roughPow * NdotH_sq; //( m^2 cos(alpha)^2 )
//Avoid Inf * 0 = NaN; we need Inf * 0 = 0
float R = min( roughness_a, 65504.0 ) * exp( 7*roughness_b / roughness_c );
//Geometric term
float shared_geo = 2.0 * NdotH / VdotH;
float geo_b = shared_geo * NdotV;
float geo_c = shared_geo * NdotL;
float G = min( 1.0, min( geo_b, geo_c ) );
//Avoid very small denominators, they go to NaN or cause aliasing artifacts
@insertpiece( FresnelType ) Rs = ( 2 * (R * G) ) / max( 20.0 * NdotV * NdotL, 0.01 );
vec3 brightSpot = Rs*lightDiffuse;
vec3 reflection = (material.kS.xyz * lightSpecular @insertpiece( MulSpecularMapValue ) );
G = min(1.0,100*G); //remove white pixels on border?
return (reflection + NdotL *( (1-(material.kS.xyz @insertpiece( MulSpecularMapValue )))*(material.kD.xyz * lightDiffuse @insertpiece( MulDiffuseMapValue )) ) + G*fresnel*lightSpecular + material.kS.xyz*brightSpot );
}
Jayray wrote:how do you set the env map?
Ogre::HlmsTextureManager::TextureLocation texLocation = hlmsTextureManager->
createOrRetrieveTexture( "SaintPetersBasilica.dds",
Ogre::HlmsTextureManager::TEXTURE_TYPE_ENV_MAP );
datablock->setTexture( Ogre::PBSM_REFLECTION, texLocation.xIdx, texLocation.texture );
Crystal Hammer wrote:Is this also possible with dynamic reflections? I.e. would require that render to cubemap textures will have auto generated mip-maps too. Is this possible and any idea if it drops fps much? (I already asked on other topic )
float3 diffColor = diffuse.rgb * (1.0 - metalness);
float3 specularColor = lerp(specularLevel, diffuse.rgb, metalness);
PiroKun wrote:[*]In the actual default we have the impression that the [specular colour + fresnel value] should be in fresnel, but fresnel just accepts a value, not a texture, so there is a problem here.
Another important point (that affects both SeparateDiffuseFresnel and Default/CookTorrance )is that roughness affects the final reflection.
We don't know how are the exact math of this, but roughness should decrease the final reflectivity of the material (including at grazing angles), like the examples in http://www.filmicworlds.com/2014/03/17/ ... flectance/
dark_sylinc wrote:Just to be clear. Specular and coloured fresnel yield very similar results but they're not the same. Try a maxed out green fresnel vs a maxed out green specular. The inner section of a sphere material looks the same. But as we look outwards, coloured fresnel starts losing the green colour while green specular remains green.
Users browsing this forum: Crashy and 1 guest