コード例 #1
0
        private void UpdateCubeMapFacePassCBs()
        {
            for (int i = 0; i < 6; i++)
            {
                PassConstants cubeFacePassCB = _mainPassCB;

                Matrix view = _cubeMapCameras[i].View;
                Matrix proj = _cubeMapCameras[i].Proj;

                Matrix viewProj    = view * proj;
                Matrix invView     = Matrix.Invert(view);
                Matrix invProj     = Matrix.Invert(proj);
                Matrix invViewProj = Matrix.Invert(viewProj);

                cubeFacePassCB.View                = Matrix.Transpose(view);
                cubeFacePassCB.InvView             = Matrix.Transpose(invView);
                cubeFacePassCB.Proj                = Matrix.Transpose(proj);
                cubeFacePassCB.InvProj             = Matrix.Transpose(invProj);
                cubeFacePassCB.ViewProj            = Matrix.Transpose(viewProj);
                cubeFacePassCB.InvViewProj         = Matrix.Transpose(invViewProj);
                cubeFacePassCB.EyePosW             = _cubeMapCameras[i].Position;
                cubeFacePassCB.RenderTargetSize    = new Vector2(_dynamicCubeMap.Width, _dynamicCubeMap.Height);
                cubeFacePassCB.InvRenderTargetSize = new Vector2(1.0f / _dynamicCubeMap.Width, 1.0f / _dynamicCubeMap.Height);

                UploadBuffer <PassConstants> currPassCB = CurrFrameResource.PassCB;

                // Cube map pass cbuffers are stored in elements 1-6.
                currPassCB.CopyData(1 + i, ref cubeFacePassCB);
            }
        }
コード例 #2
0
        private void UpdateReflectedPassCB()
        {
            _reflectedPassCB = _mainPassCB;

            var    mirrorPlane = new Plane(new Vector3(0, 0, 1), 0); // XY plane.
            Matrix r           = MathHelper.Reflection(mirrorPlane);

            // Reflect the lighting.
            for (int i = 0; i < 3; i++)
            {
                Vector3 lightDir          = _mainPassCB.Lights[i].Direction;
                Vector3 reflectedLightDir = Vector3.TransformNormal(lightDir, r);
                Light   reflectedLight    = _reflectedPassCB.Lights[i];
                reflectedLight.Direction   = reflectedLightDir;
                _reflectedPassCB.Lights[i] = reflectedLight;
            }

            // Reflected pass stored in index 1.
            CurrFrameResource.PassCB.CopyData(1, ref _reflectedPassCB);
        }