   Shadow Mapping using ps 1.1
  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]
  Sorry about not going on topic here, but would you be able to post the tutorial?I've been looking for something like that for a while.   ;  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   ;  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 comparisonsps.1.1def c0, 0.5, 0.5, 0.5, 0.5  // bias valuedef c1, 1.0, 1.0, 1.0, 1.0  // turn on the lighting value for a given pixeldef c2, 0.0, 0.0, 0.0, 0.0  // turn off the lighting value for a given pixeltex t0  // Texture that contains the light distance values// Subtract the light distance from the ideal distance.// Result is either zero or some positive valuesub r1, v1, t0// Add 0.5 and write result to r0.a because the cnd instruction only works on r0.aadd 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 valuecnd 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, v0Hope this helps,neneboricua   ;  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 mapsvector 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 termfloat fShadowTerm = 0.5f;fShadowTerm = tex2D( ShadowSampler, IN.vProjCoord ) < (IN.vProjCoord.z - 0.001f) ? 0.5f : 1.0f;// Compute the final colorreturn (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   ;Quote:Original post by bengaltgrsI 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 bengaltgrsI 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   ;  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   