public override void DoPostProcess()
        {
            base.DoPostProcess();

            primaryNoiseMapTag   = Open <bitmap>(shaderTransparentPlasmaValues.PrimaryNoiseMap.Value);
            secondaryNoiseMapTag = Open <bitmap>(shaderTransparentPlasmaValues.SecondaryNoiseMap.Value);

            if (MdxRender.Device.DeviceCaps.PixelShaderVersion.Major >= 2)
            {
                string shaderErrors = null;
                effect = Effect.FromStream(MdxRender.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Games.Halo.Resources.Shaders.shader_transparent_plasma.fx"), null, null, ShaderFlags.None, null, out shaderErrors);
                if (!String.IsNullOrEmpty(shaderErrors))
                {
                    LogError("Failed to initialize shader_transparent_plasma effect: {0}", shaderErrors);
                }

                wvpHandle    = effect.GetParameter(null, "worldViewProjection");
                worldHandle  = effect.GetParameter(null, "world");
                cameraHandle = effect.GetParameter(null, "cameraPosition");

                pIHandle        = effect.GetParameter(null, "primaryI");
                pJHandle        = effect.GetParameter(null, "primaryJ");
                pKHandle        = effect.GetParameter(null, "primaryK");
                sIHandle        = effect.GetParameter(null, "secondaryI");
                sJHandle        = effect.GetParameter(null, "secondaryJ");
                sKHandle        = effect.GetParameter(null, "secondaryK");
                offsetHandle    = effect.GetParameter(null, "offset");
                intensityHandle = effect.GetParameter(null, "intensity");

                effect.SetValue(effect.GetParameter(null, "perpendicularBrightness"), shaderTransparentPlasmaValues.PerpendicularBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "parallelBrightness"), shaderTransparentPlasmaValues.ParallelBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "perpendicularColor"), new Vector4(shaderTransparentPlasmaValues.PerpendicularTintColor.R, shaderTransparentPlasmaValues.PerpendicularTintColor.G, shaderTransparentPlasmaValues.PerpendicularTintColor.B, 1.0f));
                effect.SetValue(effect.GetParameter(null, "parallelColor"), new Vector4(shaderTransparentPlasmaValues.ParallelTintColor.R, shaderTransparentPlasmaValues.ParallelTintColor.G, shaderTransparentPlasmaValues.ParallelTintColor.B, 1.0f));

                effect.SetValue(effect.GetParameter(null, "primaryScale"), shaderTransparentPlasmaValues.PrimaryNoiseMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "secondaryScale"), shaderTransparentPlasmaValues.SecondaryNoiseMapScale.Value);

                if (primaryNoiseMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "PrimaryMap"), default3d[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "PrimaryMap"), primaryNoiseMapTag[0]);
                }

                if (secondaryNoiseMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "SecondaryMap"), default3d[Multiplicative]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "SecondaryMap"), secondaryNoiseMapTag[0]);
                }

                effect.Technique = technique = effect.GetTechnique("Plasma");
            }
        }
Ejemplo n.º 2
0
        public override void DoPostProcess()
        {
            // always do this
            base.DoPostProcess();

            // load up the default textures
            globals globals = Globals as globals;

            default2d           = Open <bitmap>(globals.Values.RasterizerData[0].Default2D.Value);
            default3d           = Open <bitmap>(globals.Values.RasterizerData[0].Default3D.Value);
            defaultCube         = Open <bitmap>(globals.Values.RasterizerData[0].DefaultCubeMap.Value);
            vectorNormalization = Open <bitmap>(globals.Values.RasterizerData[0].VectorNormalization.Value);
        }
Ejemplo n.º 3
0
 public override void DoPostProcess()
 {
     base.DoPostProcess();
     sprite  = new Sprite(MdxRender.Device);
     bitmaps = Open <bitmap>(lensFlareValues.Bitmap.Value);
 }
Ejemplo n.º 4
0
        public override void DoPostProcess()
        {
            // always call the base function for DoPostProcess()
            base.DoPostProcess();

            //load texture references
            baseMapTag           = Open <bitmap>(shaderModelValues.BaseMap.Value);
            multipurposeMapTag   = Open <bitmap>(shaderModelValues.MultipurposeMap.Value);
            detailMapTag         = Open <bitmap>(shaderModelValues.DetailMap.Value);
            reflectionCubeMapTag = Open <bitmap>(shaderModelValues.ReflectionCubeMap.Value);

            //initialize texture transforms
            detailMapTransform.Scale(
                shaderModelValues.DetailMapScale.Value,
                shaderModelValues.DetailMapScale.Value,
                1);

            // initialize effects
            if (MdxRender.Device.DeviceCaps.PixelShaderVersion.Major >= 2)
            {
                string shaderErrors = null;
                effect = Effect.FromStream(MdxRender.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Games.Halo.Resources.Shaders.shader_model.fx"), null, null, ShaderFlags.None, null, out shaderErrors);
                if (!String.IsNullOrEmpty(shaderErrors))
                {
                    LogError("Failed to initialize shader_model effect: {0}", shaderErrors);
                }

                lightmapHandle          = effect.GetParameter(null, "LightMap");
                worldHandle             = effect.GetParameter(null, "world");
                wvpHandle               = effect.GetParameter(null, "worldViewProjection");
                cameraHandle            = effect.GetParameter(null, "cameraPosition");
                fogStartHandle          = effect.GetParameter(null, "fogStart");
                fogEndHandle            = effect.GetParameter(null, "fogEnd");
                fogDensityHandle        = effect.GetParameter(null, "fogDensity");
                ambientColorHandle      = effect.GetParameter(null, "ambientColor");
                illuminationValueHandle = effect.GetParameter(null, "selfIlluminationValue");
                changeColorValueHandle  = effect.GetParameter(null, "changeColor");
                effect.SetValue(changeColorValueHandle, new Vector4(1.0f, 1.0f, 1.0f, 1.0f));

                effect.SetValue(effect.GetParameter(null, "detailAfterReflection"), (shaderModelValues.Flags.Value & 0x1) != 0);
                effect.SetValue(effect.GetParameter(null, "detailFunction"), shaderModelValues.DetailFunction.Value);

                effect.SetValue(effect.GetParameter(null, "parallelBrightness"), shaderModelValues.ParallelBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "perpendicularBrightness"), shaderModelValues.PerpendicularBrightness.Value);

                effect.SetValue(effect.GetParameter(null, "detailScale"), shaderModelValues.DetailMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "detailVScale"), shaderModelValues.DetailMap2.Value);
                effect.SetValue(effect.GetParameter(null, "uScale"), shaderModelValues.Map.Value);
                effect.SetValue(effect.GetParameter(null, "vScale"), shaderModelValues.Map2.Value);

                effect.SetValue(effect.GetParameter(null, "selfIlluminationLower"), new Vector4(shaderModelValues.AnimationColorLowerBound.R, shaderModelValues.AnimationColorLowerBound.G, shaderModelValues.AnimationColorLowerBound.B, 1.0f));
                effect.SetValue(effect.GetParameter(null, "selfIlluminationUpper"), new Vector4(shaderModelValues.AnimationColorUpperBound.R, shaderModelValues.AnimationColorUpperBound.G, shaderModelValues.AnimationColorUpperBound.B, 1.0f));

                if (baseMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "BaseMap"), default2d[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "BaseMap"), baseMapTag[0]);
                }

                if (reflectionCubeMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), defaultCube[SignedAdditive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), reflectionCubeMapTag[0]);
                }

                if (detailMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "DetailMap"), default2d[SignedAdditive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "DetailMap"), detailMapTag[0]);
                }

                if (multipurposeMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "MultipurposeMap"), default2d[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "MultipurposeMap"), multipurposeMapTag[0]);
                }

                switch (shaderModelValues.DetailMask.Value)
                {
                case 0:
                    effect.Technique = technique = effect.GetTechnique("ModelNoDetailMask");
                    break;

                case 1:
                    effect.Technique = technique = effect.GetTechnique("ModelIReflectionDetailMask");
                    break;

                case 2:
                    effect.Technique = technique = effect.GetTechnique("ModelReflectionDetailMask");
                    break;

                case 3:
                    effect.Technique = technique = effect.GetTechnique("ModelIIllumDetailMask");
                    break;

                case 4:
                    effect.Technique = technique = effect.GetTechnique("ModelIllumDetailMask");
                    break;

                case 5:
                    effect.Technique = technique = effect.GetTechnique("ModelIChangeColorDetailMask");
                    break;

                case 6:
                    effect.Technique = technique = effect.GetTechnique("ModelChangeColorDetailMask");
                    break;

                case 7:
                    effect.Technique = technique = effect.GetTechnique("ModelIAuxiliaryDetailMask");
                    break;

                case 8:
                    effect.Technique = technique = effect.GetTechnique("ModelAuxiliaryDetailMask");
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        public override void DoPostProcess()
        {
            // always call the base function for DoPostProcess()
            base.DoPostProcess();

            //load texture references
            baseMapTag            = Open <bitmap>(shaderEnvironmentValues.BaseMap.Value);
            primaryDetailMapTag   = Open <bitmap>(shaderEnvironmentValues.PrimaryDetailMap.Value);
            secondaryDetailMapTag = Open <bitmap>(shaderEnvironmentValues.SecondaryDetailMap.Value);
            microDetailMapTag     = Open <bitmap>(shaderEnvironmentValues.MicroDetailMap.Value);
            bumpMapTag            = Open <bitmap>(shaderEnvironmentValues.BumpMap.Value);
            environmentMapTag     = Open <bitmap>(shaderEnvironmentValues.ReflectionCubeMap.Value);
            glowMapTag            = Open <bitmap>(shaderEnvironmentValues.Map.Value);

            //initialize texture transforms
            primaryDetailMapTransform.Scale(
                shaderEnvironmentValues.PrimaryDetailMapScale.Value,
                shaderEnvironmentValues.PrimaryDetailMapScale.Value,
                1);

            secondaryDetailMapTransform.Scale(
                shaderEnvironmentValues.SecondaryDetailMapScale.Value,
                shaderEnvironmentValues.SecondaryDetailMapScale.Value,
                1);

            microDetailMapTransform.Scale(
                shaderEnvironmentValues.MicroDetailMapScale.Value,
                shaderEnvironmentValues.MicroDetailMapScale.Value,
                1);

            // load the environment shader and set our values
            if (MdxRender.Device.DeviceCaps.PixelShaderVersion.Major >= 2)
            {
                string shaderErrors = null;
                effect = Effect.FromStream(MdxRender.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Games.Halo.Resources.Shaders.shader_environment.fx"), null, null, ShaderFlags.None, null, out shaderErrors);
                if (!String.IsNullOrEmpty(shaderErrors))
                {
                    LogError("Failed to initialize shader_environment effect: {0}", shaderErrors);
                }
                lightmapHandle       = effect.GetParameter(null, "LightMap");
                worldHandle          = effect.GetParameter(null, "world");
                wvpHandle            = effect.GetParameter(null, "worldViewProjection");
                cameraHandle         = effect.GetParameter(null, "cameraPosition");
                primaryValueHandle   = effect.GetParameter(null, "primaryAnimationValue");
                secondaryValueHandle = effect.GetParameter(null, "secondaryAnimationValue");
                plasmaValueHandle    = effect.GetParameter(null, "plasmaAnimationValue");
                uValueHandle         = effect.GetParameter(null, "uAnimationValue");
                vValueHandle         = effect.GetParameter(null, "vAnimationValue");
                fogStartHandle       = effect.GetParameter(null, "fogStart");
                fogEndHandle         = effect.GetParameter(null, "fogEnd");
                fogDensityHandle     = effect.GetParameter(null, "fogDensity");
                ambientColorHandle   = effect.GetParameter(null, "ambientColor");

                if (environmentMapTag == null || (shaderEnvironmentValues.ParallelBrightness.Value == 0.0f && shaderEnvironmentValues.PerpendicularBrightness.Value == 0.0f))
                {
                    switch (shaderEnvironmentValues.Type.Value)
                    {
                    case 0: // normal
                        switch (shaderEnvironmentValues.DetailMapFunction.Value)
                        {
                        case 0: // double multiply
                            switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                            {
                            case 0: // double multiply
                                effect.Technique = technique = effect.GetTechnique("NormalDMDMDetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;

                            case 1: // multiply
                                effect.Technique = technique = effect.GetTechnique("NormalDMMDetailBlend");
                                SetDetail(SignedAdditive, Multiplicative);
                                break;

                            case 2: // biased add
                                effect.Technique = technique = effect.GetTechnique("NormalDMADetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;
                            }
                            break;

                        case 1: // multiply
                            switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                            {
                            case 0: // double multiply
                                effect.Technique = technique = effect.GetTechnique("NormalMDMDetailBlend");
                                SetDetail(Multiplicative, SignedAdditive);
                                break;

                            case 1: // multiply
                                effect.Technique = technique = effect.GetTechnique("NormalMMDetailBlend");
                                SetDetail(Multiplicative, SignedAdditive);
                                break;

                            case 2: // biased add
                                effect.Technique = technique = effect.GetTechnique("NormalMADetailBlend");
                                SetDetail(Multiplicative, SignedAdditive);
                                break;
                            }
                            break;

                        case 2: // biased add
                            switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                            {
                            case 0: // double multiply
                                effect.Technique = technique = effect.GetTechnique("NormalADMDetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;

                            case 1: // multiply
                                effect.Technique = technique = effect.GetTechnique("NormalAMDetailBlend");
                                SetDetail(SignedAdditive, Multiplicative);
                                break;

                            case 2: // biased add
                                effect.Technique = technique = effect.GetTechnique("NormalAADetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;
                            }
                            break;
                        }
                        break;

                    case 1: // normal
                        switch (shaderEnvironmentValues.DetailMapFunction.Value)
                        {
                        case 0: // double multiply
                            switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                            {
                            case 0: // double multiply
                                effect.Technique = technique = effect.GetTechnique("BlendedDMDMDetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;

                            case 1: // multiply
                                effect.Technique = technique = effect.GetTechnique("BlendedDMMDetailBlend");
                                SetDetail(SignedAdditive, Multiplicative);
                                break;

                            case 2: // biased add
                                effect.Technique = technique = effect.GetTechnique("BlendedDMADetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;
                            }
                            break;

                        case 1: // multiply
                            switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                            {
                            case 0: // double multiply
                                effect.Technique = technique = effect.GetTechnique("BlendedMDMDetailBlend");
                                SetDetail(Multiplicative, SignedAdditive);
                                break;

                            case 1: // multiply
                                effect.Technique = technique = effect.GetTechnique("BlendedMMDetailBlend");
                                SetDetail(Multiplicative, Multiplicative);
                                break;

                            case 2: // biased add
                                effect.Technique = technique = effect.GetTechnique("BlendedMADetailBlend");
                                SetDetail(Multiplicative, SignedAdditive);
                                break;
                            }
                            break;

                        case 2: // biased add
                            switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                            {
                            case 0: // double multiply
                                effect.Technique = technique = effect.GetTechnique("BlendedADMDetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;

                            case 1: // multiply
                                effect.Technique = technique = effect.GetTechnique("BlendedAMDetailBlend");
                                SetDetail(SignedAdditive, Multiplicative);
                                break;

                            case 2: // biased add
                                effect.Technique = technique = effect.GetTechnique("BlendedAADetailBlend");
                                SetDetail(SignedAdditive, SignedAdditive);
                                break;
                            }
                            break;
                        }
                        break;
                    }
                }
                else
                {
                    switch (shaderEnvironmentValues.Type2.Value)
                    {
                    case 0:
                        switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                        {
                        case 0: // double multiply
                            effect.Technique = technique = effect.GetTechnique("BumpedEnvironmentMapDM");
                            SetDetail(SignedAdditive, SignedAdditive);
                            break;

                        case 1: // multiply
                            effect.Technique = technique = effect.GetTechnique("BumpedEnvironmentMapM");
                            SetDetail(SignedAdditive, Multiplicative);
                            break;

                        case 2: // biased add
                            effect.Technique = technique = effect.GetTechnique("BumpedEnvironmentMapA");
                            SetDetail(SignedAdditive, SignedAdditive);
                            break;
                        }
                        break;

                    case 1:
                        switch (shaderEnvironmentValues.MicroDetailMapFunction.Value)
                        {
                        case 0: // double multiply
                            effect.Technique = technique = effect.GetTechnique("FlatEnvironmentMapDM");
                            SetDetail(SignedAdditive, SignedAdditive);
                            break;

                        case 1: // multiply
                            effect.Technique = technique = effect.GetTechnique("FlatEnvironmentMapM");
                            SetDetail(SignedAdditive, Multiplicative);
                            break;

                        case 2: // biased add
                            effect.Technique = technique = effect.GetTechnique("FlatEnvironmentMapA");
                            SetDetail(SignedAdditive, SignedAdditive);
                            break;
                        }
                        break;
                    }
                }

                effect.SetValue(effect.GetParameter(null, "bumpScale"), shaderEnvironmentValues.BumpMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "detailAScale"), shaderEnvironmentValues.PrimaryDetailMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "detailBScale"), shaderEnvironmentValues.SecondaryDetailMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "microDetailScale"), shaderEnvironmentValues.MicroDetailMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "glowScale"), shaderEnvironmentValues.MapScale.Value);

                effect.SetValue(effect.GetParameter(null, "parallelShininess"), shaderEnvironmentValues.ParallelBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "perpendicularShininess"), shaderEnvironmentValues.PerpendicularBrightness.Value);

                effect.SetValue(effect.GetParameter(null, "primaryAnimationColor"), new Vector4(shaderEnvironmentValues.PrimaryOnColor.R, shaderEnvironmentValues.PrimaryOnColor.G, shaderEnvironmentValues.PrimaryOnColor.B, 0.0f));
                effect.SetValue(effect.GetParameter(null, "secondaryAnimationColor"), new Vector4(shaderEnvironmentValues.SecondaryOnColor.R, shaderEnvironmentValues.SecondaryOnColor.G, shaderEnvironmentValues.SecondaryOnColor.B, 0.0f));
                effect.SetValue(effect.GetParameter(null, "plasmaAnimationColor"), new Vector4(shaderEnvironmentValues.PlasmaOnColor.R, shaderEnvironmentValues.PlasmaOnColor.G, shaderEnvironmentValues.PlasmaOnColor.B, 0.0f));

                effect.SetValue(effect.GetParameter(null, "VectorNormalization"), vectorNormalization[0]);

                if (baseMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "BaseMap"), default2d[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "BaseMap"), baseMapTag[0]);
                }

                if (environmentMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), defaultCube[SignedAdditive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), environmentMapTag[0]);
                }

                if (bumpMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "BumpMap"), default2d[Vector]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "BumpMap"), bumpMapTag[0]);
                }

                if (glowMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "GlowMap"), default2d[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "GlowMap"), glowMapTag[0]);
                }
            }


            //effect = Effect.FromStream(); (use an effect pool?)

            //todo: choose which effect file or technique
            //      to use based on lightmap presence, hardware, etc
            //effect.Technique = "LitBaseTexture";

            //this.technique = effect.Technique; //cache technique handle
        }
Ejemplo n.º 6
0
 //todo: figure out how to deal with enabled/disabled texture scaling, animation
 public Stage(bitmap bmpTag, int stage)
 {
     bitmapTag  = bmpTag;
     stageIndex = stage;
 }
Ejemplo n.º 7
0
        public override void DoPostProcess()
        {
            base.DoPostProcess();

            tintMapTag       = Open <bitmap>(shaderTransparentGlassValues.BackgroundTintMap.Value);
            reflectionMapTag = Open <bitmap>(shaderTransparentGlassValues.ReflectionMap.Value);
            bumpMapTag       = Open <bitmap>(shaderTransparentGlassValues.BumpMap.Value);
            diffuseMapTag    = Open <bitmap>(shaderTransparentGlassValues.DiffuseMap.Value);
            detailMapTag     = Open <bitmap>(shaderTransparentGlassValues.DiffuseDetailMap.Value);
            specularMapTag   = Open <bitmap>(shaderTransparentGlassValues.SpecularMap.Value);

            if (MdxRender.Device.DeviceCaps.PixelShaderVersion.Major >= 2)
            {
                string shaderErrors = null;
                effect = Effect.FromStream(MdxRender.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Games.Halo.Resources.Shaders.shader_transparent_glass.fx"), null, null, ShaderFlags.None, null, out shaderErrors);
                if (!String.IsNullOrEmpty(shaderErrors))
                {
                    LogError("Failed to initialize shader_transparent_glass effect: {0}", shaderErrors);
                }

                lightmapHandle   = effect.GetParameter(null, "LightMap");
                worldHandle      = effect.GetParameter(null, "world");
                wvpHandle        = effect.GetParameter(null, "worldViewProjection");
                cameraHandle     = effect.GetParameter(null, "cameraPosition");
                fogStartHandle   = effect.GetParameter(null, "fogStart");
                fogEndHandle     = effect.GetParameter(null, "fogEnd");
                fogDensityHandle = effect.GetParameter(null, "fogDensity");

                effect.SetValue(effect.GetParameter(null, "perpendicularBrightness"), shaderTransparentGlassValues.PerpendicularBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "parallelBrightness"), shaderTransparentGlassValues.ParallelBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "perpendicularColor"), new ColorValue(shaderTransparentGlassValues.PerpendicularTintColor.R, shaderTransparentGlassValues.PerpendicularTintColor.G, shaderTransparentGlassValues.PerpendicularTintColor.B, 1.0f));
                effect.SetValue(effect.GetParameter(null, "parallelColor"), new ColorValue(shaderTransparentGlassValues.ParallelTintColor.R, shaderTransparentGlassValues.ParallelTintColor.G, shaderTransparentGlassValues.ParallelTintColor.B, 1.0f));
                if (shaderTransparentGlassValues.BackgroundTintColor.R == 0.0f && shaderTransparentGlassValues.BackgroundTintColor.G == 0.0f && shaderTransparentGlassValues.BackgroundTintColor.B == 0.0f)
                {
                    effect.SetValue(effect.GetParameter(null, "backgroundTintColor"), new ColorValue(1.0f, 1.0f, 1.0f, 1.0f));
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "backgroundTintColor"), new ColorValue(shaderTransparentGlassValues.BackgroundTintColor.R, shaderTransparentGlassValues.BackgroundTintColor.G, shaderTransparentGlassValues.BackgroundTintColor.B, 1.0f));
                }

                effect.SetValue(effect.GetParameter(null, "diffuseScale"), shaderTransparentGlassValues.DiffuseMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "bumpScale"), shaderTransparentGlassValues.BumpMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "tintScale"), shaderTransparentGlassValues.BackgroundTintMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "detailScale"), shaderTransparentGlassValues.DiffuseDetailMapScale.Value);
                effect.SetValue(effect.GetParameter(null, "specularScale"), shaderTransparentGlassValues.SpecularMapScale.Value);

                if (diffuseMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "DiffuseMap"), default2d[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "DiffuseMap"), diffuseMapTag[0]);
                }

                if (bumpMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "BumpMap"), default2d[Vector]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "BumpMap"), bumpMapTag[0]);
                }

                if (tintMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "TintMap"), default2d[Multiplicative]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "TintMap"), tintMapTag[0]);
                }

                if (detailMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "DetailMap"), default2d[SignedAdditive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "DetailMap"), detailMapTag[0]);
                }

                if (reflectionMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), defaultCube[SignedAdditive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), reflectionMapTag[0]);
                }

                if (specularMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "SpecularMap"), defaultCube[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "SpecularMap"), specularMapTag[0]);
                }

                if (shaderTransparentGlassValues.ReflectionType.Value == 1)
                {
                    if (specularMapTag == null)
                    {
                        effect.Technique = technique = effect.GetTechnique("FlatGlass");
                    }
                    else if (diffuseMapTag == null && reflectionMapTag == null)
                    {
                        effect.Technique = technique = effect.GetTechnique("FlatGlassSpecular");
                    }
                    else
                    {
                        effect.Technique = technique = effect.GetTechnique("FlatGlassTwoPass");
                    }
                }
                else
                {
                    if (specularMapTag == null)
                    {
                        effect.Technique = technique = effect.GetTechnique("BumpedGlass");
                    }
                    else if (diffuseMapTag == null && reflectionMapTag == null)
                    {
                        effect.Technique = technique = effect.GetTechnique("BumpedGlassSpecular");
                    }
                    else
                    {
                        effect.Technique = technique = effect.GetTechnique("BumpedGlassTwoPass");
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public override void DoPostProcess()
        {
            // always call the base function for DoPostProcess()
            base.DoPostProcess();

            //load texture references
            baseMapTag       = Open <bitmap>(shaderTransparentWaterValues.BaseMap.Value);
            reflectionMapTag = Open <bitmap>(shaderTransparentWaterValues.ReflectionMap.Value);
            rippleMapsTag    = Open <bitmap>(shaderTransparentWaterValues.RippleMaps.Value);

            //initialize texture transforms
            for (int i = 0; i < rippleTransforms.Count; i++)
            {
                float u_offset = shaderTransparentWaterValues.Ripples[i].MapOffset.I;
                float v_offset = shaderTransparentWaterValues.Ripples[i].MapOffset.K;

                Matrix tmp = new Matrix();
                tmp     = Matrix.Identity;
                tmp.M31 = u_offset;
                tmp.M32 = v_offset;
                tmp.Scale(
                    shaderTransparentWaterValues.RippleScale.Value,
                    shaderTransparentWaterValues.RippleScale.Value,
                    0);
                rippleTransforms.Add(tmp);
            }

            // initialize effects
            if (MdxRender.Device.DeviceCaps.PixelShaderVersion.Major >= 2)
            {
                string shaderErrors = null;
                effect = Effect.FromStream(MdxRender.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Games.Halo.Resources.Shaders.shader_transparent_water.fx"), null, null, ShaderFlags.None, null, out shaderErrors);
                if (!String.IsNullOrEmpty(shaderErrors))
                {
                    LogError("Failed to initialize shader_transparent_water effect: {0}", shaderErrors);
                }

                lightmapHandle = effect.GetParameter(null, "LightMap");
                worldHandle    = effect.GetParameter(null, "world");
                wvpHandle      = effect.GetParameter(null, "worldViewProjection");
                cameraHandle   = effect.GetParameter(null, "cameraPosition");
                animations     = new EffectHandle[4];
                for (int i = 0; i < 4; i++)
                {
                    animations[i] = effect.GetParameter(null, "animation" + i.ToString());
                }

                effect.SetValue(effect.GetParameter(null, "alphaModulatesReflection"), (shaderTransparentWaterValues.Flags.Value & 0x1) != 0);
                effect.SetValue(effect.GetParameter(null, "colorModulatesBackground"), (shaderTransparentWaterValues.Flags.Value & 0x2) != 0);

                effect.SetValue(effect.GetParameter(null, "rippleCount"), shaderTransparentWaterValues.Ripples.Count);
                effect.SetValue(effect.GetParameter(null, "rippleScale"), shaderTransparentWaterValues.RippleScale.Value);
                effect.SetValue(effect.GetParameter(null, "rippleAngle"), shaderTransparentWaterValues.RippleAnimationAngle.Value);

                if (shaderTransparentWaterValues.Ripples.Count > 0)
                {
                    effect.SetValue(effect.GetParameter(null, "factor0"), shaderTransparentWaterValues.Ripples[0].ContributionFactor.Value);
                    effect.SetValue(effect.GetParameter(null, "repeat0"), (float)shaderTransparentWaterValues.Ripples[0].MapRepeats.Value);
                    effect.SetValue(effect.GetParameter(null, "angle0"), shaderTransparentWaterValues.Ripples[0].AnimationAngle.Value);
                    effect.SetValue(effect.GetParameter(null, "offset0"), new Vector4(shaderTransparentWaterValues.Ripples[0].MapOffset.I, shaderTransparentWaterValues.Ripples[0].MapOffset.K, 0.0f, 0.0f));
                    if (shaderTransparentWaterValues.Ripples.Count > 1)
                    {
                        effect.SetValue(effect.GetParameter(null, "factor1"), shaderTransparentWaterValues.Ripples[1].ContributionFactor.Value);
                        effect.SetValue(effect.GetParameter(null, "repeat1"), (float)shaderTransparentWaterValues.Ripples[1].MapRepeats.Value);
                        effect.SetValue(effect.GetParameter(null, "angle1"), shaderTransparentWaterValues.Ripples[1].AnimationAngle.Value);
                        effect.SetValue(effect.GetParameter(null, "offset1"), new Vector4(shaderTransparentWaterValues.Ripples[1].MapOffset.I, shaderTransparentWaterValues.Ripples[1].MapOffset.K, 0.0f, 0.0f));
                        if (shaderTransparentWaterValues.Ripples.Count > 2)
                        {
                            effect.SetValue(effect.GetParameter(null, "factor2"), shaderTransparentWaterValues.Ripples[2].ContributionFactor.Value);
                            effect.SetValue(effect.GetParameter(null, "repeat2"), (float)shaderTransparentWaterValues.Ripples[2].MapRepeats.Value);
                            effect.SetValue(effect.GetParameter(null, "angle2"), shaderTransparentWaterValues.Ripples[2].AnimationAngle.Value);
                            effect.SetValue(effect.GetParameter(null, "offset2"), new Vector4(shaderTransparentWaterValues.Ripples[2].MapOffset.I, shaderTransparentWaterValues.Ripples[2].MapOffset.K, 0.0f, 0.0f));
                            if (shaderTransparentWaterValues.Ripples.Count > 3)
                            {
                                effect.SetValue(effect.GetParameter(null, "factor3"), shaderTransparentWaterValues.Ripples[3].ContributionFactor.Value);
                                effect.SetValue(effect.GetParameter(null, "repeat3"), (float)shaderTransparentWaterValues.Ripples[3].MapRepeats.Value);
                                effect.SetValue(effect.GetParameter(null, "angle3"), shaderTransparentWaterValues.Ripples[3].AnimationAngle.Value);
                                effect.SetValue(effect.GetParameter(null, "offset3"), new Vector4(shaderTransparentWaterValues.Ripples[3].MapOffset.I, shaderTransparentWaterValues.Ripples[3].MapOffset.K, 0.0f, 0.0f));
                            }
                        }
                    }
                }

                effect.SetValue(effect.GetParameter(null, "perpendicularBrightness"), shaderTransparentWaterValues.ViewPerpendicularBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "parallelBrightness"), shaderTransparentWaterValues.ViewParallelBrightness.Value);
                effect.SetValue(effect.GetParameter(null, "perpendicularColor"), new Vector4(shaderTransparentWaterValues.ViewPerpendicularTintColor.R, shaderTransparentWaterValues.ViewPerpendicularTintColor.G, shaderTransparentWaterValues.ViewPerpendicularTintColor.B, 1.0f));
                effect.SetValue(effect.GetParameter(null, "parallelColor"), new Vector4(shaderTransparentWaterValues.ViewParallelTintColor.R, shaderTransparentWaterValues.ViewParallelTintColor.G, shaderTransparentWaterValues.ViewParallelTintColor.B, 1.0f));

                if (baseMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "BaseMap"), default2d[Additive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "BaseMap"), baseMapTag[0]);
                }

                if (reflectionMapTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), defaultCube[SignedAdditive]);
                }
                else
                {
                    effect.SetValue(effect.GetParameter(null, "EnvironmentMap"), reflectionMapTag[0]);
                }

                if (rippleMapsTag == null)
                {
                    effect.SetValue(effect.GetParameter(null, "RippleMap0"), default2d[Vector]);
                    effect.SetValue(effect.GetParameter(null, "RippleMap1"), default2d[Vector]);
                    effect.SetValue(effect.GetParameter(null, "RippleMap2"), default2d[Vector]);
                    effect.SetValue(effect.GetParameter(null, "RippleMap3"), default2d[Vector]);
                }
                else
                {
                    if (shaderTransparentWaterValues.Ripples.Count > 0)
                    {
                        effect.SetValue(effect.GetParameter(null, "RippleMap0"), rippleMapsTag[shaderTransparentWaterValues.Ripples[0].MapIndex.Value]);
                        if (shaderTransparentWaterValues.Ripples.Count > 1)
                        {
                            effect.SetValue(effect.GetParameter(null, "RippleMap1"), rippleMapsTag[shaderTransparentWaterValues.Ripples[1].MapIndex.Value]);
                            if (shaderTransparentWaterValues.Ripples.Count > 2)
                            {
                                effect.SetValue(effect.GetParameter(null, "RippleMap2"), rippleMapsTag[shaderTransparentWaterValues.Ripples[2].MapIndex.Value]);
                                if (shaderTransparentWaterValues.Ripples.Count > 3)
                                {
                                    effect.SetValue(effect.GetParameter(null, "RippleMap3"), rippleMapsTag[shaderTransparentWaterValues.Ripples[3].MapIndex.Value]);
                                }
                                else
                                {
                                    effect.SetValue(effect.GetParameter(null, "RippleMap3"), default2d[Vector]);
                                }
                            }
                            else
                            {
                                effect.SetValue(effect.GetParameter(null, "RippleMap2"), default2d[Vector]);
                            }
                        }
                        else
                        {
                            effect.SetValue(effect.GetParameter(null, "RippleMap1"), default2d[Vector]);
                        }
                    }
                    else
                    {
                        effect.SetValue(effect.GetParameter(null, "RippleMap0"), default2d[Vector]);
                    }
                }

                effect.Technique = technique = effect.GetTechnique("Water");
            }
        }