private void BuildFFPSubRenderState(int subRenderStateOrder, string subRenderStateType,
                                            ShaderGenerator.SGPass sgPass, TargetRenderState renderState)
        {
            if (subRenderStateOrder == -1)
            {
                throw new Exception("Actual sub render type needs to be declared");
            }

            SubRenderState subRenderState;

            subRenderState = sgPass.GetCustomFFPSubState(subRenderStateOrder);

            if (subRenderState == null)
            {
                subRenderState = ShaderGenerator.Instance.CreateSubRenderState(subRenderStateType);
            }

            if (subRenderState.PreAddToRenderState(renderState, sgPass.SrcPass, sgPass.DstPass))
            {
                renderState.AddSubRenderStateInstance(subRenderState);
            }
            else
            {
                ShaderGenerator.Instance.DestroySubRenderState(subRenderState);
            }
        }
        private void ResolveColorStageFlags(ShaderGenerator.SGPass sgPass, TargetRenderState renderState)
        {
            var      subRenderStateList = renderState.TemplateSubRenderStateList;
            FFPColor colorSubState      = null;

            //find the color sub state
            foreach (var curSubRenderState in subRenderStateList)
            {
                if (curSubRenderState.Type == FFPColor.FFPType)
                {
                    colorSubState = curSubRenderState as FFPColor;
                }
            }

            foreach (var curSubRenderState in subRenderStateList)
            {
                //Add vertex shader specular lighting output in case of specular enabled.
                if (curSubRenderState.Type == FFPLighting.FFPType)
                {
                    colorSubState.AddResolveStageMask((int)FFPColor.StageFlags.VsOutputdiffuse);

                    Pass srcPass = sgPass.SrcPass;

                    if (srcPass.Shininess > 0 && srcPass.Specular != ColorEx.Black)
                    {
                        colorSubState.AddResolveStageMask((int)FFPColor.StageFlags.VsOutputSpecular);
                    }
                    break;
                }
            }
        }
Beispiel #3
0
        internal void ReleasePrograms(Graphics.Pass pass, TargetRenderState renderState)
        {
            ProgramSet programSet = renderState.ProgramSet;

            pass.SetVertexProgram(string.Empty);
            pass.SetFragmentProgram(string.Empty);

            renderState.DestroyProgramSet();

            foreach (var key in this.vertexShaderMap.Keys)
            {
                if (true)                   //TODO
                {
                    DestroyGpuProgram(this.vertexShaderMap[key]);
                    this.vertexShaderMap.Remove(key);
                    break;
                }
            }

            foreach (var key in this.fragmentShaderMap.Keys)
            {
                if (true)
                {
                    DestroyGpuProgram(this.fragmentShaderMap[key]);
                    this.fragmentShaderMap.Remove(key);
                    break;
                }
            }
        }
Beispiel #4
0
        public override bool PreAddToRenderState(TargetRenderState targetRenderState, Graphics.Pass srcPass,
                                                 Graphics.Pass dstPass)
        {
            if (srcPass.LightingEnabled == false)
            {
                return(false);
            }

            var lightCount = new int[3];

            targetRenderState.GetLightCount(out lightCount);
            TrackVertexColorType = srcPass.VertexColorTracking;

            if (srcPass.Shininess > 0 && srcPass.Specular != ColorEx.Black)
            {
                SpecularEnabled = true;
            }
            else
            {
                SpecularEnabled = false;
            }

            //Case this pass should run once per light(s) -> override the light policy.
            if (srcPass.IteratePerLight)
            {
                //This is the preferred case -> only one type of light is handled
                if (srcPass.RunOnlyOncePerLightType)
                {
                    if (srcPass.OnlyLightType == LightType.Point)
                    {
                        lightCount[0] = srcPass.LightsPerIteration;
                        lightCount[1] = 0;
                        lightCount[2] = 0;
                    }
                    else if (srcPass.OnlyLightType == LightType.Directional)
                    {
                        lightCount[0] = 0;
                        lightCount[1] = srcPass.LightsPerIteration;
                        lightCount[2] = 0;
                    }
                    else if (srcPass.OnlyLightType == LightType.Spotlight)
                    {
                        lightCount[0] = 0;
                        lightCount[1] = 0;
                        lightCount[2] = srcPass.LightsPerIteration;
                    }
                }
                else
                {
                    throw new AxiomException(
                              "Using iterative lighting method with RT Shader System requires specifying explicit light type");
                }
            }

            SetLightCount(lightCount);

            return(true);
        }
Beispiel #5
0
        public override bool PreAddToRenderState(TargetRenderState targetRenderState, Pass srcPass, Pass dstPass)
        {
            this.atlasTexcoordPos = 0;
            TextureAtlasSamplerFactory factory = TextureAtlasSamplerFactory.Instance;

            bool hasAtlas = false;
            int  texCount = srcPass.TextureUnitStatesCount;

            for (int i = 0; i < texCount; i++)
            {
                TextureUnitState pState = srcPass.GetTextureUnitState(i);

                var table = factory.GetTextureAtlasTable(pState.TextureName);
                if (table != null)
                {
                    if (table.Count > TextureAtlasSampler.MaxSafeAtlasedTextuers)
                    {
                        Axiom.Core.LogManager.Instance.Write(
                            "Warning: Compiling atlas texture has too many internally defined textures. Shader may fail to compile.");
                    }
                    if (i > TextureAtlasSampler.MaxTextures)
                    {
                        throw new Axiom.Core.AxiomException(
                                  "Texture atlas sub-render does not support more than TextureAtlasSampler.MaxTextures {0} atlas textures",
                                  TextureAtlasSampler.MaxTextures);
                    }
                    if (pState.TextureType != TextureType.TwoD)
                    {
                        throw new Axiom.Core.AxiomException("Texture atlas sub-render state only supports 2d textures.");
                    }

                    this.atlasTableDatas[i]     = table;
                    this.textureAddressings[i]  = pState.TextureAddressingMode;
                    this.isAtlasTextureUnits[i] = true;
                    hasAtlas = true;
                }
            }

            //Gather the materials atlas processing attributes
            //and calculate the position of the indexes
            TextureAtlasAttib attrib;

            factory.HasMaterialAtlasingAttributes(srcPass.Parent.Parent, out attrib);

            this.autoAdjustPollPosition = attrib.autoBorderAdjust;
            this.atlasTexcoordPos       = attrib.positionOffset;
            if (attrib.positionMode == IndexPositionMode.Relative)
            {
                this.atlasTexcoordPos += texCount - 1;
            }

            return(hasAtlas);
        }
Beispiel #6
0
        public override bool PreAddToRenderState(TargetRenderState targetRenderState, Graphics.Pass srcPass,
                                                 Graphics.Pass dstPass)
        {
            TrackVertexColor trackColor = srcPass.VertexColorTracking;

            if (trackColor != null)
            {
                AddResolveStageMask((int)StageFlags.VsInputDiffuse);
            }

            return(true);
        }
Beispiel #7
0
        public override bool PreAddToRenderState(TargetRenderState targetRenderState, Pass srcPass, Pass dstPass)
        {
            FogMode fMode;
            ColorEx newFogColor;
            Real    newFogStart, newFogEnd, newFogDensity;

            if (srcPass.FogOverride)
            {
                fMode         = srcPass.FogMode;
                newFogColor   = srcPass.FogColor;
                newFogStart   = srcPass.FogStart;
                newFogEnd     = srcPass.FogEnd;
                newFogDensity = srcPass.FogDensity;
            }
            else
            {
                var sceneMgr = ShaderGenerator.Instance.ActiveSceneManager;

                if (sceneMgr == null)
                {
                    fMode         = FogMode.None;
                    newFogColor   = ColorEx.White;
                    newFogStart   = 0.0f;
                    newFogEnd     = 0.0f;
                    newFogDensity = 0.0f;
                }
                else
                {
                    fMode         = sceneMgr.FogMode;
                    newFogColor   = sceneMgr.FogColor;
                    newFogStart   = sceneMgr.FogStart;
                    newFogEnd     = sceneMgr.FogEnd;
                    newFogDensity = sceneMgr.FogDensity;
                }

                this.passOverrideParams = false;
            }
            //Set fog properties
            SetFogProperties(fMode, newFogColor, newFogStart, newFogEnd, newFogDensity);

            //Override scene fog since it will happen in shader
            dstPass.SetFog(true, FogMode.None, newFogColor, newFogDensity, newFogStart, newFogEnd);
            return(true);
        }
Beispiel #8
0
        public override bool PreAddToRenderState(TargetRenderState targetRenderState, Graphics.Pass srcPass,
                                                 Graphics.Pass dstPass)
        {
            bool      isValid   = true;
            Technique firstTech = srcPass.Parent.Parent.GetTechnique(0);

            //TODO
            //var hsAny = firstTech.UserObjectBindings.GetUserAny(HardwareSkinning.HsDataBindName);
            if (false) //hsAny.isEmpty == false)
            {
            }
            //If there is no associated techniqe, default to linear skinning as a pass-through
            if (this.activeTechnique == null)
            {
                SetHardwareSkinningParam(0, 0, RTShaderSystem.SkinningType.Linear, false, false);
            }
            int boneCount   = this.activeTechnique.BoneCount;
            int weightCount = this.activeTechnique.WeightCount;

            bool doBoneCalculations = isValid && (boneCount != 0) && (boneCount <= 256) && (weightCount != 0) &&
                                      (weightCount <= 4) &&
                                      ((this.creator == null) || (boneCount <= this.creator.MaxCalculableBoneCount));

            this.activeTechnique.DoBoneCalculations = doBoneCalculations;


            if ((doBoneCalculations) && (this.creator != null))
            {
                //update the receiver and caster materials
                if (dstPass.Parent.ShadowCasterMaterial == null)
                {
                    Material mat = this.creator.GetCustomShadowCasterMaterial(this.skinningType, weightCount - 1);
                    dstPass.Parent.SetShadowCasterMaterial(mat.Name);
                }

                if (dstPass.Parent.ShadowReceiverMaterial == null)
                {
                    Material mat = this.creator.GetCustomShadowCasterMaterial(this.skinningType, weightCount - 1);
                    dstPass.Parent.SetShadowReceiverMaterial(mat.Name);
                }
            }
            return(true);
        }
Beispiel #9
0
        public override bool PreAddToRenderState(TargetRenderState targetRenderState, Graphics.Pass srcPass,
                                                 Graphics.Pass dstPass)
        {
            if (srcPass.LightingEnabled == false || srcPass.Parent.Parent.ReceiveShadows == false)
            {
                return(false);
            }

            foreach (var it in this.shadowTextureParamsList)
            {
                TextureUnitState curShadowTexture = dstPass.CreateTextureUnitState();

                //TODO
                //curShadowTexture.ContentType = TextureUnitState.ContentShadow;
                curShadowTexture.SetTextureAddressingMode(TextureAddressing.Border);
                curShadowTexture.TextureBorderColor = Core.ColorEx.White;
                it.TextureSamplerIndex = dstPass.TextureUnitStatesCount - 1;
            }

            return(true);
        }
        /// <summary>
        ///   build render state from the given pass that emulates the fixed function pipeline behavior
        /// </summary>
        /// <param name="sgPass"> The shader generator pass representation. Contains both source and destination pass </param>
        /// <param name="renderState"> The target render state that will hold the given pass FFP representation </param>
        public void BuildRenderState(ShaderGenerator.SGPass sgPass, TargetRenderState renderState)
        {
            renderState.Reset();

            //Build transformation sub state
            BuildFFPSubRenderState(-1, FFPTransform.FFPType, sgPass, renderState);

            //Build color sub state
            BuildFFPSubRenderState(-1, FFPTransform.FFPType, sgPass, renderState);

            //Build lighting sub state.
            BuildFFPSubRenderState(-1, FFPTransform.FFPType, sgPass, renderState);

            //Build texturing sub state
            BuildFFPSubRenderState(-1, FFPTransform.FFPType, sgPass, renderState);

            //Build fog sub state
            BuildFFPSubRenderState(-1, FFPTransform.FFPType, sgPass, renderState);

            //resolve color stage flags
            ResolveColorStageFlags(sgPass, renderState);
        }
Beispiel #11
0
        internal void AcquirePrograms(Graphics.Pass pass, TargetRenderState renderState)
        {
            //Create the CPU programs
            if (!renderState.CreateCpuPrograms())
            {
                throw new Core.AxiomException("Could not apply render state ");
            }

            ProgramSet programSet = renderState.ProgramSet;

            //Create the GPU programs
            if (!CreateGpuPrograms(programSet))
            {
                throw new Core.AxiomException("Could not create gpu program from render state ");
            }

            //bind the created gpu programs to the target pass
            pass.SetVertexProgram(programSet.GpuVertexProgram.Name);
            pass.SetFragmentProgram(programSet.GpuFragmentProgram.Name);

            //Bind uniform parameters to pass parameters
            BindUniformParameters(programSet.CpuVertexProgram, pass.VertexProgramParameters);
            BindUniformParameters(programSet.CpuFragmentProgram, pass.FragmentProgramParameters);
        }
Beispiel #12
0
 public virtual bool PreAddToRenderState(TargetRenderState targetRenderState, Graphics.Pass srcPass,
                                         Graphics.Pass dstPass)
 {
     return(true);
 }