Sign in to follow this  

ps 1.1 dependent texture reads using HLSL

This topic is 4860 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'm stuck translating my Pixel shader to PS 1.1 (GeForce3 target specs). The problem is I need to do a "dependant read of the specular power texture map" but I can't get it to work. I've found a good step-by-step guide at MSDN but I want to do some alterations to it, however I'm not sure what the limitations are. This is what I'm trying to do: * Read the normal from a dot3-map * Calculate the diffuse value * Calculate the specular value using a texture lookup for the pow-operation I'm using HLSL but can probably understand ASM if need be. Now, does anyone know if it is at all possible to do what I stated above? I've searched in the SDKs and on the internet and this is the closest thing I've found that should work on ps_1_1: > (http://msdn.microsoft.com/library/en-us/dndrive/html/directx04152003.asp) > > tDiffuse = tex2D( sampler0, i.Tex0 ); > tNormal = tex2D( sampler1, i.tNormal); > > t2.x = dot( tNormal*2-1, i.depRead); > t2.y = dot( tNormal*2-1, i.tH); > tSample = tex2D( sampler2, t2); This is some of the code I'm trying to get to work: > sampler Texture0; > sampler Texture1; > > float4 ps_main( > float2 Texture : TEXCOORD0, > float3 Light : TEXCOORD1, > float3 Half : TEXCOORD2 ) : COLOR0 > { > float3 Normal = tex2D( Texture0, Texture ); > > float Specular = max( 0, dot( Half*2-1, Normal*2-1 )); > > Specular = tex1D( Texture1, Specular ); This won't compile, saying: "cannot map this dependent texture read to ps_1_1". I know there are the "texm3x2pad" and "texm3x2tex" operators, but I can't get the compiler to use them. I've also tried a Tex2D-lookup like the one in the first example, but I can't get that to work either. Does anyone know what changes I need to do or why it's not possible?

Share this post


Link to post
Share on other sites
You can try throwing the max at the end of the shader. You cannot adjust texcoords in code in ps.1.1.

first you read your normal map, which is fine

Then you need to perform a 3x2 matrix multiply to get the dot product to work, as all the texdp3 instructions are 1.2. Try outputting a second matrix row in texcoord3, all zeros.

The *2-1 of the normal and halfvector is fine (because it's just the _bx2 modifier, not changing the coords in code.)

create a matrix as float3x2(halfvector*2-1, normal*2-1), and sample that.

then, after you've read the map, you can perform MAX operations. You could also try using CLAMP to ensure you don't read from bad negative texcoords that way.


in asm your result will be
tex t0
texcoord t1
texpad3x2 t2,t0_bx2
texpad3x2 t3,t0_bx2
// Now we have specular in t3. Light in t1, and normalmap in t0
// dot3 the light and normal, with clamping
dp3_sat r0, t0_bx2, t1_bx2
// Mix in specular... not sure how you want it mixed...
// Usually you zero specular if diffuse dot3 was < 0
// But I'm lazy.
add r0, r0, t3

edit: I just noticed I'm not doing _bx2 on the halfvector... if you use it this way (rather then doing texcoord) I'm pretty sure you can output from the vertex shader as -1..1.

If you want, try texpad3x2 t2_bx2, t0_bx2 instead, which is what your HLSL is trying to do.

Share this post


Link to post
Share on other sites

This topic is 4860 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.

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