Sign in to follow this  
Mythar

Projected Texture in HLSL

Recommended Posts

Hi all, im currently working on improving my sky to include skybodys like a moon etc. The easy way to add the moon and stuff, would be to simply billboard them. I would like to avoid that (to cut down on the no. of render passes) and render the "base/background" sky by, letting the shader do the work. In the first pass of the dome, I would like to send the "night texture" as a cube texture, the moon texture (alpha mapped) and a texture for the sky color (with alpha for how mush of the night sky to show). The sun is done like this : VS_OUTPUT o; o.Pos = mul(float4(i.Pos.xyz,1), mViewProj); o.sunlight = sun_strength*pow(saturate(dot(normalize(i.Pos), sun_vec)),sun_shininess)*float3(1.2, 0.4, 0.1); ( sun_vec = D3DXVECTOR4(cos(Fsun_Theta)*sin(Fsun_Alpha), sin(Fsun_Theta), cos(Fsun_Theta)*cos(Fsun_Alpha),0); ) Doing the cube texture, sun and sky color, is no problem. What I need to learn, is how to project the moon texture onto the dome ? I would like to be able to send a "moon_vec" to the shader, to control the position of the moon. (as it done with the sun) ps. I need to do this in shader vs_1_1 and ps_1_4 I anyone could help me with the projected "moon", I would be very happy :)

Share this post


Link to post
Share on other sites
you can generate a projeciton matrix from your moon vector using the cross product with the up vector to get a 'right' vector, then generate a proper 'up' vector using the cross product of the up and the moon vector.
Then once you have this matrix, you need to multiply this with a projection matrix as well as a texture bias matrix which if i recall correctly should roughly look like:
[0.5 0 0 0]
[0 0.5 0 0]
[0 0 1 0]
[0.5 0.5 0.5 1]

this can all be done outside of the shader and just uploaded as a single matrix: 'moon projector matrix' or what ever you want to call it.

so in your vertex shader, apply the object space vertices through this matrix, and you have your texture coords for your moon.

erm, hope that helps

Share this post


Link to post
Share on other sites
So it should look something like this :

( m = the present viewmatrix, I use 0-3, 0-3 as the matrix array)

up_vector = Normalize(m._01, m._11, m._21)

"you can generate a projeciton matrix from your moon vector using the cross product with the up vector to get a 'right' vector"

- not quite sure what you mean.

right_vector = cross(moon_vec, up_vector) ?

"then generate a proper 'up' vector using the cross product of the up and the moon vector"

proper_up = cross(up_vector, moon_vec) ?

How do you contsruct a matrix from this ?

Share this post


Link to post
Share on other sites

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