public void RenderWater(BaseCamera camera, ref Matrix4 projectionMatrix, float nearClipPlane, float farClipPlane
                                , DirectionalLight sun = null, List <PointLight> lights = null)
        {
            PostConstructor();
            /*Water distortion cycle*/

            m_shader.startProgram();
            m_fbo.ReflectionTexture.BindTexture(TextureUnit.Texture0);
            m_fbo.RefractionTexture.BindTexture(TextureUnit.Texture1);
            m_waterDistortionMap.BindTexture(TextureUnit.Texture2);
            m_waterNormalMap.BindTexture(TextureUnit.Texture3);
            m_fbo.DepthTexture.BindTexture(TextureUnit.Texture4);
            m_shader.setTransformationMatrices(ref m_modelMatrix, camera.GetViewMatrix(), ref projectionMatrix);
            m_shader.setReflectionSampler(0);
            m_shader.setRefractionSampler(1);
            m_shader.setDuDvSampler(2);
            m_shader.setNormalMapSampler(3);
            m_shader.setDepthSampler(4);
            m_shader.setCameraPosition(camera.GetEyeVector());
            m_shader.setDistortionProperties(m_moveFactor, m_waveStrength);
            m_shader.setDirectionalLight(sun);
            m_shader.setPointLight(lights);
            m_shader.setClippingPlanes(ref nearClipPlane, ref farClipPlane);
            m_shader.setMist(m_mist);
            m_shader.setTransparancyDepth(TransparencyDepth);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            m_buffer.RenderVAO(PrimitiveType.Triangles);
            GL.Disable(EnableCap.Blend);
            m_shader.stopProgram();
        }
Exemple #2
0
        private void GetEdgePoints(BaseCamera viewerCamera, ConvexVolume volume, out Vector3 LBN, out Vector3 RTF)
        {
            Vector3 ViewerPosition = viewerCamera.GetEyeVector();

            // Find left and right edges
            Vector3 IntersectionPointC = GetLeftRightIntersectionPoint(ViewerPosition, volume.FarPlane, volume.LeftPlane);
            Vector3 IntersectionPointB = GetLeftRightIntersectionPoint(ViewerPosition, volume.FarPlane, volume.RightPlane);
            // Find top and bottom edges
            Vector3 IntersectionPointBottom = GetTopBottomIntersectionPoint(ViewerPosition, volume.FarPlane, volume.BottomPlane);
            Vector3 IntersectionPointTop    = GetTopBottomIntersectionPoint(ViewerPosition, volume.FarPlane, volume.TopPlane);

            float left, right, top, bottom, near, far;
            // left
            Dictionary <float, Vector3> projectedValues = new Dictionary <float, Vector3>();

            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, -RightVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, -RightVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -RightVector), ViewerPosition);
            left = projectedValues[projectedValues.Keys.Max()].X;

            // right
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, RightVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, RightVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, RightVector), ViewerPosition);
            right = projectedValues[projectedValues.Keys.Max()].X;

            // top
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointTop, UpVector), IntersectionPointTop);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointBottom, UpVector), IntersectionPointBottom);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, UpVector), ViewerPosition);
            top = projectedValues[projectedValues.Keys.Max()].Y;

            // bottom
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointTop, -UpVector), IntersectionPointTop);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointBottom, -UpVector), IntersectionPointBottom);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -UpVector), ViewerPosition);
            bottom = projectedValues[projectedValues.Keys.Max()].Y;

            // far
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, ForwardVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, ForwardVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, ForwardVector), ViewerPosition);
            far = projectedValues[projectedValues.Keys.Max()].Z;

            // near
            projectedValues.Clear();
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointB, -ForwardVector), IntersectionPointB);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(IntersectionPointC, -ForwardVector), IntersectionPointC);
            projectedValues.Add(GeometryMath.ProjectVectorOnNormalizedVector(ViewerPosition, -ForwardVector), ViewerPosition);
            near = projectedValues[projectedValues.Keys.Max()].Z;

            LBN = new Vector3(left, bottom, near);
            RTF = new Vector3(right, top, far);
        }
Exemple #3
0
        private Vector3 GetTargetOriginPosition()
        {
            ThirdPersonCamera thirdPersonCamera = m_viewerCamera as ThirdPersonCamera;

            if (thirdPersonCamera != null)
            {
                return((thirdPersonCamera.GetThirdPersonTarget() as Component).ComponentTranslation);
            }
            else
            {
                return(m_viewerCamera.GetEyeVector());
            }
        }
Exemple #4
0
        /*________*/
        /*|   A  |*/
        /*|  /\  |*/
        /*| /  \ |*/
        /*|C----B|*/
        /*|______|*/


        // There is no use for current algorithm because orthogonal projection should be cubic
        public void Update()
        {
            float ShadowFarPlane  = 300.0f;
            float ShadowNearPlane = 30.0f;
            float FoV             = EngineStatics.FoV;
            float halfFoV         = FoV * 0.5f;
            float AspectRatio     = EngineStatics.SCREEN_ASPECT_RATIO;

            Vector3 camWorldPosition = m_camera.GetEyeVector();
            Vector3 camForward       = m_camera.GetEyeSpaceForwardVector();
            Vector3 camRight         = m_camera.GetEyeSpaceRightVector();

            // Omit y component
            camForward = new Vector3(camForward.X, 0, camForward.Z).Normalized();
            camRight   = new Vector3(camRight.X, 0, camRight.Z).Normalized();

            Vector3 camFarPlaneWorldPosition = camWorldPosition + camForward * ShadowFarPlane;

            Vector3 camEdgeFarPlaneWorldPosition1 = camFarPlaneWorldPosition + camRight * ShadowFarPlane;
            Vector3 camEdgeFarPlaneWorldPosition2 = camFarPlaneWorldPosition - camRight * ShadowFarPlane;
            Vector3 camEdgeNearPlaneWorldPosition = camWorldPosition - camForward * ShadowNearPlane;

            //Matrix3 rotationPositive = Matrix3.CreateRotationY(MathHelper.DegreesToRadians(halfFoV));
            //Matrix3 rotationNegative = Matrix3.CreateRotationY(MathHelper.DegreesToRadians(-halfFoV));

            //Vector3 camEdgePlaneDirection1 = (VectorMath.VectorMathOperations.TransformVec3(ref camForward, ref rotationPositive)).Normalized();
            //Vector3 camEdgePlaneDirection2 = (VectorMath.VectorMathOperations.TransformVec3(ref camForward, ref rotationNegative)).Normalized();



            //float edge1ProjValue = Vector3.Dot(camEdgePlaneDirection1, camFarPlaneWorldPosition);
            //float edge2ProjValue = Vector3.Dot(camEdgePlaneDirection2, camFarPlaneWorldPosition);

            //Vector3 edgePosition1 = camWorldPosition + camEdgePlaneDirection1 * edge1ProjValue;
            //Vector3 edgePosition2 = camWorldPosition + camEdgePlaneDirection2 * edge2ProjValue;
            //Vector3 edgePosition3 = camWorldPosition - camForward * ShadowNearPlane;

            // TODO -> Find maxX, minX, maxZ, minZ

            float maxX = Math.Max(Math.Max(camEdgeFarPlaneWorldPosition1.X, camEdgeFarPlaneWorldPosition2.X), camEdgeNearPlaneWorldPosition.X);
            float maxZ = Math.Max(Math.Max(camEdgeFarPlaneWorldPosition1.Z, camEdgeFarPlaneWorldPosition2.Z), camEdgeNearPlaneWorldPosition.Z);

            float minX = Math.Min(Math.Min(camEdgeFarPlaneWorldPosition1.X, camEdgeFarPlaneWorldPosition2.X), camEdgeNearPlaneWorldPosition.X);
            float minZ = Math.Min(Math.Min(camEdgeFarPlaneWorldPosition1.Z, camEdgeFarPlaneWorldPosition2.Z), camEdgeNearPlaneWorldPosition.Z);

            Max = new Vector3(maxX, 0, maxZ);
            Min = new Vector3(minX, 0, minZ);
        }
Exemple #5
0
        public void render(BaseCamera camera, ref Matrix4 projectionMatrix)
        {
            postConstructor();

            Matrix4 modelMatrix = Matrix4.Identity;

            GetShader().startProgram();
            m_texture.BindTexture(TextureUnit.Texture0);
            m_envMap.BindTexture(TextureUnit.Texture1);
            GetShader().setUniformValues(ref modelMatrix, camera.GetViewMatrix(), ref projectionMatrix, camera.GetEyeVector(), 0, 1);
            m_skin.Buffer.RenderVAO(PrimitiveType.Triangles);
            GetShader().stopProgram();
        }