Beispiel #1
0
        internal override bool CreateCpuSubPrograms(ProgramSet programSet)
        {
            Program vsProgram = programSet.CpuVertexProgram;

            //Resolve world view proj matrix
            UniformParameter wvpMatrix =
                vsProgram.ResolveAutoParameterInt(Graphics.GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0);

            if (wvpMatrix == null)
            {
                return(false);
            }

            Function vsEntry = vsProgram.EntryPointFunction;

            //Resolve input position parameter
            Parameter positionIn = vsEntry.ResolveInputParameter(Parameter.SemanticType.Position, 0,
                                                                 Parameter.ContentType.PositionObjectSpace,
                                                                 Graphics.GpuProgramParameters.GpuConstantType.Float4);

            if (positionIn == null)
            {
                return(false);
            }

            //Resolve output position parameter
            Parameter positionOut = vsEntry.ResolveOutputParameter(Parameter.SemanticType.Position, 0,
                                                                   Parameter.ContentType.PositionProjectiveSpace,
                                                                   Graphics.GpuProgramParameters.GpuConstantType.Float4);

            if (positionOut == null)
            {
                return(false);
            }

            //Add dependency
            vsProgram.AddDependency(FFPRenderState.FFPLibTransform);

            var transformFunc = new FunctionInvocation(FFPRenderState.FFPFuncTransform, -1, 0);

            transformFunc.PushOperand(wvpMatrix, Operand.OpSemantic.In);
            transformFunc.PushOperand(positionIn, Operand.OpSemantic.In);
            transformFunc.PushOperand(positionOut, Operand.OpSemantic.Out);

            vsEntry.AddAtomInstance(transformFunc);

            return(true);
        }
Beispiel #2
0
        protected override bool ResolveParameters(ProgramSet programSet)
        {
            Program  vsProgram = programSet.CpuVertexProgram;
            Program  psProgram = programSet.CpuFragmentProgram;
            Function vsMain    = vsProgram.EntryPointFunction;
            Function psMain    = psProgram.EntryPointFunction;

            // Resolve vs input mask texture coordinates.
            // NOTE: We use the first texture coordinate hard coded here
            // You may want to parametrize this as well - just remember to add it to hash and copy methods.
            this.vsInMaskTexcoord = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, 0,
                                                                 Parameter.ContentType.TextureCoordinate0,
                                                                 GpuProgramParameters.GpuConstantType.Float2);
            if (this.vsInMaskTexcoord == null)
            {
                return(false);
            }

            //Resolve vs output mask texture coordinates
            this.vsInMaskTexcoord = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, 0,
                                                                 Parameter.ContentType.TextureCoordinate0,
                                                                 GpuProgramParameters.GpuConstantType.Float2);
            if (this.vsInMaskTexcoord == null)
            {
                return(false);
            }

            //Resolve vs output mask texture coordinates.
            this.vsOutMaskTexcoord = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1,
                                                                   this.vsInMaskTexcoord.Content,
                                                                   GpuProgramParameters.GpuConstantType.Float2);
            if (this.vsInMaskTexcoord == null)
            {
                return(false);
            }

            //Resolve ps input mask texture coordinates.
            this.psInMaskTexcoord = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates,
                                                                 this.vsOutMaskTexcoord.Index,
                                                                 this.vsOutMaskTexcoord.Content,
                                                                 GpuProgramParameters.GpuConstantType.Float2);

            //Resolve vs output reflection texture coordinates
            this.vsOutReflectionTexcoord = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1,
                                                                         Parameter.ContentType.Unknown,
                                                                         (this.reflectionMapType == TextureType.TwoD)
                                                                                        ? GpuProgramParameters.GpuConstantType.Float2
                                                                                        : GpuProgramParameters.GpuConstantType.Float3);
            if (this.vsOutReflectionTexcoord == null)
            {
                return(false);
            }

            //Resolve ps input reflection texture coordinates.
            this.psInReflectionTexcoord = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates,
                                                                       this.vsOutReflectionTexcoord.Index,
                                                                       this.vsOutReflectionTexcoord.Content,
                                                                       this.vsOutReflectionTexcoord.Type);

            //Resolve world matrix.
            this.worldMatrix = vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.WorldMatrix, 0);
            if (this.worldMatrix == null)
            {
                return(false);
            }

            this.worldITMatrix = vsProgram.ResolveAutoParameterInt(
                GpuProgramParameters.AutoConstantType.InverseTransposeWorldMatrix, 0);
            if (this.worldITMatrix == null)
            {
                return(false);
            }

            this.viewMatrix = vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.ViewMatrix, 0);
            if (this.viewMatrix == null)
            {
                return(false);
            }

            this.vsInputPos = vsMain.ResolveInputParameter(Parameter.SemanticType.Position, 0,
                                                           Parameter.ContentType.PositionObjectSpace,
                                                           GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInputPos == null)
            {
                return(false);
            }

            this.vsInputNormal = vsMain.ResolveInputParameter(Parameter.SemanticType.Normal, 0,
                                                              Parameter.ContentType.NormalObjectSpace,
                                                              GpuProgramParameters.GpuConstantType.Float3);
            if (this.vsInputNormal == null)
            {
                return(false);
            }

            this.maskMapSampler = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Sampler2D,
                                                             this.maskMapSamplerIndex,
                                                             GpuProgramParameters.GpuParamVariability.Global, "mask_sampler");
            if (this.maskMapSampler == null)
            {
                return(false);
            }

            this.reflectionMapSampler =
                psProgram.ResolveParameter(
                    (this.reflectionMapType == TextureType.TwoD)
                                                ? GpuProgramParameters.GpuConstantType.Sampler2D
                                                : GpuProgramParameters.GpuConstantType.SamplerCube,
                    this.reflectionMapSamplerIndex, GpuProgramParameters.GpuParamVariability.Global, "reflection_texture");
            if (this.reflectionMapSampler == null)
            {
                return(false);
            }

            this.reflectionPower = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float1, -1,
                                                              GpuProgramParameters.GpuParamVariability.Global,
                                                              "reflection_power");
            if (this.reflectionPower == null)
            {
                return(false);
            }

            this.psOutDiffuse = psMain.ResolveOutputParameter(Parameter.SemanticType.Color, 0,
                                                              Parameter.ContentType.ColorDiffuse,
                                                              GpuProgramParameters.GpuConstantType.Float4);
            if (this.psOutDiffuse == null)
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        protected override bool ResolveParameters(Axiom.Components.RTShaderSystem.ProgramSet programSet)
        {
            Program vsProgram = programSet.CpuVertexProgram;
            Program psProgram = programSet.CpuFragmentProgram;

            Function vsMain = vsProgram.EntryPointFunction;
            Function psMain = psProgram.EntryPointFunction;

            //Resolve vertex shader output position in projective space.

            this.vsInPosition = vsMain.ResolveInputParameter(Parameter.SemanticType.Position, 0,
                                                             Parameter.ContentType.PositionObjectSpace,
                                                             Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInPosition == null)
            {
                return(false);
            }

            this.vsOriginalOutPositionProjectiveSpace = vsMain.ResolveOutputParameter(Parameter.SemanticType.Position, 0,
                                                                                      Parameter.ContentType.
                                                                                      PositionProjectiveSpace,
                                                                                      Graphics.GpuProgramParameters.
                                                                                      GpuConstantType.
                                                                                      Float4);
            if (this.vsOriginalOutPositionProjectiveSpace == null)
            {
                return(false);
            }

            var positionProjectiveSpaceAsTexcoord = (Parameter.ContentType)(Parameter.ContentType.CustomContentBegin + 1);

            this.vsOutPositionProjectiveSpace = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1,
                                                                              positionProjectiveSpaceAsTexcoord,
                                                                              Graphics.GpuProgramParameters.GpuConstantType.
                                                                              Float4);
            if (this.vsOutPositionProjectiveSpace == null)
            {
                return(false);
            }

            //Resolve ps input position in projective space
            this.psInPositionProjectiveSpace = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates,
                                                                            this.vsOutPositionProjectiveSpace.Index,
                                                                            this.vsOutPositionProjectiveSpace.Content,
                                                                            Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.psInPositionProjectiveSpace == null)
            {
                return(false);
            }

            //Resolve vertex shader uniform monitors count
            this.vsInMonitorsCount = vsProgram.ResolveParameter(Graphics.GpuProgramParameters.GpuConstantType.Float2, -1,
                                                                Graphics.GpuProgramParameters.GpuParamVariability.Global,
                                                                "monitorsCount");
            if (this.vsInMonitorsCount == null)
            {
                return(false);
            }

            //Resolve pixel shader uniform monitors count
            this.psInMonitorsCount = psProgram.ResolveParameter(Graphics.GpuProgramParameters.GpuConstantType.Float2, -1,
                                                                Graphics.GpuProgramParameters.GpuParamVariability.Global,
                                                                "monitorsCount");
            if (this.psInMonitorsCount == null)
            {
                return(false);
            }

            //Resolve the current world & view matrices concatenated
            this.worldViewMatrix =
                vsProgram.ResolveAutoParameterInt(Graphics.GpuProgramParameters.AutoConstantType.WorldViewMatrix,
                                                  0);
            if (this.worldViewMatrix == null)
            {
                return(false);
            }

            //Resolve the current projection matrix
            this.projectionMatrix = vsProgram.ResolveAutoParameterInt(
                Graphics.GpuProgramParameters.AutoConstantType.ProjectionMatrix, 0);
            if (this.projectionMatrix == null)
            {
                return(false);
            }

            var monitorIndex = Parameter.ContentType.TextureCoordinate3;

            //Resolve vertex shader monitor index
            this.vsInMonitorIndex = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, 3, monitorIndex,
                                                                 Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInMonitorIndex == null)
            {
                return(false);
            }

            Parameter.ContentType matrixR0 = Parameter.ContentType.TextureCoordinate4;
            Parameter.ContentType matrixR1 = Parameter.ContentType.TextureCoordinate5;
            Parameter.ContentType matrixR2 = Parameter.ContentType.TextureCoordinate6;
            Parameter.ContentType matrixR3 = Parameter.ContentType.TextureCoordinate7;

            //Resolve vertex shader viewport offset matrix
            this.vsInViewportOffsetMatrixR0 = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, 4,
                                                                           matrixR0,
                                                                           Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInViewportOffsetMatrixR0 == null)
            {
                return(false);
            }
            this.vsInViewportOffsetMatrixR1 = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, 4,
                                                                           matrixR1,
                                                                           Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInViewportOffsetMatrixR1 == null)
            {
                return(false);
            }
            this.vsInViewportOffsetMatrixR2 = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, 4,
                                                                           matrixR2,
                                                                           Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInViewportOffsetMatrixR2 == null)
            {
                return(false);
            }
            this.vsInViewportOffsetMatrixR3 = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, 4,
                                                                           matrixR3,
                                                                           Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInViewportOffsetMatrixR3 == null)
            {
                return(false);
            }

            this.vsOutMonitorIndex = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1, monitorIndex,
                                                                   Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsOutMonitorIndex == null)
            {
                return(false);
            }

            //Resolve ps input monitor index
            this.psInMonitorIndex = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates,
                                                                 this.vsOutMonitorIndex.Index,
                                                                 this.vsOutMonitorIndex.Content,
                                                                 Graphics.GpuProgramParameters.GpuConstantType.Float4);
            if (this.psInMonitorIndex == null)
            {
                return(false);
            }

            return(true);
        }