| Poster | : reyjexter | | Posts | : 21 | | Country | : philippines | | City | : legazpi city |
| | | | Posted by reyjexter on 22/02/2007 at 12:48:08
| | hi riemer!
i'm i bit lost on the tutorial that cast shadows specifically on the hlsl part:
SScenePixelToFrame ShadowedScenePixelShader(SSceneVertexToPixel vs)
{
SScenePixelToFrame output = (SScenePixelToFrame) 0;
float2 projectedTextureCoords;
projectedTextureCoords.x = vs.shadowMapSamplingPos.x / vs.shadowMapSamplingPos.w / 2.0f + 0.5f;
projectedTextureCoords.y = -vs.shadowMapSamplingPos.y / vs.shadowMapSamplingPos.w / 2.0f + 0.5f;
output.color = tex2D(shadowMapSampler, projectedTextureCoords);
return output;
}
i cant understand why you needed to negate the projectedTextureCoords.y
thanks
rey | |
|
|
| |
| |
| Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 23/02/2007 at 02:45:01
| | | For a reason I forgot, the result of multiplying the vertices with the view and projection matrix, the image you get is flipped upside down. To correct for this, we need to negate the Y coord | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 17/08/2009 at 16:51:32
| | | Could someone please elborate on this? | |
|
|
| |
| |
| Poster | : radulph | | Posts | : 225 | | Country | : germany | | City | : hamburg |
| | | | Posted by radulph on 18/08/2009 at 04:44:04
| | XNA uses a right hand coordinate system. Thus, the x axis points to the right, the y axis to the top and the z axis towards the viewer. Further the origin of the 3d space is at the center of the screen.
The last thing to note is that (given an identity matrix as the projection matrix) both x and y axis range from -1 to 1 (from left side of the screen to the right side of the screen, top to bottom as well)
On the other hand, texture coordinates range from (0,0) to (1,1) (top left to bottom right corner where u = horizontal pos. and v = vertical pos.).
What happens in the code snippet above is to transform view space coordinates to texture coordinates. the division by 2 and addition of 0.5 shifts the origin to the top left corner and scales the axis. The -sign inverts the y axis since it originally points up, whereas the v coordinate of a texture points downwards.
| |
|
|