Opengl - mirror shader capability?

Until today, when I wanted to create reflections (mirror) in opengl

, I mapped the view to a texture and mapped that texture onto the mirror surface.

What I want to know is if there are other methods to create a mirror in opengl?

And 2. can it do it alone in shaders (like a geometry shader)?

+3


source to share


2 answers


There is no one-size-fits-all way to do this in any 3D API that I know of. Depending on your case, there are several possible methods with different cons.

  • Flat reflections: What you are doing already. Note that your mirror needs to be flat and you need to anchor something closer than the mirror that is not displayed in the texture.
  • Nice old cubemaps : attach a cube file to each mirror and then try it in the direction of the reflection. This works for any surface, but you will need to render the cubes (this can only be done once if you don't need moving objects). I don't think you can do this without shaders, but only a mirror is needed. Its very common technique, which is easy to implement, can be dynamic and quite cheap, while being easily integrated into an existing engine.
  • Spacebar screen: . He suggested danny-ruijters . View as SSAO : For each pixel, drag the depth buffer along the reflection vector until you click something. This has the advantage of being applicable anywhere (on arbitrary complex surfaces), however, it can only reflect what appears on the screen, which can introduce many small artifacts, but it is completely dynamic and very easy to implement. Note that you will need an extra pass (or render normals to a buffer) to access your final scene color when calculating reflections. You absolutely need shaders for this, but it dispatches the process so that it doesn't interfere with the rendering of the scene if that's what you're afraid of. Some modern game engines use this to add fine detail to reflective surfaces without stress compute / store cubes.


They are probably many other ways to render mirrors, but this is the main tree (at least for what I know), ways of reflection.

+3


source


Trace ray. You can write a ray tracer in a fragment shader (each fragment follows a ray). Ray tracer can do an excellent job of reflecting (mirroring) on ​​all surfaces.



You can find an OpenGL example here and a WebGL example including mirroring here .

+4


source







All Articles