Help with compiling CubeMaps in HLSL

Started by
10 comments, last by rpsathe 18 years, 4 months ago
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)); vTotalLightDiffuse += g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir)) ; //vTotalLightDiffuse += g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir)) ; } 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
Advertisement
test.
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
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
Why exactly do you need vertex texturing for cubemaps? O_o
I believe texture lookups are for vertex shader 3.0 only.
--m_nPostCount++
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
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);

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
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
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.

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, 0.0f) );

See if that works for you.

neneboricua

This topic is closed to new replies.

Advertisement