🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Inverted z axis in specular reflection

Started by
0 comments, last by komilll 4 years, 2 months ago

Hello,

I have a problem regarding z axis direction when presenting specular IBL. Notice that z direction is inverted and image presented to user is alongside his view.

Specular IBL - wrong direction
float4 main(PixelInputType input) : SV_TARGET
{	
	input.normal = normalize(input.normal);
	input.tangent = normalize(input.tangent);
	input.binormal = normalize(input.binormal);

	float3x3 TBN = transpose(float3x3(input.tangent, input.binormal, input.normal));
	float3 N = normalTexture.Sample(baseSampler, input.uv).rgb * 2.0 - 1.0;
	N = normalize(mul(TBN, N));

	const float3 V = normalize(input.viewDir.xyz);
	const float NoV = abs(dot(N, V)) + 0.0001f; //avoid artifact - as in Frostbite
	const float3 R = 2.0 * NoV * N - V;

	const float3 prefilteredSpecular = specularIBLTexture.SampleLevel(baseSampler, R, roughness * 5.0);
	return float4(prefilteredSpecular, 1.0f);
}

Where input.viewDir is defined in VS as and g_viewerPosition is camera position in world space.

	float4 positionWS = mul(output.position, worldMatrix);
	output.viewDir.xyz = normalize(g_viewerPosition.xyz - positionWS.xyz);

This topic is closed to new replies.

Advertisement