HLSL Multitexturing

Started by
7 comments, last by dhanji 19 years, 6 months ago
Ok I am compiling my pixel shader for 1.4 and am trying to apply multiple textures:

//Pixel Shader
    PS_OUTPUT Output;
    Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV);
    Output.RGBColor *= tex2D(MeshTexture2Sampler, In.TextureUV);

    return Output;

Now this makes my screen go black, but if I use just one texture sampler I get the texture displaying correctly (so I know the textures are going into the shader fine). Also I am compiling for PS_1_4 which I know supports upto 4 sampling instructions (and I'm only trying to do 2). Any ideas? Also this displays texture 2 correctly:

    Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV);
    Output.RGBColor = tex2D(MeshTexture2Sampler, In.TextureUV);
so I know 2 samples are working. Just not modulating, why oh why? I even tried this:

    Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV);
    Output.RGBColor *= tex2D(MeshTexture2Sampler, In.TextureUV);
    Output.RGBColor.a = 1.0;
in case the alpha was being messed with. no dice, still a black screen.
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)
Advertisement
Try
Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * tex2D(MeshTexture2Sampler, In.TextureUV);


I'm not 100% sure how it works in HLSL but I don't think you can read from the output values (like *= does)
thanks I thought it was a good idea, but it dint work =(
any others?
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)
ok I figured it out, you have to use different texture coordinates (or rebuild the existing one) like so:

In.TextureUV.xy += 0.000000001f; // < 1 texel


then you have to buffer it to a register, and then swizzle it into the color components (direct multiply doesnt work):

    Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV);    In.TextureUV.xy += 0.000000001f; // < 1 texel    float4 clr2 = tex2D(MeshTexture2Sampler, In.TextureUV);    Output.RGBColor.rgb *= clr2.rgb;


this works fine.
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)
If I were you, I'd inspect the asm output generated by fxc to know what was wrong with the initial version.

yea that's a good idea. I think the problem is that it's unable to read from the same register twice?
The same thing happens when I try to access the clr2 "variable" a second time.
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)
that is very odd behaviour (maybe even undefined) have you contacted MS tech support about this?

also, what video card and drivers are you using?
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
ps_1_4 allows the usage of the same texture coordinate for several texture lookups, so that should work. ps_1_3 needs separate texture coordinates though.
no I havent contacted ms. heh.
I have an ATI Radeon 9000 mobility running CATALYST 6.14.10.6348. I havent updated in awhile, maybe thats the problem?

I definitely narrowed it down to the unable to read from same register twice, issue.
Right now Im having to sample the 2nd texture twice over in the same pass.
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)

This topic is closed to new replies.

Advertisement