Sign in to follow this  
josiah7

Please help to convert instruction from ps 2.0 to ps1.4

Recommended Posts

josiah7    122
Hello, I have a hlsl shader that works fine with ps2.0 compile, however I want a fallback for cards that only support ps1.4. The problem is a line that divides texture coordinates. "In.tex0.xy / temp". I understand that ps1.4 dosent support division and ps2.0 does? Is there any workaround? Thanks much for any help!

Share this post


Link to post
Share on other sites
jamesw    400
Can you pull 1/temp out to the CPU or vertex shader? If not then you can use tex2Dproj, which divides by the last component before lookup.

Share this post


Link to post
Share on other sites
josiah7    122
Thanks James, I appreciate your help, it may not be immediately apparent that I
am clueless!

I should have included the type of the variable "temp" is. The line can be
better written as "float2 temp2 = In.tex0.xy/In.tex.z". I looked at the
tex2Dproj function, but couldnt get it to work with these variable types.
If I could just convert this line for ps1.4 I would be done.

Perhaps I could include this line as Assembly?
Thanks again.

Share this post


Link to post
Share on other sites
Cygon    1219
I'm not an expert, but I remember something about these .xy, .xz and other extractors might have been introduced with shader model 2.0. Maybe you can just replace that line with the following:

float2 temp2;
temp2.x = In.tex0.x / In.tex.z;
temp2.y = In.tex0.y / In.tex.z;

-Markus-

Share this post


Link to post
Share on other sites
josiah7    122
Thank you Markus, but I get a "cannot map expression to pixel shader instruction set" error with that. It is the "/" (division) that is giving the problem. if I replace "/" with "*", then it compiles under ps1.4. But I need to divide and not multiply. It seems ps1.4 dosent support division :(

Share this post


Link to post
Share on other sites
TheAdmiral    1122
Unless you need to divide for the purposes of projective texturing (in which case you should look at tex2Dproj) you're out of luck - the ps_1_4 instruction set doesn't support floating inversion (or, equivalently, division by variables). On the off-chance that temp is a constant, if you mark it const, the HLSL assembler will hard-code it in as multiplication by the reciprocal, and everything will be tickedy-boo.

Is it possible for you to perform the division in the vertex shader? This would result in the values being interpolated in reciprocal-space, which may not work out, but if the modulus of continuity of the parameter over adjacent vertices is small, the error may not be noticeable.

Admiral

Share this post


Link to post
Share on other sites
cyber_wiz_2007    124
how about:


/*
float dx = 1 / x_value;
float dy = 1 / y_value;
*/


float2 texcoords;
texcoords.x = IN.texcoords.x * dx;
texcoords.y = IN.texcoords.y * dy;

col = tex2D( texSampler, texcoords );




you just need to keep the instructions to a minimum, and the number of texture reads should be less than 4.

Share this post


Link to post
Share on other sites
Mastaba    761
Quote:
Original post by josiah7
Thanks James, I appreciate your help, it may not be immediately apparent that I
am clueless!

I should have included the type of the variable "temp" is. The line can be
better written as "float2 temp2 = In.tex0.xy/In.tex.z". I looked at the
tex2Dproj function, but couldnt get it to work with these variable types.
If I could just convert this line for ps1.4 I would be done.

Perhaps I could include this line as Assembly?
Thanks again.


I would suggest you change your vertex shader so that tex0 is in homogeneous coordinates and then use the tex2Dproj instruction in your pixel shader.

[Edited by - Mastaba on May 13, 2007 2:25:01 PM]

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