Sign in to follow this  

Realtime reflections using Sphere Mapping?

This topic is 3271 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, I'm thinking about realtime reflections, and don't really want to be generating 6 textures per frame per realtime reflective object, so I was thinking, could I generate a single sphere map texture per object instead? Is this a bad idea? How would I go about trying to generate a Sphere Map? Taken from a NeHe tutorial: The "red book" defines a Sphere map as a picture of the scene on a metal ball from infinite distance away and infinite focal point. This doesn't sound promising.. but has anyone got any ideas on how I might fake it? Cheers for your help Hybrid

Share this post


Link to post
Share on other sites
Rendering with a 360 degree field of view would do it. However that is not possible with rasterization due to limitations in how that technique works. It would be possible with raytracing though but at the moment I think you are stuck with rendering six textures into a cubemap :)

Share this post


Link to post
Share on other sites
As far as I can tell, use the mirror approach (render the reflected scene again, mirrored) for highly reflective stuff such as water and... mirrors. However, this cannot be used in big numbers or for organic shapes. Luckily most other materials won't reflect that much, so using a cubeMap or Dual Paraboloid map can work.

In my engine I update 1 cubeMap every frame at the players position. I also tried Dual Paraboloid Maps, but in the end I didn't like the downsides of this approach. Anyway, reflections on nearby surfaces such as your weapon, a nearby wet wall/floor or a shiny car are 'good enough'. Of course, if you look carefull the reflections are not correct. But due the distances, low-reflectivity, normalMaps and/or complex shapes, the average user won't notice this. I think this is how most games 'fake' it so far.

If you have more specific objects that require reflections, you could use multiple cubeMaps/sphereMaps/DPM's maybe. For example, in a racing game you could give realtime reflections for all cars that are nearby the player. If they get too far away, just use the most nearby point then. You won't really notice the error since these cars are on a larger distance, and ussually racing cars tend to move fast :) In case you use cubeMaps, also consider if you need all faces. It's useless to render the road beneath the car in your reflection Map. Probably half a sphere pointing upwards to reflect the sky/bridges/flats/trees already does the job for you.

Greetings,
Rick

Share this post


Link to post
Share on other sites
Disclaimer: I have not tried this, but have thought about it over a few cups of coffee.

It may be possible to render both sides of a DPM in a single draw call by using the face-normal to format pixel shader output values to blend to 2 render targets. I thought this up while trying to figure out how I wanted to do shadow maps for point lights. I think the frustum math should work out properly, as long as you do: xyz / abs(w). If anyone gets to trying this before I do, let me know if it works ;)

Share this post


Link to post
Share on other sites
I have done a sphere mapping implementation in D3D10, and I have also done single pass cube maps as well as single pass dual paraboloid maps. The implementations were done for a book chapter (which will be available relatively soon to everyone... hopefully within the next few weeks or so...)

Here is the worst case artifacts from sphere mapping:



However, as long as you steer the singularity of the sphere map away from the viewer, then you get decent environment mapping without much additional rendering required. The sample for the book chapter will be available here on GDNet, so keep an eye out for it in the next couple of weeks!

Share this post


Link to post
Share on other sites
Hot damn! Around where I'm from, that's what we call "the elegant solution" (aka someone else figures it out for you). I can't wait to check it out, Jason.

Share this post


Link to post
Share on other sites
Hi guys, thanks for all the replies!

It sounds like i'm best waiting for these demos to be released so that I can learn a bit more about the techniques being described. The screenshot looks awesome, by the way :)

I'm a bit confused by the artifacts on the sphere in the screenshot, is that due to geometry of the sphere or the sphere mapping technique? Surely the sphere map is generated by setting up a camera from the object, facing towards the viewer, so artifacts like that would never be seen?

I'm probably overlooking something though!

Hybrid

Share this post


Link to post
Share on other sites
Quote:
Original post by Hybrid666
Hi guys, thanks for all the replies!

It sounds like i'm best waiting for these demos to be released so that I can learn a bit more about the techniques being described. The screenshot looks awesome, by the way :)
Thanks [grin] The artwork is from the DXSDK, so I can only take credit for the little sphere in the middle...

Quote:
Original post by Hybrid666
I'm a bit confused by the artifacts on the sphere in the screenshot, is that due to geometry of the sphere or the sphere mapping technique? Surely the sphere map is generated by setting up a camera from the object, facing towards the viewer, so artifacts like that would never be seen?

I'm probably overlooking something though!
That is an artifact from the sphere mapping technique itself. When you warp the scene to appear in the sphere map (which is a single texture with a circle in the middle) there is a single point on the other side of the virtual sphere that can't be represented correctly. Essentially that one single point is actually represented by the entire circumference of the sphere map, mapping many points to one area.

The end result is that there is a large gradient in texture coordinates around that point, producing the cool warp sphere you see above. You are 100% right though, you can basically hide the ugliness by keeping the singularity pointed away from the viewer. The only time (that I know of) that this won't work is if you are doing multiple reflectors where both sides of the object are going to be visible no matter what.

Share this post


Link to post
Share on other sites
Quote:
Original post by patw
Disclaimer: I have not tried this, but have thought about it over a few cups of coffee.

It may be possible to render both sides of a DPM in a single draw call by using the face-normal to format pixel shader output values to blend to 2 render targets. I thought this up while trying to figure out how I wanted to do shadow maps for point lights. I think the frustum math should work out properly, as long as you do: xyz / abs(w). If anyone gets to trying this before I do, let me know if it works ;)

Just wanted to follow up on this. I attempted to do an atlased DPM using a single draw in DX9 and it (unfortunately) exhibits the artifacts I was afraid would show up.

I did have very good luck with using an atlased map. What I am doing is creating a shadow map which is of size (width *2, height). This saves target changes, and doesn't seem to produce artifacts. Nothing magic, but if anyone is interested I can post the shader code.

I can live with 2 draw calls under DX9. Looking forward to the article, Jason, and thanks for your article, it was a big help to me.

Share this post


Link to post
Share on other sites
I'm glad that you got some use out of it. The remaining chapters should be released sometime before Christmas (hopefully). I really want to get the whole project released, and I think we can keep on track for that time frame...

My implementations are all in DX10, which can use the geometry shader to pick which render target to send geometry to. That's how I'm doing it all in one pass, but it is still a very efficient method.

Share this post


Link to post
Share on other sites
I just wanted to bump this topic - the book is now available! The link is in my signature, and I look forward to hearing your feedback!

Unfortunately, it looks like the wiki server has gone down :( So it may take a little while for the GDNet guys to figure out what is going on. Stay tuned...

Share this post


Link to post
Share on other sites
We hope you enjoy it and get a lot of use out of it! If you have any questions please feel free to PM or post a topic - all of the authors are regular visitors to the forums.

Share this post


Link to post
Share on other sites

This topic is 3271 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.

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