コード例 #1
0
        static void RenderSpotLight(MyLightRenderElement lightElement, MyEffectPointLight effectPointLight)
        {
            MyLight 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.ShadowLightViewProjection, lightElement.ShadowMap);
            }
            effectPointLight.SetNearSlopeBiasDistance(4);

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

            effectPointLight.SetLightViewProjection(lightElement.View * 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.DefaultSpotShadowTechnique);
            else
                effectPointLight.SetTechnique(effectPointLight.DefaultSpotTechnique);

            MySimpleObjectDraw.DrawConeForLight(effectPointLight, lightElement.World);
        }
コード例 #2
0
        static void RenderSpotLights(List<MyLightRenderElement> spotLightElements, MyEffectPointLight effectPointLight)
        {
            if (spotLightElements.Count == 0)
            {
                return;
            }

            spotLightElements.Sort(MyLightRenderElement.SpotComparer); // Sort by texture
            var lastTexture = spotLightElements[0].Light.ReflectorTexture;

            m_renderProfiler.StartProfilingBlock("RenderSpotLightList");
            foreach (var spotElement in spotLightElements)
            {
                RenderSpotLight(spotElement, effectPointLight);
                lastTexture = spotElement.Light.ReflectorTexture;
            }
            m_renderProfiler.EndProfilingBlock();
        }
コード例 #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
            Matrix world = Matrix.CreateScale(scaleXY, scaleXY, scaleZ) * Matrix.CreateWorld(position, direction, upVector);
            DrawConeForLight(effect, world);
        }
コード例 #4
0
        public static void DrawConeForLight(MyEffectPointLight effect, Matrix worldMatrix)
        {
            Matrix worldViewProjMatrix;
            Matrix.Multiply(ref worldMatrix, ref MyCamera.ViewProjectionMatrix, out worldViewProjMatrix);

            effect.SetWorldViewProjMatrix(ref worldViewProjMatrix);
            effect.SetWorldMatrix(ref worldMatrix);

            effect.Begin();

            m_modelCone.Render();

            effect.End();
        }
コード例 #5
0
        public static void DrawHemisphereForLight(MyEffectPointLight effect, ref Vector3 position, float radius, ref Vector3 diffuseColor, float alpha)
        {
            Matrix scaleMatrix;
            Matrix.CreateScale(radius, out scaleMatrix);
            Matrix positionMatrix;
            Matrix.CreateTranslation(ref position, out positionMatrix);
            Matrix lightMatrix;
            Matrix.Multiply(ref scaleMatrix, ref positionMatrix, out lightMatrix);

            DrawHemisphereForLight(effect, ref lightMatrix, ref diffuseColor, alpha);
        }
コード例 #6
0
        public static void DrawHemisphereForLight(MyEffectPointLight effect, ref Matrix worldMatrix, ref Vector3 diffuseColor, float alpha)
        {
            Matrix worldViewProjMatrix;
            Matrix.Multiply(ref worldMatrix, ref MyCamera.ViewProjectionMatrix, out worldViewProjMatrix);

            effect.SetWorldViewProjMatrix(ref worldViewProjMatrix);
            effect.SetWorldMatrix(ref worldMatrix);

            effect.Begin();

            m_modelHemisphereLowRes.Render();

            effect.End();
        }