Setting texture coords using oPos

Started by
3 comments, last by programmer_tom 19 years, 2 months ago
Sorta unusual thing we're doing here... In rendering voxels, to avoid seeing the line where the z intersect is between our alpha blended quad and the terrain, we are using an alpha mask to fade line between the ground. We rotate the texture coords into position, and blend in the mask. Works/looks great. Too slow to lock the vertex buffer inside every time to adjust UV coords ( well actually just V, it's essentially an 1D texture, U can be set to 0.5f pr whatever ). So, knowing where my V of all 4 vertices is, and the pixel position of all 4 vertices, and because this is a billboard, there is a linear relationship between V and height...I figure I can set a constant each time through the game loop, and have the shader dynamically set the V coords. mul r0, v0.x, c0 ; Transpose and transform to clip space using mad r0, v0.y, c1, r0 ; concatenated matWorld * matView * matProj (c0-c3). mad r0, v0.z, c2, r0 add r3, c3, r0 ; storing in r3 before moving to oPos. mov oPos, r3 ; The c program has figured out where the lowest V of UV is ( c20.y ), ; and where that point is in screen coords ( c20.x ), and the significance ; of a pixel in texture range V. They are sent in a constant register c20. ; I want to use the output screen position to set the texture coords. ; This is too slow if i have to lock the vertex buffer and set them ; every frame. ; oPos is in RHW right? so valid ranges are 0 to window width, 0 to window ; height right? Or is it 0 to 1? sub r3.y, r3.y, c20.x ; subtract least screen coord from this screen coord. mul r3.y, r3.y, c20.z ; multiply difference by significance. add oT1.y, r3.y, c20.y ; add starting V. mov oT1.x, v8 ; U is always 0.5f.
Advertisement
Quote:Original post by programmer_tom
...
; oPos is in RHW right? so valid ranges are 0 to window width, 0 to window
; height right? Or is it 0 to 1?


Actually, for a vertex to be on screen, the output must be in the range:

oPos.x / oPos.w : -1 (left side of the screen) to 1 (right side of the screen)
oPos.y / oPos.w : -1 (bottom of the screen) to 1 (top of the screen)
oPos.z / oPos.w : 0 (at the near plane) to 1 (at the far plane)
so how can i form a relationship between pixel coods from the c program, and oPos output?

i tried this:

rcp r3.w, r3.w
mul r3.y, r3.y, r3.w ; y divide by w

in the shader to give me -1 to 1 (if it's on screen), and in the c program, i just use the simple :

( fPixelY / ( height/2 ) ) / ( height /2 )

for screen coords -1 to 1.

i just need a way to force my c program pixelY to match oPos.y, then i can use the linear relationship between height onscreen and UV coords, so the shader can move around the UV.
Not sure this is exactly what you are looking for, but the relationship between a pixel's y coordinate and oPos is:

pixelY = ( 1.0f - ( oPos.y / oPos.w ) ) * ( screenHeight / 2.0f );
thanks a lot man. this has been a tough problem to solve. slim pickings on help on this subject. hope to get it down this morning :)


This topic is closed to new replies.

Advertisement