Jump to content
  • Advertisement
Sign in to follow this  
bengaltgrs

Shadow Mapping using ps 1.1

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to convert a shadow mapping tutorial that uses pixel shader version 2.0 to use version 1.1. The only place I run into trouble is with this line of the pixel shader:
float fShadowTerm = tex2D( ShadowSampler, IN.vProjCoord ) < (IN.vProjCoord.z - 0.001f) ? 0.5f : 1.0f;
When I try to compile using pixel shader verion 1.1 I get the error, "error X4520: can read from texcoord and use it for texlookup only in ps_1_4 and higher". So then I attempted to compile using version 1.4 and came up with this error, "error X4532: cannot map expression to pixel shader instruction set". Is there a way to convert this line into something pixel shader version 1.1 can handle? Thanks, -Chris [Edited by - bengaltgrs on December 2, 2005 5:23:46 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sure, it's actually just a demo project, not really a tutorial, but it shows how to do soft shadows as well as hard shadows with pixel shader 2.0. Anyways, here it is, just scroll down until you see "Soft Shadows":

http://www.shadertech.com/cgi-bin/shaders.cgi?filter=2

-Chris

Share this post


Link to post
Share on other sites
The HLSL compiler sometimes has difficulty translating HLSL code into ASM for ps1.x. In those cases, since the number of instructions you can use isn't all that high anyway, you should probably just use ASM directly.

Here's a ps1.1 pixel shader in ASM for shadow map depth comparisons

ps.1.1

def c0, 0.5, 0.5, 0.5, 0.5 // bias value
def c1, 1.0, 1.0, 1.0, 1.0 // turn on the lighting value for a given pixel
def c2, 0.0, 0.0, 0.0, 0.0 // turn off the lighting value for a given pixel

tex t0 // Texture that contains the light distance values

// Subtract the light distance from the ideal distance.
// Result is either zero or some positive value
sub r1, v1, t0

// Add 0.5 and write result to r0.a because the cnd instruction only works on r0.a
add r0.a, r1.b, c0.b

// Compare r0.a with 0.5. If r0.a is greater than 0.5,
// the final output value is set to zero and the pixel
// is in shadow. If the value of r0.a is 0.5, the final
// output is set to 1.0 and the pixel receives the full
// lighting value
cnd r0, r0.a, c2, c1

// The value of r0 is multiplied by the lighting value.
// This turns the lighting either on or off for each pixel.
mul r0, r0, v0


Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites
I see, so is there no way to use HLSL and ps 1.1 to do shadow mapping? I also added a little more than just shadow mapping to the pixel shader, it also blends some textures together for the ground mesh having the shadow cast onto it. Here is the pixel shader:


float4 PS_SceneHard( VSOUTPUT_SCENE IN ) : COLOR0
{
// Sample the color and blend maps
vector vColor = tex2D( ColorSampler, IN.vTexCoord );
vector vColor1 = tex2D( Color1Sampler, IN.vTexCoord );
vector vBlend = tex2D( BlendSampler, IN.vTexCoord );

vColor = ((vColor * vBlend.g) + (vColor1 * vBlend.b)) * vBlend.r;

// Grab the shadow term
float fShadowTerm = 0.5f;
fShadowTerm = tex2D( ShadowSampler, IN.vProjCoord ) < (IN.vProjCoord.z - 0.001f) ? 0.5f : 1.0f;

// Compute the final color
return (vColor * g_vLightColor * fShadowTerm);
}



The only area where there is a problem is when it tries to set fShadowTerm, but I do not know how to change it to work with ps 1.1. Also, I have never actually used ASM before, and was hoping to just use HLSL for everything. Any help is greatly appreciated.

Thanks,
-Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by bengaltgrs
I see, so is there no way to use HLSL and ps 1.1 to do shadow mapping?

It doesn't have anything specific to do with shadow mapping per se, its that the HLSL compiler in general sometimes has trouble compiling shaders to ps1.x targets. And since those targets support so few instructions anyway, its not too difficult to write the shader directly in ASM anyway.
Quote:
Original post by bengaltgrs
I also added a little more than just shadow mapping to the pixel shader, it also blends some textures together for the ground mesh having the shadow cast onto it.

Also, I have never actually used ASM before, and was hoping to just use HLSL for everything.

Well, guess its time to learn then :) Writing small shaders in ASM really isn't too bad. When your shaders become more complex, then yes, it gets hard. But especially for ps1.1 shaders, where you can have at most 8 instructions, it really isn't all that hard.

The ASM code posted earlier has every single line commented. Look up each instruction in the SDK docs to see what it does and trace through it. Once you understand how it works, you should be able to modify the shader a bit to add your other operations to it.

If you're hell-bent on trying to make your HLSL shader work with ps1.x, then my suggestion to you is to simplify it as much as possible so it does the bare minimum necessary. If you make it very simple, the HLSL compiler will have a better chance of successfully compiling it to ps1.x target. Once you can do that, slowly start adding back functionality until you figure out why it wasn't compiling the whole thing in the first place.

neneboricua

Share this post


Link to post
Share on other sites
Ok, well learning to use ASM sounds like the best plan so I will look through the code and find out how to use it. I am still curious to know why the HLSL code will not compile though, it is just that one line it has a problem with. Thanks for the help and I'll start looking at ASM stuff.

-Chris

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!