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

HLSL Env Mapping

Started by BlackDragon Dec 20, 2005 at 2:12 PM 2 replies 1k views
Original Post
BlackDragon
BlackDragon
Hello, I am trying to create a water plane that reflects the enviroment above it. But I am not having much success. I am trying to learn using the HDR HLSL env mapping demo included in the SDK. I belive the problem lies in the shader.
[Source]

//-----------------------------------------------------------------------------
// Vertex Shader: HDRVertEnvMap
// Desc: Process vertex for HDR environment mapping
//-----------------------------------------------------------------------------
void HDRVertEnvMap( float4 vPos : POSITION,
                    float3 vNormal : NORMAL,
                    float2 vTexCoord0 : TEXCOORD0,
                    out float4 oPos : POSITION,
                    out float3 EnvTex : TEXCOORD0 )
{


	//g_mWorld = mul(g_mWorld, g_mView);
	
    //
    // Transform position to view space
    //
    oPos = mul( vPos, mul(g_mWorld,g_mView));

    //
    // Compute normal in camera space
    //
    float3 vN = mul( vNormal, g_mWorld );
    vN = normalize( vN );

    //
    // Obtain the reverse eye vector
    //
    float3 vEyeR = -normalize( oPos );

    //
    // Compute the reflection vector
    //
    float3 vRef = 2 * dot( vEyeR, vN ) * vN - vEyeR;

    //
    // Store the reflection vector in texcoord0
    //
    EnvTex = vRef;

    //
    // Apply the projection
    //
    oPos = mul( oPos, g_mProj );

}

//-----------------------------------------------------------------------------
// Pixel Shader: HDRPixEnvMap
// Desc: Process pixel for HDR environment mapped object
//-----------------------------------------------------------------------------
float4 HDRPixEnvMap( float3 Tex : TEXCOORD0 ) : COLOR
{
	return 1.0 * texCUBE( g_samCubeMap, Tex );
}
[/Source]
jollyjeffers
jollyjeffers
I don't have any ideas off the top of my head, but you might find that a better description will get you more response..

What exactly is "not having much success"?
  1. Compilation errors?
  2. D3D runtime errors?
  3. Incorrect results
    1. Wrong colours being outputted
    2. No colours being outputted


hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
BlackDragon
BlackDragon
What I mean by not much success is the reflections appear to be totaly wrong, there is something being reflected but its not what i expect. I have a Height map with a plane cutting across it(water plane) and Im trying to get the water plane to reflect the terrain above it. the reflection what appears on the water plane is terrain but I cant id what part of the terrain is being reflected.
jollyjeffers
jollyjeffers
Okay... are you sure that your environment cube map is correctly constructed? have you displayed it on-screen (or saved it to disk) to verify that the contents are correct?

I don't have my tools in front of me, but I presume that FX file is the same as in the SDK?

A good avenue to explore is where your application differs from the SDK. Is the data you're passing into the effect in the same form as the SDK is (e.g. same coordinate space).

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |

Topic Locked

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

Sign in to reply to this topic.