Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        public override void FrameUpdate()
        {
            long currentTime = mWindTimer.Milliseconds;
            long elapsedTime = currentTime - mLastTime;

            mLastTime = currentTime;
            float elapsed = elapsedTime / 1000.0f;

            //Update the vertex shader parameters
            foreach (GrassLayer it in mLayerList)
            {
                GrassLayer layer = it;
                layer.UpdateShaders();

                GpuProgramParameters gparams = layer.Material.GetTechnique(0).GetPass(0).VertexProgramParameters;
                if (layer.IsAnimationEnabled)
                {
                    //Increment animation frame
                    layer.WaveCount += elapsed * (float)(layer.SwaySpeed * System.Math.PI);
                    if (layer.WaveCount > System.Math.PI * 2)
                    {
                        layer.WaveCount -= (float)System.Math.PI * 2;
                    }

                    //Set vertex shader parameters
                    gparams.SetNamedConstant("time", layer.WaveCount);
                    gparams.SetNamedConstant("frequency", layer.SwayDistribution);

                    Vector3 direction = mWindDir * layer.SwayLength;
                    gparams.SetNamedConstant("direction", new Vector4(direction.x, direction.y, direction.z, 0));
                }
            }
        }
Beispiel #2
0
        public UniformParameter(GpuProgramParameters.AutoConstantType autoConstantType, int autoConstantData, int size)
            : base(
                Parameter.AutoParameters[autoConstantType].Type, Parameter.AutoParameters[autoConstantType].Name,
                SemanticType.Unknown, -1, ContentType.Unknown, size)
        {
            AutoShaderParameter parameterDef = Parameter.AutoParameters[autoConstantType];

            _name = parameterDef.Name;
            if (autoConstantData != 0)
            {
                _name += autoConstantData.ToString();
            }
            _type     = parameterDef.Type;
            _semantic = SemanticType.Unknown;
            _index    = -1;
            _content  = Parameter.ContentType.Unknown;
            this.isAutoConstantInt   = true;
            this.isAutoConstantReal  = false;
            this.autoConstantType    = autoConstantType;
            this.autoConstantIntData = autoConstantData;
            this.variability         = (int)GpuProgramParameters.GpuParamVariability.Global;
            this._params             = null;
            this.physicalIndex       = -1;
            _size = size;
        }
Beispiel #3
0
        /// <summary>
        ///     Binds named parameters to fp30 programs.
        /// </summary>
        /// <param name="parms"></param>
        public override void BindProgramParameters(GpuProgramParameters parms, GpuProgramParameters.GpuParamVariability mask)
        {
            throw new NotImplementedException();

            /*
             *          if ( parms.HasFloatConstants )
             *          {
             *                  for ( int index = 0; index < parms.FloatConstantCount; index++ )
             *                  {
             *                          string name = parms.GetNameByIndex( index );
             *
             *                          if ( name != null )
             *                          {
             *                                  using (var entry = parms.GetFloatPointer( index ))
             *                              {
             *
             *                                  // send the params 4 at a time
             *                                  throw new AxiomException( "Update this!" );
             *                                  Gl.glProgramNamedParameter4fvNV( programId, name.Length, System.Text.Encoding.ASCII.GetBytes( name ),
             *                                                                   entry.Pointer ); // TAO 2.0
             *                                  //Gl.glProgramNamedParameter4fvNV( programId, name.Length, name, entry.val );
             *                              }
             *                          }
             *                  }
             *          }
             */
        }
Beispiel #4
0
        public UniformParameter(GpuProgramParameters.AutoConstantType autoConstantType, Real autoConstantData, int size,
                                GpuProgramParameters.GpuConstantType type)
            : base(
                Parameter.AutoParameters[autoConstantType].Type, Parameter.AutoParameters[autoConstantType].Name,
                SemanticType.Unknown, -1, ContentType.Unknown, size)
        {
            AutoShaderParameter parameterDef = Parameter.AutoParameters[autoConstantType];

            _name = parameterDef.Name;
            if (autoConstantData != 0.0)
            {
                _name += autoConstantData.ToString();
                //replace possible illegal point character in name
                _name = _name.Replace('.', '_');
            }
            _type     = type;
            _semantic = SemanticType.Unknown;
            _index    = -1;
            _content  = Parameter.ContentType.Unknown;
            this.isAutoConstantReal   = true;
            this.isAutoConstantInt    = false;
            this.autoConstantType     = autoConstantType;
            this.autoConstantRealData = autoConstantData;
            this.variability          = (int)GpuProgramParameters.GpuParamVariability.Global;
            this._params       = null;
            this.physicalIndex = -1;
            _size = size;
        }
Beispiel #5
0
        protected override void PopulateParameterNames(GpuProgramParameters parms)
        {
            var unused = ConstantDefinitions;             // SIDE EFFECT

            parms.NamedConstants = constantDefs;
            // Don't set logical / physical maps here, as we can't access parameters by logical index in GLHL.
        }
        protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
        {
            base.OnMaterialRender(passId, material, ref skipPass);

            if (passId == 700 || passId == 701)
            {
                bool horizontal = passId == 700;

                Vec2[] sampleOffsets = new Vec2[15];
                Vec4[] sampleWeights = new Vec4[15];

                // calculate gaussian texture offsets & weights
                Vec2i textureSize = Owner.DimensionsInPixels.Size;
                float texelSize   = 1.0f / (float)(horizontal ? textureSize.X : textureSize.Y);

                texelSize *= fuzziness;

                // central sample, no offset
                sampleOffsets[0] = Vec2.Zero;
                {
                    float distribution = GaussianDistribution(0, 0, 3);
                    sampleWeights[0] = new Vec4(distribution, distribution, distribution, 0);
                }

                // 'pre' samples
                for (int n = 1; n < 8; n++)
                {
                    float distribution = GaussianDistribution(n, 0, 3);
                    sampleWeights[n] = new Vec4(distribution, distribution, distribution, 1);

                    if (horizontal)
                    {
                        sampleOffsets[n] = new Vec2((float)n * texelSize, 0);
                    }
                    else
                    {
                        sampleOffsets[n] = new Vec2(0, (float)n * texelSize);
                    }
                }
                // 'post' samples
                for (int n = 8; n < 15; n++)
                {
                    sampleWeights[n] = sampleWeights[n - 7];
                    sampleOffsets[n] = -sampleOffsets[n - 7];
                }

                //convert to Vec4 array
                Vec4[] vec4Offsets = new Vec4[15];
                for (int n = 0; n < 15; n++)
                {
                    Vec2 offset = sampleOffsets[n];
                    vec4Offsets[n] = new Vec4(offset.X, offset.Y, 0, 0);
                }

                GpuProgramParameters parameters = material.GetBestTechnique().
                                                  Passes[0].FragmentProgramParameters;
                parameters.SetNamedConstant("sampleOffsets", vec4Offsets);
                parameters.SetNamedConstant("sampleWeights", sampleWeights);
            }
        }
        public void SetConstantMatrix4()
        {
            float[] expected = new[] { (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(),
                                       (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(),
                                       (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(),
                                       (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom() };

            float[] actual = new float[16];

            GpuProgramParameters parameters = new GpuProgramParameters();

            //var floatLogical = new GpuLogicalBufferStruct();
            //parameters._setLogicalIndexes( floatLogical, new GpuLogicalBufferStruct() );
            parameters.SetConstant(0, new Matrix4(expected[0], expected[1], expected[2], expected[3],
                                                  expected[4], expected[5], expected[6], expected[7],
                                                  expected[8], expected[9], expected[10], expected[11],
                                                  expected[12], expected[13], expected[14], expected[15]));

            GpuProgramParameters.FloatConstantEntry fcEntry;
            for (int i = 0; i < 4; i++)
            {
                fcEntry = parameters.GetFloatConstant(i);
                Assert.IsTrue(fcEntry.isSet);

                fcEntry.val.CopyTo(actual, i * 4);
            }

            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        /// <summary>
        ///     Predefined controller value for setting a single floating-
        ///     point value in a constant paramter of a vertex or fragment program.
        /// </summary>
        /// <remarks>
        ///     Any value is accepted, it is propagated into the 'x'
        ///     component of the constant register identified by the index. If you
        ///     need to use named parameters, retrieve the index from the param
        ///     object before setting this controller up.
        /// </remarks>
        /// <param name="parms"></param>
        /// <param name="index"></param>
        /// <param name="timeFactor"></param>
        /// <returns></returns>
        public Controller <Real> CreateGpuProgramTimerParam(GpuProgramParameters parms, int index, Real timeFactor)
        {
            IControllerValue <Real>    val  = new FloatGpuParamControllerValue(parms, index);
            IControllerFunction <Real> func = new MultipyControllerFunction(timeFactor, true);

            return(CreateController(val, func));
        }
        void SetProgramAutoConstants(GpuProgramParameters parameters, int lightCount)
        {
            parameters.SetNamedAutoConstant("worldMatrix",
                                            GpuProgramParameters.AutoConstantType.WorldMatrix);
            parameters.SetNamedAutoConstant("worldViewProjMatrix",
                                            GpuProgramParameters.AutoConstantType.WorldViewProjMatrix);
            parameters.SetNamedAutoConstant("cameraPosition",
                                            GpuProgramParameters.AutoConstantType.CameraPosition);
            parameters.SetNamedAutoConstant("farClipDistance",
                                            GpuProgramParameters.AutoConstantType.FarClipDistance);

            parameters.SetNamedAutoConstant("ambientLightColor",
                                            GpuProgramParameters.AutoConstantType.AmbientLightColor);

            if (lightCount != 0)
            {
                parameters.SetNamedAutoConstant("lightPositionArray",
                                                GpuProgramParameters.AutoConstantType.LightPositionArray, lightCount);
                parameters.SetNamedAutoConstant("lightPositionObjectSpaceArray",
                                                GpuProgramParameters.AutoConstantType.LightPositionObjectSpaceArray, lightCount);
                parameters.SetNamedAutoConstant("lightDirectionArray",
                                                GpuProgramParameters.AutoConstantType.LightDirectionArray, lightCount);
                parameters.SetNamedAutoConstant("lightDirectionObjectSpaceArray",
                                                GpuProgramParameters.AutoConstantType.LightDirectionObjectSpaceArray, lightCount);
                parameters.SetNamedAutoConstant("lightAttenuationArray",
                                                GpuProgramParameters.AutoConstantType.LightAttenuationArray, lightCount);
                parameters.SetNamedAutoConstant("lightDiffuseColorPowerScaledArray",
                                                GpuProgramParameters.AutoConstantType.LightDiffuseColorPowerScaledArray, lightCount);
                parameters.SetNamedAutoConstant("spotLightParamsArray",
                                                GpuProgramParameters.AutoConstantType.SpotLightParamsArray, lightCount);
            }
        }
Beispiel #10
0
        public override void UpdateGpuProgramsParams(IRenderable rend, Pass pass, AutoParamDataSource source,
                                                     Core.Collections.LightList lightList)
        {
            if (this.isTableDataUpdated == false)
            {
                this.isTableDataUpdated = true;
                for (int j = 0; j < TextureAtlasSampler.MaxTextures; j++)
                {
                    if (this.isAtlasTextureUnits[j] == true)
                    {
                        //Update the information of the size of the atlas textures
                        //TODO: Replace -1, -1 with actual dimensions
                        var texSizeInt = new Math.Tuple <int, int>(-1, -1);
                        // = pass.GetTextureUnitState(j).Dimensions;
                        var texSize = new Vector2(texSizeInt.First, texSizeInt.Second);
                        this.psTextureSizes[j].SetGpuParameter(texSize);

                        //Update the information of which texture exists where in the atlas
                        GpuProgramParameters vsGpuParams = pass.VertexProgramParameters;
                        var buffer = new List <float>(this.atlasTableDatas[j].Count * 4);
                        for (int i = 0; i < this.atlasTableDatas[j].Count; i++)
                        {
                            buffer[i * 4]     = this.atlasTableDatas[j][i].posU;
                            buffer[i * 4 + 1] = this.atlasTableDatas[j][i].posV;
                            buffer[i * 4 + 2] =
                                (float)Axiom.Math.Utility.Log2((int)this.atlasTableDatas[j][i].width * (int)texSize.x);
                            buffer[i * 4 + 3] =
                                (float)Axiom.Math.Utility.Log2((int)this.atlasTableDatas[j][i].height * (int)texSize.y);
                        }
                        vsGpuParams.SetNamedConstant(this.vsTextureTable[j].Name, buffer.ToArray(),
                                                     this.atlasTableDatas[j].Count);
                    }
                }
            }
        }
Beispiel #11
0
        public override void BindProgramParameters(GpuProgramParameters parms, GpuProgramParameters.GpuParamVariability mask)
        {
            var type = programType;

            // only supports float constants
            var floatStruct = parms.FloatLogicalBufferStruct;

            foreach (var i in floatStruct.Map)
            {
                if ((i.Value.Variability & mask) != 0)
                {
                    var logicalIndex = i.Key;
                    var pFloat       = parms.GetFloatConstantList();
                    var ptr          = i.Value.PhysicalIndex;
                    {
                        for (var j = 0; j < i.Value.CurrentSize; j += 4)
                        {
                            var x = pFloat[ptr + j];
                            var y = pFloat[ptr + j + 1];
                            var z = pFloat[ptr + j + 2];
                            var w = pFloat[ptr + j + 3];
                            Gl.glProgramLocalParameter4fARB(type, logicalIndex, x, y, z, w);
                            ++logicalIndex;
                        }
                    }
                }
            }
        }
        /// <summary>
        ///		Updates program object uniforms using data from GpuProgramParameters.
        ///		normally called by GLSLGpuProgram.BindParameters() just before rendering occurs.
        /// </summary>
        /// <param name="parameters">GPU Parameters to use to update the uniforms params.</param>
        public void UpdateUniforms(GpuProgramParameters parameters)
        {
            for(int i = 0; i < uniformReferences.Count; i++) {
                UniformReference uniformRef = (UniformReference)uniformReferences[i];

                GpuProgramParameters.FloatConstantEntry currentFloatEntry = null;
                GpuProgramParameters.IntConstantEntry currentIntEntry = null;

                if(uniformRef.isFloat) {
                    currentFloatEntry = parameters.GetNamedFloatConstant(uniformRef.name);

                    if(currentFloatEntry != null) {
                        if(currentFloatEntry.isSet) {
                            switch(uniformRef.elementCount) {
                                case 1:
                                    Gl.glUniform1fvARB(uniformRef.location, 1, currentFloatEntry.val);
                                    break;

                                case 2:
                                    Gl.glUniform2fvARB(uniformRef.location, 1, currentFloatEntry.val);
                                    break;

                                case 3:
                                    Gl.glUniform3fvARB(uniformRef.location, 1, currentFloatEntry.val);
                                    break;

                                case 4:
                                    Gl.glUniform4fvARB(uniformRef.location, 1, currentFloatEntry.val);
                                    break;
                            } // end switch
                        }
                    }
                }
                else {
                    currentIntEntry = parameters.GetNamedIntConstant(uniformRef.name);

                    if(currentIntEntry != null) {
                        if(currentIntEntry.isSet) {
                            switch(uniformRef.elementCount) {
                                case 1:
                                    Gl.glUniform1ivARB(uniformRef.location, 1, currentIntEntry.val);
                                    break;

                                case 2:
                                    Gl.glUniform2ivARB(uniformRef.location, 1, currentIntEntry.val);
                                    break;

                                case 3:
                                    Gl.glUniform3ivARB(uniformRef.location, 1, currentIntEntry.val);
                                    break;

                                case 4:
                                    Gl.glUniform4ivARB(uniformRef.location, 1, currentIntEntry.val);
                                    break;
                            } // end switch
                        }
                    }
                }
            }
        }
        private void SetProgramAutoConstants(GpuProgramParameters parameters, int lightCount)
        {
            parameters.SetNamedAutoConstant("worldMatrix",
                GpuProgramParameters.AutoConstantType.WorldMatrix);
            parameters.SetNamedAutoConstant("worldViewProjMatrix",
                GpuProgramParameters.AutoConstantType.WorldViewProjMatrix);
            parameters.SetNamedAutoConstant("cameraPosition",
                GpuProgramParameters.AutoConstantType.CameraPosition);
            parameters.SetNamedAutoConstant("farClipDistance",
                GpuProgramParameters.AutoConstantType.FarClipDistance);

            parameters.SetNamedAutoConstant("ambientLightColor",
                GpuProgramParameters.AutoConstantType.AmbientLightColor);

            if (lightCount != 0)
            {
                parameters.SetNamedAutoConstant("lightPositionArray",
                    GpuProgramParameters.AutoConstantType.LightPositionArray, lightCount);
                parameters.SetNamedAutoConstant("lightPositionObjectSpaceArray",
                    GpuProgramParameters.AutoConstantType.LightPositionObjectSpaceArray, lightCount);
                parameters.SetNamedAutoConstant("lightDirectionArray",
                    GpuProgramParameters.AutoConstantType.LightDirectionArray, lightCount);
                parameters.SetNamedAutoConstant("lightDirectionObjectSpaceArray",
                    GpuProgramParameters.AutoConstantType.LightDirectionObjectSpaceArray, lightCount);
                parameters.SetNamedAutoConstant("lightAttenuationArray",
                    GpuProgramParameters.AutoConstantType.LightAttenuationArray, lightCount);
                parameters.SetNamedAutoConstant("lightDiffuseColorPowerScaledArray",
                    GpuProgramParameters.AutoConstantType.LightDiffuseColorPowerScaledArray, lightCount);
                parameters.SetNamedAutoConstant("spotLightParamsArray",
                    GpuProgramParameters.AutoConstantType.SpotLightParamsArray, lightCount);
            }
        }
        protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
        {
            base.OnMaterialRender(passId, material, ref skipPass);

            //update texture name
            if (passId == 100)
            {
                TextureUnitState textureUnit = material.Techniques[0].Passes[0].TextureUnitStates[1];

                //we can't change texture by means call SetTextureName() for compositor materials. use _Internal_SetTexture
                Texture texture = null;
                if (!string.IsNullOrEmpty(TextureName))
                {
                    texture = TextureManager.Instance.Load(TextureName, Texture.Type.Type2D);
                }
                if (texture == null)
                {
                    texture = TextureManager.Instance.Load("Base\\FullScreenEffects\\ColorCorrectionLUT\\Textures\\NoEffect.png");
                }
                textureUnit._Internal_SetTexture(texture);
                //if( textureUnit.TextureName != TextureName )
                //   textureUnit.SetTextureName( TextureName );

                GpuProgramParameters parameters = material.Techniques[0].Passes[0].FragmentProgramParameters;
                parameters.SetNamedConstant("multiply", multiply);
                parameters.SetNamedConstant("add", add);
            }
        }
Beispiel #15
0
        public override void BindProgramPassIterationParameters(GpuProgramParameters parms)
        {
            // activate the link program object
            var linkProgram = GLSLLinkProgramManager.Instance.ActiveLinkProgram;

            // pass on parameters from params to program object uniforms
            linkProgram.UpdatePassIterationUniforms(parms);
        }
Beispiel #16
0
        /// <summary>
        ///     Overriden to return parms set to transpose matrices.
        /// </summary>
        /// <returns></returns>
        public override GpuProgramParameters CreateParameters()
        {
            GpuProgramParameters parms = base.CreateParameters();

            parms.TransposeMatrices = true;

            return(parms);
        }
Beispiel #17
0
        private void BindUniformParameters(Program cpuProgram, GpuProgramParameters passParams)
        {
            var progParams = cpuProgram.Parameters;

            foreach (var item in progParams)
            {
                item.Bind(passParams);
            }
        }
        protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
        {
            base.OnMaterialRender(passId, material, ref skipPass);

            if (passId == 555)
            {
                GpuProgramParameters parameters = material.Techniques[0].Passes[0].FragmentProgramParameters;
                parameters.SetNamedConstant("intensity", intensity);
            }
        }
        public GpuProgramParameters getTargetParams()
        {
            global::System.IntPtr cPtr = OgrePINVOKE.GpuSharedParametersUsage_getTargetParams(swigCPtr);
            GpuProgramParameters  ret  = (cPtr == global::System.IntPtr.Zero) ? null : new GpuProgramParameters(cPtr, false);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #20
0
 public UniformParameter(GpuProgramParameters.GpuConstantType type, string name, SemanticType semantic,
                         int index, ContentType content, int variability, int size)
     : base(type, name, semantic, index, content, size)
 {
     this.isAutoConstantInt   = false;
     this.isAutoConstantReal  = false;
     this.autoConstantIntData = 0;
     this.variability         = variability;
     this._params             = null;
     this.physicalIndex       = -1;
 }
Beispiel #21
0
        UpdateGpuProgramsParams(IRenderable rend, Pass pass, AutoParamDataSource source,
                                Core.Collections.LightList lightList)
        {
            if (this.reflectionPowerChanged)
            {
                GpuProgramParameters fsParams = pass.FragmentProgramParameters;

                this.reflectionPower.SetGpuParameter(this.reflectionPowerValue);
                this.reflectionPowerChanged = false;
            }
        }
Beispiel #22
0
        protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
        {
            base.OnMaterialRender(passId, material, ref skipPass);

            if (passId == 333) //Incin framerate?
            {
                Vec4 multiplier = new Vec4(Red, Green, Blue, alpha);

                GpuProgramParameters parameters = material.Techniques[0].Passes[0].FragmentProgramParameters;
                parameters.SetNamedConstant("multiplier", multiplier);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="visibleDist"></param>
        /// <param name="invisibleDist"></param>
        /// <returns></returns>
        private Material GetFadeMaterial(float visibleDist, float invisibleDist)
        {
            string materialSignature = string.Empty;

            materialSignature += mEntityName + "|";
            materialSignature += visibleDist + "|";
            materialSignature += invisibleDist + "|";
            materialSignature += mMaterial.GetTechnique(0).GetPass(0).GetTextureUnitState(0).TextureScrollU + "|";
            materialSignature += mMaterial.GetTechnique(0).GetPass(0).GetTextureUnitState(0).TextureScrollV + "|";

            Material fadeMaterial = null;

            if (!mFadedMaterialMap.TryGetValue(materialSignature, out fadeMaterial))
            {
                //clone the material
                fadeMaterial = mMaterial.Clone(GetUniqueID("ImpostorFade"));

                //And apply the fade shader
                for (int t = 0; t < fadeMaterial.TechniqueCount; t++)
                {
                    Technique tech = fadeMaterial.GetTechnique(t);
                    for (int p = 0; p < tech.PassCount; p++)
                    {
                        Pass pass = tech.GetPass(p);
                        //Setup vertex program
                        pass.SetVertexProgram("SpriteFade_vp");
                        GpuProgramParameters gparams = pass.VertexProgramParameters;
                        gparams.SetNamedAutoConstant("worldViewProj", GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0);
                        gparams.SetNamedAutoConstant("uScroll", GpuProgramParameters.AutoConstantType.Custom, 0);
                        gparams.SetNamedAutoConstant("vScroll", GpuProgramParameters.AutoConstantType.Custom, 0);
                        gparams.SetNamedAutoConstant("preRotatedQuad[0]", GpuProgramParameters.AutoConstantType.Custom, 0);
                        gparams.SetNamedAutoConstant("preRotatedQuad[1]", GpuProgramParameters.AutoConstantType.Custom, 0);
                        gparams.SetNamedAutoConstant("preRotatedQuad[2]", GpuProgramParameters.AutoConstantType.Custom, 0);
                        gparams.SetNamedAutoConstant("preRotatedQuad[3]", GpuProgramParameters.AutoConstantType.Custom, 0);

                        gparams.SetNamedAutoConstant("camPos", GpuProgramParameters.AutoConstantType.CameraPositionObjectSpace, 0);
                        gparams.SetNamedAutoConstant("fadeGap", GpuProgramParameters.AutoConstantType.Custom, 0);
                        gparams.SetNamedAutoConstant("invisibleDist", GpuProgramParameters.AutoConstantType.Custom, 0);

                        //Set fade ranges
                        gparams.SetNamedConstant("invisibleDist", invisibleDist);
                        gparams.SetNamedConstant("fadeGap", invisibleDist - visibleDist);

                        pass.SetSceneBlending(SceneBlendType.TransparentAlpha);
                    }
                }

                //Add it to the list so it can be reused later
                mFadedMaterialMap.Add(materialSignature, fadeMaterial);
            }

            return(fadeMaterial);
        }
Beispiel #24
0
        protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
        {
            base.OnMaterialRender(passId, material, ref skipPass);

            if (passId == 666)
            {
                GpuProgramParameters parameters = material.Techniques[0].
                                                  Passes[0].FragmentProgramParameters;
                if (parameters != null)
                {
                    parameters.SetNamedConstant("blur", Blur);
                }
            }
        }
Beispiel #25
0
        public void Bind(GpuProgramParameters gpuParams)
        {
            if (gpuParams != null)
            {
                Axiom.Graphics.GpuProgramParameters.GpuConstantDefinition def =
                    gpuParams.FindNamedConstantDefinition(_name);

                if (def != null)
                {
                    this._params       = gpuParams;
                    this.physicalIndex = def.PhysicalIndex;
                }
            }
        }
Beispiel #26
0
        public override GpuProgramParameters CreateParameters()
        {
            GpuProgramParameters parms = base.CreateParameters();

            if (sdkMulCompat)
            {
                parms.TransposeMatrices = !columnMajorMatrices;
            }
            else
            {
                parms.TransposeMatrices = columnMajorMatrices;
            }
            return(parms);
        }
Beispiel #27
0
        /// <summary>
        ///     Dervices parameter names from the constant table.
        /// </summary>
        /// <param name="parms"></param>
        protected override void PopulateParameterNames(GpuProgramParameters parms)
        {
            Debug.Assert(constantTable != null);

            D3D.ConstantTableDescription desc = constantTable.Description;

            // iterate over the constants
            for (int i = 0; i < desc.Constants; i++)
            {
                // Recursively descend through the structure levels
                // Since D3D9 has no nice 'leaf' method like Cg (sigh)
                ProcessParamElement(null, "", i, parms);
            }
        }
Beispiel #28
0
        protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
        {
            base.OnMaterialRender(passId, material, ref skipPass);

            if (passId == 123)
            {
                GpuProgramParameters parameters = material.Techniques[0].Passes[0].FragmentProgramParameters;
                if (parameters != null)
                {
                    parameters.SetNamedConstant("center", new Vec4(center.X, center.Y, 0, 0));
                    parameters.SetNamedConstant("blurFactor", blurFactor);
                }
            }
        }
        protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
        {
            base.OnMaterialRender(passId, material, ref skipPass);

            if (passId == 100)
            {
                GpuProgramParameters parameters = material.Techniques[0].Passes[0].FragmentProgramParameters;
                if (parameters != null)
                {
                    parameters.SetNamedAutoConstant("viewportSize",
                                                    GpuProgramParameters.AutoConstantType.ViewportSize);
                }
            }
        }
        public void SetConstantFloat()
        {
            float[] expected = new[] { (float)Utility.SymmetricRandom(), 0f, 0f, 0f };
            float   actual;

            GpuProgramParameters parameters = new GpuProgramParameters();

            //var floatLogical = new GpuLogicalBufferStruct();
            //parameters._setLogicalIndexes( floatLogical, new GpuLogicalBufferStruct() );
            parameters.SetConstant(0, expected[0]);

            Assert.IsTrue(parameters.GetFloatConstant(0) != 0);
            actual = parameters.GetFloatConstant(0);
            Assert.AreEqual(expected[0], actual);
        }
        public void SetConstantVector4()
        {
            float[] expected = new[] { (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom() };
            float[] actual;

            GpuProgramParameters parameters = new GpuProgramParameters();

            //var floatLogical = new GpuLogicalBufferStruct();
            //parameters._setLogicalIndexes( floatLogical, new GpuLogicalBufferStruct() );
            parameters.SetConstant(0, new Vector4(expected[0], expected[1], expected[2], expected[3]));

            Assert.IsTrue(parameters.GetFloatConstant(0).isSet);
            actual = parameters.GetFloatConstant(0).val;
            Assert.AreEqual(expected, actual);
        }
        private void SetProgramAutoConstants(GpuProgramParameters parameters)
        {
            parameters.SetNamedAutoConstant("worldMatrix",
                GpuProgramParameters.AutoConstantType.WorldMatrix);
            parameters.SetNamedAutoConstant("viewProjMatrix",
                GpuProgramParameters.AutoConstantType.ViewProjMatrix);
            parameters.SetNamedAutoConstant("texelOffsets",
                GpuProgramParameters.AutoConstantType.TexelOffsets);
            parameters.SetNamedAutoConstant("cameraPosition",
                GpuProgramParameters.AutoConstantType.CameraPosition);
            parameters.SetNamedAutoConstant("farClipDistance",
                GpuProgramParameters.AutoConstantType.FarClipDistance);

            parameters.SetNamedAutoConstant("shadowDirectionalLightBias",
                GpuProgramParameters.AutoConstantType.ShadowDirectionalLightBias);
            parameters.SetNamedAutoConstant("shadowSpotLightBias",
                GpuProgramParameters.AutoConstantType.ShadowSpotLightBias);
            parameters.SetNamedAutoConstant("shadowPointLightBias",
                GpuProgramParameters.AutoConstantType.ShadowPointLightBias);

            parameters.SetNamedAutoConstant("instancing",
                GpuProgramParameters.AutoConstantType.Instancing);
        }
        protected virtual void OnSetProgramAutoConstants(
            GpuProgramParameters parameters, int lightCount)
        {
            parameters.SetNamedAutoConstant( "worldMatrix",
                GpuProgramParameters.AutoConstantType.WorldMatrix );
            parameters.SetNamedAutoConstant( "worldViewMatrix",
                GpuProgramParameters.AutoConstantType.WorldViewMatrix );
            parameters.SetNamedAutoConstant( "worldViewProjMatrix",
                GpuProgramParameters.AutoConstantType.WorldViewProjMatrix );
            parameters.SetNamedAutoConstant( "viewProjMatrix",
                GpuProgramParameters.AutoConstantType.ViewProjMatrix );
            parameters.SetNamedAutoConstant( "cameraPositionObjectSpace",
                GpuProgramParameters.AutoConstantType.CameraPositionObjectSpace );
            parameters.SetNamedAutoConstant( "cameraPosition",
                GpuProgramParameters.AutoConstantType.CameraPosition );
            parameters.SetNamedAutoConstant( "farClipDistance",
                GpuProgramParameters.AutoConstantType.FarClipDistance );

            parameters.SetNamedAutoConstant( "texelOffsets",
                GpuProgramParameters.AutoConstantType.TexelOffsets );
            parameters.SetNamedAutoConstant( "alphaRejectValue",
                GpuProgramParameters.AutoConstantType.AlphaRejectValue );

            parameters.SetNamedAutoConstant( "disableFetch4ForBrokenDrivers",
                GpuProgramParameters.AutoConstantType.DisableFetch4ForBrokenDrivers );

            //Light
            parameters.SetNamedAutoConstant( "ambientLightColor",
                GpuProgramParameters.AutoConstantType.AmbientLightColor );

            if( lightCount != 0 )
            {
                parameters.SetNamedAutoConstant( "textureViewProjMatrix0",
                    GpuProgramParameters.AutoConstantType.TextureViewProjMatrix, 0 );
                parameters.SetNamedAutoConstant( "textureViewProjMatrix1",
                    GpuProgramParameters.AutoConstantType.TextureViewProjMatrix, 1 );
                parameters.SetNamedAutoConstant( "textureViewProjMatrix2",
                    GpuProgramParameters.AutoConstantType.TextureViewProjMatrix, 2 );
                parameters.SetNamedAutoConstant( "lightShadowFarClipDistance",
                    GpuProgramParameters.AutoConstantType.LightShadowFarClipDistance, 0 );
                parameters.SetNamedAutoConstant( "shadowFarDistance",
                    GpuProgramParameters.AutoConstantType.ShadowFarDistance );
                parameters.SetNamedAutoConstant( "shadowColorIntensity",
                    GpuProgramParameters.AutoConstantType.ShadowColorIntensity );
                parameters.SetNamedAutoConstant( "shadowTextureSizes",
                    GpuProgramParameters.AutoConstantType.ShadowTextureSizes );
                parameters.SetNamedAutoConstant( "shadowDirectionalLightSplitDistances",
                    GpuProgramParameters.AutoConstantType.ShadowDirectionalLightSplitDistances );
                parameters.SetNamedAutoConstant( "lightPositionArray",
                    GpuProgramParameters.AutoConstantType.LightPositionArray, lightCount );
                parameters.SetNamedAutoConstant( "lightPositionObjectSpaceArray",
                    GpuProgramParameters.AutoConstantType.LightPositionObjectSpaceArray, lightCount );
                parameters.SetNamedAutoConstant( "lightDirectionArray",
                    GpuProgramParameters.AutoConstantType.LightDirectionArray, lightCount );
                parameters.SetNamedAutoConstant( "lightDirectionObjectSpaceArray",
                    GpuProgramParameters.AutoConstantType.LightDirectionObjectSpaceArray, lightCount );
                parameters.SetNamedAutoConstant( "lightAttenuationArray",
                    GpuProgramParameters.AutoConstantType.LightAttenuationArray, lightCount );
                parameters.SetNamedAutoConstant( "lightDiffuseColorPowerScaledArray",
                    GpuProgramParameters.AutoConstantType.LightDiffuseColorPowerScaledArray, lightCount );
                parameters.SetNamedAutoConstant( "lightSpecularColorPowerScaledArray",
                    GpuProgramParameters.AutoConstantType.LightSpecularColorPowerScaledArray, lightCount );
                parameters.SetNamedAutoConstant( "spotLightParamsArray",
                    GpuProgramParameters.AutoConstantType.SpotLightParamsArray, lightCount );
                parameters.SetNamedAutoConstant( "lightCastShadowsArray",
                    GpuProgramParameters.AutoConstantType.LightCastShadowsArray, lightCount );
            }

            //Fog
            parameters.SetNamedAutoConstant( "fogParams",
                GpuProgramParameters.AutoConstantType.FogParams );
            parameters.SetNamedAutoConstant( "fogColor",
                GpuProgramParameters.AutoConstantType.FogColor );

            //Time
            //1 hour interval. for better precision
            parameters.SetNamedAutoConstantFloat( "time",
                GpuProgramParameters.AutoConstantType.Time0X, 3600.0f );

            //lightmap
            parameters.SetNamedAutoConstant( "lightmapUVTransform",
                GpuProgramParameters.AutoConstantType.LightmapUVTransform );

            //clip planes
            for( int n = 0; n < 6; n++ )
            {
                parameters.SetNamedAutoConstant( "clipPlane" + n.ToString(),
                    GpuProgramParameters.AutoConstantType.ClipPlane, n );
            }

            parameters.SetNamedAutoConstant( "instancing",
                GpuProgramParameters.AutoConstantType.Instancing );
        }
Beispiel #34
0
 public override void _updateCustomGpuParameter(GpuProgramParameters.AutoConstantEntry_NativePtr constantEntry, GpuProgramParameters @params)
 {
     base._updateCustomGpuParameter(constantEntry, @params);
     @params.SetNamedConstant(_scaleFactorName, ScaleFactor);
     @params.SetNamedConstant(_fineBlockOriginName, FineBlockOrigin);
 }
Beispiel #35
0
        void SetProgramAutoConstants_ShadowCaster_Vertex( GpuProgramParameters parameters )
        {
            parameters.SetNamedAutoConstant( "worldMatrix",
                GpuProgramParameters.AutoConstantType.WorldMatrix );
            parameters.SetNamedAutoConstant( "viewProjMatrix",
                GpuProgramParameters.AutoConstantType.ViewProjMatrix );
            parameters.SetNamedAutoConstant( "cameraPosition",
                GpuProgramParameters.AutoConstantType.CameraPosition );
            parameters.SetNamedAutoConstant( "texelOffsets",
                GpuProgramParameters.AutoConstantType.TexelOffsets );

            if( RenderSystem.Instance.HasShaderModel3() &&
                RenderSystem.Instance.Capabilities.HardwareInstancing )
            {
                parameters.SetNamedAutoConstant( "instancing", GpuProgramParameters.AutoConstantType.Instancing );
            }

            //1 hour interval for better precision.
            parameters.SetNamedAutoConstantFloat( "time",
                GpuProgramParameters.AutoConstantType.Time0X, 3600.0f );
        }
Beispiel #36
0
        void SetProgramAutoConstants_ShadowCaster_Fragment( GpuProgramParameters parameters )
        {
            parameters.SetNamedAutoConstant( "farClipDistance",
                GpuProgramParameters.AutoConstantType.FarClipDistance );
            parameters.SetNamedAutoConstant( "shadowDirectionalLightBias",
                GpuProgramParameters.AutoConstantType.ShadowDirectionalLightBias );
            parameters.SetNamedAutoConstant( "shadowSpotLightBias",
                GpuProgramParameters.AutoConstantType.ShadowSpotLightBias );
            parameters.SetNamedAutoConstant( "shadowPointLightBias",
                GpuProgramParameters.AutoConstantType.ShadowPointLightBias );

            parameters.SetNamedAutoConstant( "alphaRejectValue",
                GpuProgramParameters.AutoConstantType.AlphaRejectValue );

            //1 hour interval for better precision.
            parameters.SetNamedAutoConstantFloat( "time",
                GpuProgramParameters.AutoConstantType.Time0X, 3600.0f );
        }
Beispiel #37
0
        static void SetProgramAutoConstants( GpuProgramParameters parameters )
        {
            //Matrix
            parameters.SetNamedAutoConstant( "worldViewProjMatrix",
                GpuProgramParameters.AutoConstantType.WorldViewProjMatrix );
            parameters.SetNamedAutoConstant( "worldViewMatrix",
                GpuProgramParameters.AutoConstantType.WorldViewMatrix );
            parameters.SetNamedAutoConstant( "cameraPositionObjectSpace",
                GpuProgramParameters.AutoConstantType.CameraPositionObjectSpace );

            //Fog
            parameters.SetNamedAutoConstant( "fogParams",
                GpuProgramParameters.AutoConstantType.FogParams );
            parameters.SetNamedAutoConstant( "fogColor",
                GpuProgramParameters.AutoConstantType.FogColor );

            //Time
            //parameters.SetNamedAutoConstantFloat( "timeValue",
            //   GpuProgramParameters.AutoConstantType.Time01, 20.0f );
            parameters.SetNamedAutoConstantFloat( "time0X",
                GpuProgramParameters.AutoConstantType.Time0X, 1000.0f );

            parameters.SetNamedAutoConstant( "renderTargetFlipping",
                GpuProgramParameters.AutoConstantType.RenderTargetFlipping );
        }
Beispiel #38
0
        protected virtual void OnSetProgramAutoConstants( GpuProgramParameters parameters, int lightCount,
			GpuProgramType programType, bool shadowCasterPass )
        {
            if( shadowCasterPass )
            {
                if( programType == GpuProgramType.Vertex )
                    SetProgramAutoConstants_ShadowCaster_Vertex( parameters );
                else
                    SetProgramAutoConstants_ShadowCaster_Fragment( parameters );
            }
            else
            {
                if( programType == GpuProgramType.Vertex )
                    SetProgramAutoConstants_Main_Vertex( parameters, lightCount );
                else
                    SetProgramAutoConstants_Main_Fragment( parameters, lightCount );
            }
        }
Beispiel #39
0
        void SetProgramAutoConstants_Main_Fragment( GpuProgramParameters parameters, int lightCount )
        {
            bool shadowMap = SceneManager.Instance.IsShadowTechniqueShadowmapBased() && ReceiveShadows &&
                lightCount != 0;

            parameters.SetNamedAutoConstant( "worldMatrix", GpuProgramParameters.AutoConstantType.WorldMatrix );
            parameters.SetNamedAutoConstant( "cameraPosition", GpuProgramParameters.AutoConstantType.CameraPosition );

            parameters.SetNamedAutoConstant( "farClipDistance",
                GpuProgramParameters.AutoConstantType.FarClipDistance );

            if( shadowMap )
            {
                parameters.SetNamedAutoConstant( "drawShadowDebugging",
                    GpuProgramParameters.AutoConstantType.DrawShadowDebugging );
            }

            //viewportSize
            if( SoftParticles )
            {
                parameters.SetNamedAutoConstant( "viewportSize",
                    GpuProgramParameters.AutoConstantType.ViewportSize );
            }

            //Light
            parameters.SetNamedAutoConstant( "ambientLightColor",
                GpuProgramParameters.AutoConstantType.AmbientLightColor );

            if( lightCount != 0 )
            {
                if( shadowMap )
                {
                    parameters.SetNamedAutoConstant( "lightShadowFarClipDistance",
                        GpuProgramParameters.AutoConstantType.LightShadowFarClipDistance, 0 );
                    parameters.SetNamedAutoConstant( "shadowFarDistance",
                        GpuProgramParameters.AutoConstantType.ShadowFarDistance );
                    parameters.SetNamedAutoConstant( "shadowColorIntensity",
                        GpuProgramParameters.AutoConstantType.ShadowColorIntensity );
                    parameters.SetNamedAutoConstant( "shadowTextureSizes",
                        GpuProgramParameters.AutoConstantType.ShadowTextureSizes );
                    if( SceneManager.Instance.IsShadowTechniquePSSM() )
                    {
                        parameters.SetNamedAutoConstant( "shadowDirectionalLightSplitDistances",
                            GpuProgramParameters.AutoConstantType.ShadowDirectionalLightSplitDistances );
                    }
                }

                parameters.SetNamedAutoConstant( "lightPositionArray",
                    GpuProgramParameters.AutoConstantType.LightPositionArray, lightCount );
                parameters.SetNamedAutoConstant( "lightDirectionArray",
                    GpuProgramParameters.AutoConstantType.LightDirectionArray, lightCount );
                parameters.SetNamedAutoConstant( "lightAttenuationArray",
                    GpuProgramParameters.AutoConstantType.LightAttenuationArray, lightCount );
                parameters.SetNamedAutoConstant( "lightDiffuseColorPowerScaledArray",
                    GpuProgramParameters.AutoConstantType.LightDiffuseColorPowerScaledArray, lightCount );
                parameters.SetNamedAutoConstant( "lightSpecularColorPowerScaledArray",
                    GpuProgramParameters.AutoConstantType.LightSpecularColorPowerScaledArray, lightCount );
                parameters.SetNamedAutoConstant( "spotLightParamsArray",
                    GpuProgramParameters.AutoConstantType.SpotLightParamsArray, lightCount );
                parameters.SetNamedAutoConstant( "lightCastShadowsArray",
                    GpuProgramParameters.AutoConstantType.LightCastShadowsArray, lightCount );
                parameters.SetNamedAutoConstant( "lightCustomShaderParameterArray",
                    GpuProgramParameters.AutoConstantType.LightCustomShaderParameterArray, lightCount );
            }

            //Fog
            if( allowFog && SceneManager.Instance.GetFogMode() != FogMode.None )
            {
                parameters.SetNamedAutoConstant( "fogParams",
                    GpuProgramParameters.AutoConstantType.FogParams );
                parameters.SetNamedAutoConstant( "fogColor",
                    GpuProgramParameters.AutoConstantType.FogColor );
            }

            //lightmap
            if( LightmapTexCoordIndex != -1 )
            {
                parameters.SetNamedAutoConstant( "lightmapUVTransform",
                    GpuProgramParameters.AutoConstantType.LightmapUVTransform );
            }

            //clip planes
            if( RenderSystem.Instance.IsOpenGL() )
            {
                for( int n = 0; n < 6; n++ )
                {
                    parameters.SetNamedAutoConstant( "clipPlane" + n.ToString(),
                        GpuProgramParameters.AutoConstantType.ClipPlane, n );
                }
            }

            if( RenderSystem.Instance.IsOpenGLES() )
            {
                parameters.SetNamedAutoConstant( "alphaRejectValue",
                    GpuProgramParameters.AutoConstantType.AlphaRejectValue );
            }

            //1 hour interval for better precision.
            parameters.SetNamedAutoConstantFloat( "time",
                GpuProgramParameters.AutoConstantType.Time0X, 3600.0f );
        }
Beispiel #40
0
        void SetProgramAutoConstants_Main_Vertex( GpuProgramParameters parameters, int lightCount )
        {
            bool shadowMap = SceneManager.Instance.IsShadowTechniqueShadowmapBased() && ReceiveShadows &&
                lightCount != 0;

            parameters.SetNamedAutoConstant( "worldMatrix",
                GpuProgramParameters.AutoConstantType.WorldMatrix );
            parameters.SetNamedAutoConstant( "viewProjMatrix",
                GpuProgramParameters.AutoConstantType.ViewProjMatrix );
            parameters.SetNamedAutoConstant( "cameraPositionObjectSpace",
                GpuProgramParameters.AutoConstantType.CameraPositionObjectSpace );
            parameters.SetNamedAutoConstant( "cameraPosition",
                GpuProgramParameters.AutoConstantType.CameraPosition );

            if( lightCount != 0 )
            {
                if( shadowMap )
                {
                    parameters.SetNamedAutoConstant( "textureViewProjMatrix0",
                    GpuProgramParameters.AutoConstantType.TextureViewProjMatrix, 0 );
                    parameters.SetNamedAutoConstant( "textureViewProjMatrix1",
                        GpuProgramParameters.AutoConstantType.TextureViewProjMatrix, 1 );
                    parameters.SetNamedAutoConstant( "textureViewProjMatrix2",
                        GpuProgramParameters.AutoConstantType.TextureViewProjMatrix, 2 );
                    parameters.SetNamedAutoConstant( "shadowFarDistance",
                        GpuProgramParameters.AutoConstantType.ShadowFarDistance );
                    parameters.SetNamedAutoConstant( "shadowTextureSizes",
                        GpuProgramParameters.AutoConstantType.ShadowTextureSizes );
                    if( SceneManager.Instance.IsShadowTechniquePSSM() )
                    {
                        parameters.SetNamedAutoConstant( "shadowDirectionalLightSplitDistances",
                            GpuProgramParameters.AutoConstantType.ShadowDirectionalLightSplitDistances );
                    }
                }

                parameters.SetNamedAutoConstant( "lightPositionArray",
                    GpuProgramParameters.AutoConstantType.LightPositionArray, lightCount );
                parameters.SetNamedAutoConstant( "lightPositionObjectSpaceArray",
                    GpuProgramParameters.AutoConstantType.LightPositionObjectSpaceArray, lightCount );
                parameters.SetNamedAutoConstant( "lightDirectionArray",
                    GpuProgramParameters.AutoConstantType.LightDirectionArray, lightCount );
                parameters.SetNamedAutoConstant( "lightAttenuationArray",
                    GpuProgramParameters.AutoConstantType.LightAttenuationArray, lightCount );
                parameters.SetNamedAutoConstant( "spotLightParamsArray",
                    GpuProgramParameters.AutoConstantType.SpotLightParamsArray, lightCount );
                parameters.SetNamedAutoConstant( "lightCustomShaderParameterArray",
                    GpuProgramParameters.AutoConstantType.LightCustomShaderParameterArray, lightCount );
            }

            //instancing
            if( RenderSystem.Instance.HasShaderModel3() &&
                RenderSystem.Instance.Capabilities.HardwareInstancing )
            {
                parameters.SetNamedAutoConstant( "instancing", GpuProgramParameters.AutoConstantType.Instancing );
            }

            //1 hour interval for better precision.
            parameters.SetNamedAutoConstantFloat( "time",
                GpuProgramParameters.AutoConstantType.Time0X, 3600.0f );
        }