Sign in to follow this  
rpsathe

Help with compiling CubeMaps in HLSL

Recommended Posts

Folks, I am trying to use a simple cube map. Nothing fancy and sample it using texCube and passing a sampler and a direction vector as input. I am getting a weird compile error that I can't track down. Here's my HLSL code for sampler texture g_txCubeMap; samplerCUBE g_samCubeMap = sampler_state { Texture = <g_txCubeMap>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; In vertex shader, I do following for(int i=0; i<nNumLights; i++ ) { temp_color = texCUBE( g_samCubeMap, normalize(g_LightDir[i])); vTotalLightDiffuse += g_LightDiffuse[i] * max(0,dot(vNormalWorldSpace, g_LightDir[i])) ; //vTotalLightDiffuse += g_LightDiffuse[i] * max(0,dot(vNormalWorldSpace, g_LightDir[i])) ; } Output.Diffuse = temp_color; temp_color and Output.Diffuse are both float4. g_LightDir[] is array of float3. when I compile using fxc I don't get any compilation errors, but at runtime I get following error - 0x80004005 which error look-up utility says HRESULT: 0x80004005 (2147500037) Name: E_FAIL Description: An undetermined error occurred Severity code: Failed Facility Code: FACILITY_NULL (0) Error Code: 0x4005 (16389) I am at a complete loss...Any help would be appreciated. I can send the whole project if someone has time. Thanks -R

Share this post


Link to post
Share on other sites
If you use the Debug Runtime, the compiler will spit out a message telling you exactly which line of your .fx file is messed up, along with some kind of reason why.

neneboricua

Share this post


Link to post
Share on other sites
Thanks for the reply. I tried looking at the output again and looked carefully this time.

I am seeing this

error X4545: vs_2_sw target does not support texture lookups
c:\Program Files\Microsoft DirectX 9.0 SDK (October 2005)\Samples\C++\Direct3D\BasicHLSL\BasicHLSL.fx(179): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
ID3DXEffectCompiler: Compilation failed

Apparantly in vs_2_sw texture look-ups are not supported.
Now what I don't understand is _sw should support everything that regular vs2 supprots. I checked my device's CAPs for CubeTextureFilterCaps and I see all the min and mag filters. This to me, means CubeMaps are supported on my hardware.

So I now I know that if I toss in a VS3 compliant card it may work. But I want to understand if I am reading CAPs incorrectly?

Thanks
-Rahul

Share this post


Link to post
Share on other sites
I am implementing BRDF lighting. BRDF = bidirectional reflectance distribution function. It's a class of precomputed radiance transfer functions.

Cube-maps is the easiest way to look-up function values as they are in fact functions of directions. Cube maps are indexed using directions.

-Rahul

Share this post


Link to post
Share on other sites
Okay fellas, I am still having problems. I tossed in 7800 (Which supports shader model3, and tried to compile the shader with debug runtime.) I get following error on the line where I call texCube function.



c:\Program Files\Microsoft DirectX 9.0 SDK (October 2005)\Samples\C++\Direct3D\BasicHLSL\BasicHLSL.fx(95): error X4532: cannot map expression to vertex shader instruction set
c:\Program Files\Microsoft DirectX 9.0 SDK (October 2005)\Samples\C++\Direct3D\BasicHLSL\BasicHLSL.fx(179): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
ID3DXEffectCompiler: Compilation failed


line 95 looks like this -
temp_color = texCUBE( g_samCubeMap, g_LightDir[i]);

The error lookup gives following information

HRESULT: 0x80004001 (2147500033)
Name: E_NOTIMPL
Description: The function called is not supported at this time
Severity code: Failed
Facility Code: FACILITY_NULL (0)
Error Code: 0x4001 (16385)

I am surprised that simple cubemaps are not supported in 7800?
-Rahul

Share this post


Link to post
Share on other sites
Cubemaps are supported, but you're doing this from the vertex shader. I don't have an SM3.0 card to play with so I can't try it out but just so you can make some progress, can your algorithm handle moving the cubmap access to the pixel shader? You should be able to access the cubemap from the pixel shader just fine.

neneboricua

Share this post


Link to post
Share on other sites
Thanks man...Now I am even more bummed =(. It works inside PS but not inside VS.
I am using both shader model 3.0 for both PS and VS.

No clue why it'd do it. I thought SM3.0 releases the limit on instruction count. While randomly looking online I came across paper by Wolfgang on gamasutra that talks about the error that has similar signature.

Now my next task before calling it a day is how to get cube-maps working in vertex shaders .

Thanks a ton ..
-Rahul
PS : if you have any ideas on why it's not working inside VS...I'd appreciate if you can share.

Share this post


Link to post
Share on other sites
Looking at the documentation for the "texldl" instruction in VS 3.0 ASM shaders, it seems that you need to specify the mipmap level to access. Perhaps you could give the HLSL vertex shader code a little help in figuring this out? Try to make the second parameter to the texture fetch have a "w" compnent of 0 to specify the first mipmap level. Your HLSL code could look like this:

texCUBE( g_samCubeMap, float4(g_LightDir[i], 0.0f) );

See if that works for you.

neneboricua

Share this post


Link to post
Share on other sites
Will definitely give it a shot tomorrow. I've gotten things working for me now in PS as far as cube maps are concerned.

Thanks
-Rahul

Share this post


Link to post
Share on other sites
Hey ...I found out that texCUBE intrinsic is not supported in Vertex shader.
If you look up at msdn site, at the very bottom it says n/a under vertex shader.

Now I am happy as all my questions are answered.

Thank you very much for the help.

-Rahul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this