Dear all,
I am trying to write a script to automatically convert Vray Materials to FX-Shader for later converting them to a separate scene for a realtime engine. The script does automatically parse the materials and recursively goes through all texture nodes (also procedural). Now I have a bit of trouble to work with the fresnel formula. I understand the concept of fresnel and got in the internet a simplified formula to approximate fresnel. The formula somehow works in the shader, but the fresnel reflection is always much darker than the rendered fresnel in VRay. Can anybody tell me what is wrong with this approximation?
//fragment shader excerpt
float3 psOutNormal = normalize(psIn.PSiNormal.xyz);
float3 psOutViewDir = normalize(psIn.PSiViewDir);
CUV = normalize( reflect( psOutViewDir, psOutNormal).xzy);
CUV.y = -CUV.y;
CUV.x = -CUV.x;
env = pow(texCUBE(g_ReflectionSampler, CUV), 0.454); //gamma correct HDR-cubemaps
float nAirIOR = 1.000293;
float matIOR = 1.6; //example
float R0 = pow((nAirIOR - matIOR), 2) / pow ((nAirIOR + matIOR), 2);
blendAmount = R0 + (1 - R0) * pow (1.0 - dot(psOutNormal, psOutViewDir ), 5.0 );
psOut.Colour.rgb = lerp(diff * light, env, blendAmount); //diff is diffuse texture or color, light is hdr-lightmap texturebaked within max. In my example both are completely black, as the vray shader is in this example, just the reflection is white with fresnel index.
Rendered Scene with reflection color rgb pure white, no camera exposure, diffuse and refraction pure black, gammacorrected:
Rendered Scene with reflection color rgb pure white, no camera exposure, fresnel reflections IOR1.6, diffuse and refraction pure black, gammacorrected:
Cubemap rendered from max (somehow 20% brighter., but doesn't matter, rendered from the center of the sphere, box camera, no exposure):
Vertical cross converted to dds for fx-shaders in Max:
This is a screenshot from Max with the fx-shader applied on the sphere only. See that it is much darker than the fresnel of 1.6 in Vray:
Can anybody help me on this?
Thanks!
I am trying to write a script to automatically convert Vray Materials to FX-Shader for later converting them to a separate scene for a realtime engine. The script does automatically parse the materials and recursively goes through all texture nodes (also procedural). Now I have a bit of trouble to work with the fresnel formula. I understand the concept of fresnel and got in the internet a simplified formula to approximate fresnel. The formula somehow works in the shader, but the fresnel reflection is always much darker than the rendered fresnel in VRay. Can anybody tell me what is wrong with this approximation?
//fragment shader excerpt
float3 psOutNormal = normalize(psIn.PSiNormal.xyz);
float3 psOutViewDir = normalize(psIn.PSiViewDir);
CUV = normalize( reflect( psOutViewDir, psOutNormal).xzy);
CUV.y = -CUV.y;
CUV.x = -CUV.x;
env = pow(texCUBE(g_ReflectionSampler, CUV), 0.454); //gamma correct HDR-cubemaps
float nAirIOR = 1.000293;
float matIOR = 1.6; //example
float R0 = pow((nAirIOR - matIOR), 2) / pow ((nAirIOR + matIOR), 2);
blendAmount = R0 + (1 - R0) * pow (1.0 - dot(psOutNormal, psOutViewDir ), 5.0 );
psOut.Colour.rgb = lerp(diff * light, env, blendAmount); //diff is diffuse texture or color, light is hdr-lightmap texturebaked within max. In my example both are completely black, as the vray shader is in this example, just the reflection is white with fresnel index.
Rendered Scene with reflection color rgb pure white, no camera exposure, diffuse and refraction pure black, gammacorrected:
Rendered Scene with reflection color rgb pure white, no camera exposure, fresnel reflections IOR1.6, diffuse and refraction pure black, gammacorrected:
Cubemap rendered from max (somehow 20% brighter., but doesn't matter, rendered from the center of the sphere, box camera, no exposure):
Vertical cross converted to dds for fx-shaders in Max:
This is a screenshot from Max with the fx-shader applied on the sphere only. See that it is much darker than the fresnel of 1.6 in Vray:
Can anybody help me on this?
Thanks!
Comment