Jump to content

  • Log In with Google      Sign In   
  • Create Account

mouse ray intersect


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 cadmonkey39   Members   -  Reputation: 114

Like
0Likes
Like

Posted 10 July 2012 - 04:57 AM

Hi,
I've got a terrain mesh(es) pre-calculated from a heightmap, and want to change it to generate the height on the fly from the heightmap in a vertex shader.

As its currently pre-calced, i can use standard mouse-ray picking to get my mouse world position, but once the shader is providing the height, how can I still get the mouse world position?

regards,
Nat.

Sponsor:

#2 Erik Rufelt   Crossbones+   -  Reputation: 3477

Like
2Likes
Like

Posted 10 July 2012 - 05:18 AM

You could read back the depth buffer value of the pixel under the cursor to get Z, and use that to unproject the point and get the world position. If you don't want to do that, you can write a function that calculates the height on the fly while doing the intersection test, in the same way as the shader, by keeping a copy of the heightmap in memory.

#3 Ashaman73   Crossbones+   -  Reputation: 7434

Like
1Likes
Like

Posted 10 July 2012 - 05:27 AM

You could read back the depth buffer value of the pixel under the cursor to get Z, and use that to unproject the point and get the world position.

Though this is a valid way of doing it (I do it myself to pick objects), it bears the danger of flushing the command queue of the GPU which could result in bad performance. First off restrict the readback only to a very small section (1 pixel) and try to move the read back as far as possible away from the render calls, i.e. just before clearing or refilling the depth buffer again in the next frame.

#4 Funkymunky   Members   -  Reputation: 641

Like
1Likes
Like

Posted 10 July 2012 - 06:37 PM

I'm assuming that you mean that it's a predefined set of vertices with the heights already applied, and that you're going to be moving to a shader that offsets the vertices instead? Well, how are you planning to offset the vertices in the shader? With a texture and a vertex-texture-fetch in the vertex shader? Or are you going to offset by means of noise functions in the vertex shader?

If it's by texture, then I'd say you could read back that value from the texture rather than from the depth buffer. If it's by noise functions, then you'd probably have to do it via a sampling of the depth buffer.

OR, if using a texture for the heightmap, you could set up a post-processing pipeline and include an "overlay" texture which represents any user interaction. This way you could adjust the size of the "brush" that offsets the terrain. You'd do an RTT that combines the current heightmap with the overlay texture (which varies depending on if the user clicked, brush selection, etc.) to render to another heightmap. Then you ping pong back and forth between the heightmaps so that you can update the values seen by the vertex shader.

#5 cadmonkey39   Members   -  Reputation: 114

Like
0Likes
Like

Posted 11 July 2012 - 05:25 AM

Thanks guys, i'll look into reading the depth buffer.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS