0

Using directx 11, I'm working on a graphics effect system that uses a geometry shader to build quads in world space. These quads then use a fragment shader in which the main texture is the rendered scene texture. Effectively producing post process effects on qorld space quads. The simplest of which is a tint effect.

The vertex shader only passes the data through to the geometry shader.

The geometry shader calculates extra vertices based on a normal. Using cross product, I find the x and z axis and append the tri-stream with 4 new verts in each diagonal direction from the original position (generating a quad from the given position and size).

The pixel shader (tint effect) simply multiplies the scene texture colour with the colour variable set.

The quad generates and displays correctly on screen. However;

The problem that I am facing is the mapping of the uv coordinates fails to align with the image on the back buffer. That is, when using the tint shader with half alpha as the given colour you can see the image displayed on the quad does not overlay the image on the back buffer perfectly, unless the quad facing towards the camera. The closer the quad normal matches the cameras y axis, the more the image is skewed.

I am currently using the formula below to calculate the uv coordinates:

    float2 uv = vert0.position.xy / vert0.position.w;
    vert0.uv.x =  uv.x * 0.5f + 0.5f;
    vert0.uv.y = -uv.y * 0.5f + 0.5f;

I have also used the formula below, which resulted (IMO) in the uv's not taking perspective into concideration.

    float2 uv = vert0.position.xy / SourceTextureResolution;
    vert0.uv.x =  uv.x * ASPECT_RATIO + 0.5f;
    vert0.uv.y = -uv.y + 0.5f;

Question: How can I obtain screen space uv coordinates based on a vertex position generated in the geometry shader?

If you would like me to elaborate on any points please ask and i will try my best :)

Thanks in advance.

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
Jester
  • 51
  • 1
  • 5
  • It's not clear where you're calculating the UVs, is it in the geometry or the pixel shader ? What I think you want is to texture using clip space coordinates, declaring a "float4 Position :SV_POSITION" in the pixel shader and then generating the UVs off that. – RelativeGames May 27 '14 at 19:55
  • Apologies, the calculation is performed in the geometry shader. I will try moving it to the pixel shader like you suggest and report back. – Jester May 29 '14 at 11:47

0 Answers0