Jump to content
• ### What is your GameDev Story?

• Advertisement

# How to get a ray in view space in volume rendering

This topic is 677 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,

In PS, I want to get a ray in view space to do volume rendering.

Let's say I have the camera position in the view space. I want to get the other end of the ray corresponding with the screen position. So I can define the ray.

My question is how to convert the screen position to view space in PS?

Thanks a lot.

YL

#### Share this post

##### Share on other sites
Advertisement
The camera position in view space ? It is the origin : float3(0,0,0) :)

The viewspace ray can be determine from the screen coordinate normalize to -1..1, add a fake z that represent something like the far plane (value depends on the kind of projection you use), w set to 1 and multiply by the inverse projection. Divide the result by w, normalize the float3, and you have your viewdirection

#### Share this post

##### Share on other sites

Thanks.

Can I use any value between near plane and far plane as fake z?

#### Share this post

##### Share on other sites

I think I can use any value between [0, 1] as fake z, right?

#### Share this post

##### Share on other sites

You gonna normalize the vector so yes, any z value should be good.

Thanks!

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 15
• 9
• 11
• 9
• 9
• Advertisement
• ### Forum Statistics

• Total Topics
634140
• Total Posts
3015761
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!