Skip to main content
GameDev.net gamedev.net
🔒 Locked

BRDF question

Started by GambitSnax Feb 21, 2007 at 1:13 AM 2 replies 1.4k views
Original Post
GambitSnax
GambitSnax
I've been looking into implementing a BRDF reflection on some objects using directx 9.0c and a HLSL shader. I'm a little confused on the theory however. My understanding is that a particular BRDF models the properties that a specific material has (say gold) when light hits it. So you use two different cube maps and simply calculate the reflected vector from the camera to the object and determine the texture coordinates for the two cube maps. My question is if the input position into both cube maps is the same, why do you need two separate cube maps? Couldn't you just merge them into one and save the calculation. Obviously this isn't correct and there is a simple, logical explanation. Is it that you don't simply use the reflected vector of the object to calculate the environment map texture coordinate? Or that the two cube map positions are calculated in a different way each, to give you two different positions on each cube map. Cheers.
Ashkan
Ashkan
Chapter 6 of real-time rendering by Akenine-Moller and Haines contains an excellent overview of the subject and the theory behind it plus a lot of references for further investigations. No API-specific code is provided though. I strongly encourage you to read it, if you want to gain a deep insight.
GambitSnax
GambitSnax
Thanks for that. I've put the book on order. Unfortunately living in Australia means the book won't get here for a month.

In the interim, can anyone tell me how to calculate the texture coordinates for the two cube maps used within the BRDF? Is it based on the normal and the incoming light direction? Or do I need more information that that? I keep seeing them refer to the incoming angle and offset and outgoing angle and offset, but nowhere can I find how you use this to generate coordinates into the cube map...

Cheers.
GambitSnax
GambitSnax
Ok i've done some more searching and found a way to calculate them via the D and H cube maps. I've implemented it into a shader but am getting some strange results.

I've included the vertex and pixel shader code. Can anyone tell me where a potential problem might be?

VSOutput VS(VSInput a_Input){	VSOutput Output;        	Output.pos = mul(float4(a_Input.pos, 1.0f), g_matWorldViewProjection);        // calculate world position	float3 posW = mul(float4(a_Input.pos, 1.0f), g_matWorld);	float3 toEye = normalize(g_vecCameraPos - posW);	float3 toLight = normalize(g_vecLightPos - posW);	float3 halfVec = normalize(toEye + toLight);        // H cubemap coordinates	Output.coordH.x = dot(halfVec, a_Input.tan);	Output.coordH.y = dot(halfVec, a_Input.bi);	Output.coordH.z = dot(halfVec, a_Input.norm);	float3 tPrime = normalize(a_Input.tan - (halfVec*dot(a_Input.tan, halfVec)));	float3 bPrime = normalize(cross(halfVec, tPrime));        // D cubemap coordinate	Output.coordD.x = dot(toLight, tPrime);	Output.coordD.y = dot(toLight, bPrime);	Output.coordD.z = dot(toLight, halfVec);	float3 norm = normalize(mul(float4(a_Input.norm, 0.0f), g_matWorldInverseTranspose).xyz);	float diffuseVal = max(dot(toLight, norm), 0.0f);	Output.col = diffuseVal * (g_vecLightDiffuse * g_vecMaterialDiffuse);return Output;}float4 PS (VSOutput a_Input) : COLOR{	float3 colH = texCUBE(CubeMapH, a_Input.coordH);	float3 colD = texCUBE(CubeMapD, a_Input.coordD);	return float4(colH + colD, 1.0f) * a_Input.col;}


Any suggestions?

Cheers.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.