private void DrawBatchPerTexture(ref TextureInfo texture, SpriteInfo[] sprites, int offset, int count)
        {
            if (m_customEffect != null)
            {
                var currentTechnique = m_customEffect.Technique;

                int passCount = m_customEffect.GetTechniqueDescription(currentTechnique).Passes;
                for (int i = 0; i < passCount; i++)
                {
                    // Sets the texture on the custom effect if the parameter exist
                    if (m_customEffectTexture != null)
                    {
                        m_customEffect.SetTexture(m_customEffectTexture, texture.Texture);
                    }


                    m_customEffect.Begin();
                    // Apply the current pass
                    m_customEffect.BeginPass(i);

                    // Draw the batch of sprites
                    DrawBatchPerTextureAndPass(ref texture, sprites, offset, count);

                    m_customEffect.EndPass();
                    m_customEffect.End();
                }
            }
            else
            {
                var spriteEffect = MyRender.GetEffect(MyEffects.SpriteBatch) as Effects.MyEffectSpriteBatchShader;

                if (texture.Face.HasValue)
                {
                    spriteEffect.SetCubeTexture(texture.Texture as CubeTexture);

                    switch (texture.Face.Value)
                    {
                    case CubeMapFace.PositiveX:
                        spriteEffect.SetTechnique(Effects.MyEffectSpriteBatchShader.Technique.SpriteBatchCube0);
                        break;

                    case CubeMapFace.NegativeX:
                        spriteEffect.SetTechnique(Effects.MyEffectSpriteBatchShader.Technique.SpriteBatchCube1);
                        break;

                    case CubeMapFace.PositiveY:
                        spriteEffect.SetTechnique(Effects.MyEffectSpriteBatchShader.Technique.SpriteBatchCube2);
                        break;

                    case CubeMapFace.NegativeY:
                        spriteEffect.SetTechnique(Effects.MyEffectSpriteBatchShader.Technique.SpriteBatchCube3);
                        break;

                    case CubeMapFace.PositiveZ:
                        spriteEffect.SetTechnique(Effects.MyEffectSpriteBatchShader.Technique.SpriteBatchCube4);
                        break;

                    case CubeMapFace.NegativeZ:
                        spriteEffect.SetTechnique(Effects.MyEffectSpriteBatchShader.Technique.SpriteBatchCube5);
                        break;
                    }
                }
                else
                {
                    spriteEffect.SetTexture(texture.Texture as Texture);
                    spriteEffect.SetTechnique(Effects.MyEffectSpriteBatchShader.Technique.Sprite);
                }

                spriteEffect.Begin();

                DrawBatchPerTextureAndPass(ref texture, sprites, offset, count);

                spriteEffect.End();
            }
        }
        private void PrepareForRendering()
        {
            // Setup states (Blend, DepthStencil, Rasterizer)
            if (m_blendState != null)
            {
                m_blendState.Apply();
            }

            if (m_rasterizerState != null)
            {
                m_rasterizerState.Apply();
            }

            if (m_depthStencilState != null)
            {
                m_depthStencilState.Apply();
            }

            if (m_samplerState != null)
            {
                m_samplerState.Apply();
            }

            // Build ortho-projection matrix
            /*SharpDX.ViewportF*/ var viewport = m_graphicsDevice.Viewport;
            float xRatio = (viewport.Width > 0) ? (1f / (viewport.Width)) : 0f;
            float yRatio = (viewport.Height > 0) ? (-1f / (viewport.Height)) : 0f;
            var   matrix = new Matrix {
                M11 = xRatio * 2f, M22 = yRatio * 2f, M33 = 1f, M44 = 1f, M41 = -1f, M42 = 1f
            };

            Matrix finalMatrix;

            Matrix.Multiply(ref m_transformMatrix, ref matrix, out finalMatrix);

            // Use LinearClamp for sampler state
            //var localSamplerState = samplerState ?? GraphicsDevice.SamplerStates.LinearClamp;

            // Setup effect states and parameters: SamplerState and MatrixTransform
            // Sets the sampler state
            if (m_customEffect != null)
            {
                if (m_customEffect.Technique == null)
                {
                    throw new InvalidOperationException("CurrentTechnique is not set on custom effect");
                }

                //if (customEffectSampler != null)
                //  customEffectSampler.SetResource(localSamplerState);

                if (m_customEffectMatrixTransform != null)
                {
                    m_customEffect.SetValue(m_customEffectMatrixTransform, finalMatrix);
                }
            }
            else
            {
                var spriteEffect = MyRender.GetEffect(MyEffects.SpriteBatch) as Effects.MyEffectSpriteBatchShader;
                spriteEffect.SetMatrixTransform(ref finalMatrix);
            }

            // Set VertexInputLayout
            m_graphicsDevice.VertexDeclaration = MyVertexFormatPositionTextureColor.VertexDeclaration;

            // VertexBuffer
            m_graphicsDevice.SetStreamSource(0, m_VBResourceContext.VertexBuffer, 0, MyVertexFormatPositionTextureColor.Stride);

            // Index buffer
            m_graphicsDevice.Indices = m_indexBuffer;

            // If this is a deferred D3D context, reset position so the first Map call will use D3D11_MAP_WRITE_DISCARD.

            /* if (GraphicsDevice.IsDeferred)
             * {
             *   VBResourceContext.VertexBufferPosition = 0;
             * } */
        }
Exemple #3
0
        public override void RecreateControls(bool contructor)
        {
            Controls.Clear();



            m_scale = 0.62f;

            AddCaption(new System.Text.StringBuilder("Colors settings"), Color.Yellow.ToVector4());

            MyGuiControlLabel label = new MyGuiControlLabel(this, new Vector2(0.01f, -m_size.Value.Y / 2.0f + 0.07f), null, new System.Text.StringBuilder("(press ALT to share focus)"), Color.Yellow.ToVector4(), MyGuiConstants.LABEL_TEXT_SCALE * 0.7f,
                                                            MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP);

            Controls.Add(label);

            m_currentPosition = -m_size.Value / 2.0f + new Vector2(0.02f, 0.10f);

            m_currentPosition.Y += 0.01f;
            AddLabel(new StringBuilder("Sun"), Color.Yellow.ToVector4(), 1.2f);

            var sunObj = MySector.SunProperties;

            MyEffectShadowMap shadowMapEffect = MyRender.GetEffect(MyEffects.ShadowMap) as MyEffectShadowMap;

            if (shadowMapEffect != null)
            {
                m_currentPosition.Y += 0.01f;
                AddSlider(new StringBuilder("Intensity"), 0, 10.0f, sunObj, MemberHelper.GetMember(() => MySector.SunProperties.SunIntensity));

                m_currentPosition.Y += 0.01f;
                AddColor(new StringBuilder("Sun color"), sunObj, MemberHelper.GetMember(() => MySector.SunProperties.SunDiffuse));

                m_currentPosition.Y += 0.02f;
                AddColor(new StringBuilder("Sun specular"), sunObj, MemberHelper.GetMember(() => MySector.SunProperties.SunSpecular));

                m_currentPosition.Y += 0.02f;
                AddSlider(new StringBuilder("Back sun intensity"), 0, 5.0f, sunObj, MemberHelper.GetMember(() => MySector.SunProperties.BackSunIntensity));

                m_currentPosition.Y += 0.01f;
                AddColor(new StringBuilder("Back sun color"), sunObj, MemberHelper.GetMember(() => MySector.SunProperties.BackSunDiffuse));

                m_currentPosition.Y += 0.02f;
                AddColor(new StringBuilder("Ambient color"), sunObj, MemberHelper.GetMember(() => MySector.SunProperties.AmbientColor));

                m_currentPosition.Y += 0.02f;
                AddSlider(new StringBuilder("Ambient multiplier"), 0, 5.0f, sunObj, MemberHelper.GetMember(() => MySector.SunProperties.AmbientMultiplier));

                AddSlider(new StringBuilder("Env. ambient intensity"), 0, 5.0f, sunObj, MemberHelper.GetMember(() => MySector.SunProperties.EnvironmentAmbientIntensity));
            }

            /*
             * //m_currentPosition.Y += 0.01f;
             * AddLabel(new StringBuilder("Player ship"), Color.Yellow.ToVector4(), 1.2f);
             *
             * //m_currentPosition.Y += 0.01f;
             * AddSlider(new StringBuilder("Light range multiplier"), 0, 10, null, MemberHelper.GetMember(() => MySmallShip.LightRangeMultiplier));
             * AddSlider(new StringBuilder("Light intensity multiplier"), 0, 10, null, MemberHelper.GetMember(() => MySmallShip.LightIntensityMultiplier));
             * AddSlider(new StringBuilder("Reflector intensity multiplier"), 0, 10, null, MemberHelper.GetMember(() => MySmallShip.ReflectorIntensityMultiplier));
             */
            //m_currentPosition.Y += 0.01f;
            AddLabel(new StringBuilder("Post process"), Color.Yellow.ToVector4(), 1.2f);
            //m_currentPosition.Y += 0.01f;
            MyPostProcessContrast contrastPP = MyRender.GetPostProcess(MyPostProcessEnum.Contrast) as MyPostProcessContrast;

            if (contrastPP != null)
            {
                AddSlider(new StringBuilder("Contrast"), -10, 10, contrastPP, MemberHelper.GetMember(() => contrastPP.Contrast));
                AddSlider(new StringBuilder("Hue"), -10, 10, contrastPP, MemberHelper.GetMember(() => contrastPP.Hue));
                AddSlider(new StringBuilder("Saturation"), -10, 10, contrastPP, MemberHelper.GetMember(() => contrastPP.Saturation));
            }


            m_currentPosition.Y += 0.01f;
        }