0
\$\begingroup\$

I'm actually trying to do the reflection map for my water component, but even following the riemer's tutorial about reflection map the formulas provided doens't work. http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Reflection_map.php

I've read somewhere on the Internet that riemer uses Z-axis as UpVector, and I'm using the Y-axis instead.

So my system for now is somethink like this:

private void DrawReflectionMap()
{
        this.GraphicsDevice.SetRenderTarget(this.reflectionMap);
        this.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

        if (this.CameraPosition.Y > this.Options.Height)
        {
            Matrix reflectionMatrix = Matrix.Identity;

            // Camera position
            Vector3 reflectionCameraPosition = this.camera.Position;
            reflectionCameraPosition.Y = -this.camera.Position.Y + this.Options.Height * 2;

            // Camera target
            Vector3 reflectionCameraTarget = this.camera.TargetPosition;
            reflectionCameraTarget.Y = -this.camera.TargetPosition.Y + this.Options.Height * 2;

            Vector3 cameraRight = Vector3.Transform(new Vector3(1, 0, 0), this.camera.Rotation);
            Vector3 invUpVector = Vector3.Cross(new Vector3(1, 0, 0), reflectionCameraTarget - reflectionCameraPosition);

            reflectionMatrix = Matrix.CreateLookAt(reflectionCameraPosition, reflectionCameraTarget, invUpVector);

            Plane _reflectionPlane = this.CreatePlane(this.Options.Height - 0.5f, new Vector3(0, -1, 0), reflectionMatrix, true);

            if (this.Options.Draw != null)
                this.Options.Draw(reflectionMatrix, true, _reflectionPlane);
        }

        this.GraphicsDevice.SetRenderTarget(null);
}

and there is my camera: http://pastebin.com/hK9fi5DV

When I run all of this, I got this:

enter image description here

As you can see, it seems the reflection map is not in the right side and when I move my camera, the reflection map also moves thru the edges of the texture...

Do you have an idea from where this problem could come?

Thanks.

\$\endgroup\$
3
  • \$\begingroup\$ your reflection map needs to be generated after the rest of your scene is rendered (eg render the sky, the terrain, and what not first), if you position the camera on the edge of a small patch of terrain and don't render the sky you will end up with an empty map (as designed) ... the idea is that you will never be on the edge of your world in a real game scenario \$\endgroup\$ Commented Apr 8, 2016 at 13:00
  • \$\begingroup\$ I don't have any skybox for now, I was wondering if I could only render the mountains on the water for a start, and the if I add a skybox or whatever I want, the reflection will to automatically the job for me. What I actually do is I generate my refraction and reflection map before everything. Like I draw my terrain with a different ViewMatrix and then set the old one for the real terrain \$\endgroup\$ Commented Apr 9, 2016 at 4:54
  • \$\begingroup\$ from what I recall (it was a long time ago though) you basically just render what you want on your reflection map to an texture but inverted (the viewmatrix you talk about) ... in short > render scene to reflection texture > render scene > render water using reflection \$\endgroup\$ Commented Apr 9, 2016 at 10:25

0

You must log in to answer this question.