Ejemplo n.º 1
0
        static void RenderSpotLights(List<MyLightRenderElement> spotLightElements, MyEffectPointLight effectPointLight)
        {
            if (spotLightElements.Count == 0 || !MyRender.Settings.EnableSpotLights)
            {
                return;
            }

            GetRenderProfiler().StartProfilingBlock("RenderSpotLightList");
            foreach (var spotElement in spotLightElements)
            {
                RenderSpotLight(spotElement, effectPointLight);
            }
            GetRenderProfiler().EndProfilingBlock();
        }
Ejemplo n.º 2
0
        static void RenderSpotLight(MyLightRenderElement lightElement, MyEffectPointLight effectPointLight)
        {
            MyRenderLight light = lightElement.Light;

            //Matrix lightViewProjectionShadow = Matrix.Identity;

            // Always cull clockwise (render inner parts of object), depth test is done in PS using light radius and cone angle
            RasterizerState.CullClockwise.Apply();
            DepthStencilState.None.Apply();

            //m_device.BlendState = BlendState.Additive;
            //Need to use max because of overshinning places where multiple lights shine
            MyStateObjects.Light_Combination_BlendState.Apply();

            if (lightElement.RenderShadows && lightElement.ShadowMap != null)
            {
                m_spotShadowRenderer.SetupSpotShadowBaseEffect(effectPointLight, lightElement.ShadowLightViewProjectionAtZero, lightElement.ShadowMap);
            }
            effectPointLight.SetNearSlopeBiasDistance(0);

            effectPointLight.SetLightPosition((Vector3)(light.Position - MyRenderCamera.Position));
            effectPointLight.SetLightIntensity(light.Intensity);
            effectPointLight.SetSpecularLightColor(light.SpecularColor);
            effectPointLight.SetFalloff(light.Falloff);

            effectPointLight.SetLightViewProjection((Matrix)(lightElement.ViewAtZero * lightElement.Projection));
            effectPointLight.SetReflectorDirection(light.ReflectorDirection);
            effectPointLight.SetReflectorConeMaxAngleCos(1 - light.ReflectorConeMaxAngleCos);
            effectPointLight.SetReflectorColor(light.ReflectorColor);
            effectPointLight.SetReflectorRange(light.ReflectorRange);
            effectPointLight.SetReflectorIntensity(light.ReflectorIntensity);
            effectPointLight.SetReflectorTexture(light.ReflectorTexture);
            effectPointLight.SetReflectorFalloff(light.ReflectorFalloff);

            if (lightElement.RenderShadows)
                effectPointLight.SetTechnique(effectPointLight.SpotShadowTechnique);
            else
                effectPointLight.SetTechnique(effectPointLight.SpotTechnique);

            MyDebugDraw.DrawConeForLight(effectPointLight, lightElement.World);
        }
Ejemplo n.º 3
0
        public static void DrawConeForLight(MyEffectPointLight effect, Vector3 position, Vector3 direction, Vector3 upVector, float coneLength, float coneCosAngle)
        {
            // Cone is oriented backwards
            float scaleZ = -coneLength;

            // Calculate cone side (hypotenuse of triangle)
            float side = coneLength / coneCosAngle;

            // Calculate cone bottom scale (Pythagoras theorem)
            float scaleXY = (float)System.Math.Sqrt(side * side - coneLength * coneLength);

            // Calculate world matrix as scale * light world matrix
            MatrixD world = MatrixD.CreateScale(scaleXY, scaleXY, scaleZ) * Matrix.CreateWorld(position - MyRenderCamera.Position, direction, upVector);
            DrawConeForLight(effect, world);
        }
Ejemplo n.º 4
0
        public static void DrawConeForLight(MyEffectPointLight effect, MatrixD worldMatrix)
        {
            MatrixD worldViewProjMatrix;
            MatrixD.Multiply(ref worldMatrix, ref MyRenderCamera.ViewProjectionMatrixAtZero, out worldViewProjMatrix);

            Matrix worldViewProjMatrix2 = (Matrix)worldViewProjMatrix;
            effect.SetWorldViewProjMatrix(ref worldViewProjMatrix2);
            Matrix worldMatrix2 = (Matrix)worldMatrix;
            effect.SetWorldMatrix(ref worldMatrix2);

            effect.Begin();

            MyPerformanceCounter.PerCameraDrawWrite["Light draw calls"]++;
            ModelCone.Render();

            effect.End();
        }
Ejemplo n.º 5
0
        public static void DrawHemisphereForLight(MyEffectPointLight effect, ref Vector3D position, float radius, ref Vector3 diffuseColor, float alpha)
        {
            MatrixD scaleMatrix;
            MatrixD.CreateScale(radius, out scaleMatrix);
            MatrixD positionMatrix;
            position = position - MyRenderCamera.Position;
            MatrixD.CreateTranslation(ref position, out positionMatrix);
            MatrixD lightMatrix;
            MatrixD.Multiply(ref scaleMatrix, ref positionMatrix, out lightMatrix);

            DrawHemisphereForLight(effect, ref lightMatrix, ref diffuseColor, alpha);
        }
Ejemplo n.º 6
0
        public static void DrawHemisphereForLight(MyEffectPointLight effect, ref MatrixD worldMatrix, ref Vector3 diffuseColor, float alpha)
        {
            MatrixD worldViewProjMatrix;
            MatrixD.Multiply(ref worldMatrix, ref MyRenderCamera.ViewProjectionMatrixAtZero, out worldViewProjMatrix);

            Matrix worldViewProjMatrix2 = (Matrix)worldViewProjMatrix;
            Matrix worldMatrix2 = (Matrix)worldMatrix;
            effect.SetWorldViewProjMatrix(ref worldViewProjMatrix2);
            effect.SetWorldMatrix(ref worldMatrix2);

            effect.Begin();

            MyPerformanceCounter.PerCameraDrawWrite["Light draw calls"]++;
            ModelHemisphereLowRes.Render();

            effect.End();
        }