Sign in to follow this  

Problem with D3DTTFF_PROJECTED

This topic is 4809 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

Hi, I'm having problem with transforming texture coords. I'm using fixed function T&L and pixel shader. By fixed function T&L I want to transform texture coords from camera space to post-projection light space. I'm doing this by code like this: // We will take coords from camera space and transform them to light texture space Device->SetTransform( D3DTS_TEXTURE0, &TexMat); Device->SetTexture(0, DepthTex); Device->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION); /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THIS PRODUCE SAME OUTPUT TO PIXEL SHADER AS LINE BELOW WHY??????? SEEMS, THAT D3DTTFF_PROJECTED HAS NO EFFECT. WHY???? !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ Device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4 | D3DTTFF_PROJECTED); // THE LINE BELOW // Device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3); And then I need to get texture coords from 3D homogenous (x,y,z,w) to pure 3D tj. I need to get (x/w, y/w, z/w) for pixel shader processing. This I think should be done by setting D3DTTFF_PROJECTED flag. But division simply does not occur. And I don't know why? I have testing application of shadow mapping, where I need to this: http://www.celba.cz/ShadowMapping.rar So you can see yourself. In testing app I'm using ref device and I'm sure to have w != 1. (typically w = 15) Can someone help me to solve this problem? Thanks, Filousov

Share this post


Link to post
Share on other sites
I believe for most cards out there today the projective divide occurs per-pixel in the fixed-function rasterizer. Since you're using a pixel shander you'll probably have to do this yourself. Look at the docs for D3DPTEXTURECAPS_PROJECTED.

Share this post


Link to post
Share on other sites
This is from the DirectX SDK documentation:

Quote:


D3DTTFF_PROJECTED
This flag is honored by the fixed function pixel pipeline, as well as the programmable pixel pipeline in versions ps_1_1 to ps_1_3. When texture projection is enabled for a texture stage, all four floating point values must be written to the corresponding texture register. Each texture coordinate is divided by the last element before being passed to the rasterizer. For example, if this flag is specified with the D3DTTFF_COUNT3 flag, the first and second texture coordinates are divided by the third coordinate before being passed to the rasterizer.



Maybe you are using a pixel shader version > than 1_3?

-Mezz

Share this post


Link to post
Share on other sites
Yes, you are right. I'm using ps 2.0 and that is the reason, why it doesn't work.

But how should I do the division in pixel shader, when I'm not able to pass all four coords? D3DTTFF_COUNT4 alone is also unsupported.

There must be some way, how to do it.

There is no problem with vertex shader, but this is something, I'm trying to avoid.

Anyhow my pixel shader is:
// Light map pixel shader

// input and output structures
struct INPUT
{
vector Diffuse: COLOR0;
vector ZDepth: TEXCOORD0;
};

struct OUTPUT
{
vector Color: COLOR;
};

// globals
sampler ShadowMap : register(s0);

OUTPUT Main(INPUT Input)
{
// MapZ value
vector MapZ;
float Amount;

// Init output
OUTPUT Output = (OUTPUT) 0;

// Get shadow map z depth
MapZ = tex2D(ShadowMap, Input.ZDepth.xy);

// Compare depths
Amount = (MapZ.r > Input.ZDepth.z);

// return black or light color
Output.Color = Input.Diffuse * Amount;

return Output;
}

I just load z-depth from texture and compare it with z texture coord.

Can anyone help me, how to get right (divided by w) texture coords in my pixel shader?

Thanks, Filousov


Share this post


Link to post
Share on other sites
I don't think there is any way to do it without having the texture coordinates passed into the pixel shader, once you've got them you just use tex2Dproj() to do the lookup and it automatically divides by the last component for you, but you still need the 4D coordinates to do this.

-Mezz

Share this post


Link to post
Share on other sites

This topic is 4809 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