Example #1
0
        private void AddIndexedNormalRelatedWeight(Function vsMain, Parameter normalRelatedParam,
                                                   Parameter normalWorldRelatedParam, int index, ref int funcCounter)
        {
            FunctionInvocation curFuncInvocation;

            Operand.OpMask indexMask = IndexToMask(index);

            //multiply position with world matrix and put into temporary param
            curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncTransform,
                                                       (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                       funcCounter++);
            curFuncInvocation.PushOperand(paramInWorldMatrices, Operand.OpSemantic.In, (int)Operand.OpMask.All);
            curFuncInvocation.PushOperand(paramInIndices, Operand.OpSemantic.In, (int)indexMask, 1);
            curFuncInvocation.PushOperand(normalRelatedParam, Operand.OpSemantic.In);
            curFuncInvocation.PushOperand(paramTempFloat3, Operand.OpSemantic.Out);
            vsMain.AddAtomInstance(curFuncInvocation);

            //multiply temporary param with weight
            curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncModulate,
                                                       (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                       funcCounter++);
            curFuncInvocation.PushOperand(paramTempFloat3, Operand.OpSemantic.In);
            curFuncInvocation.PushOperand(paramInWeights, Operand.OpSemantic.In, (int)indexMask);
            curFuncInvocation.PushOperand(paramTempFloat3, Operand.OpSemantic.Out);
            vsMain.AddAtomInstance(curFuncInvocation);

            //check if on first iteration
            if (index == 0)
            {
                //set the local param as the value of the world normal
                curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign,
                                                           (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                           funcCounter++);
                curFuncInvocation.PushOperand(paramTempFloat3, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(normalWorldRelatedParam, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(normalWorldRelatedParam, Operand.OpSemantic.Out);
                vsMain.AddAtomInstance(curFuncInvocation);
            }
            else
            {
                //add the local param as the value of the world normal
                curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAdd,
                                                           (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                           funcCounter++);
                curFuncInvocation.PushOperand(paramTempFloat3, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(normalWorldRelatedParam, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(normalWorldRelatedParam, Operand.OpSemantic.Out);
                vsMain.AddAtomInstance(curFuncInvocation);
            }
        }
        private void AddIndexedPositionWeight(Function vsMain, int index, Parameter worldMatrix,
                                              Parameter positionTempParameter, Parameter positionRelatedOutputParam,
                                              ref int funcCounter)
        {
            Operand.OpMask     indexMask         = IndexToMask(index);
            FunctionInvocation curFuncInvocation = null;

            //multiply position with world matrix and put into temporary param
            curFuncInvocation = new FunctionInvocation(SGXFuncBlendWeight,
                                                       (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                       funcCounter++);
            curFuncInvocation.PushOperand(paramInWeights, Operand.OpSemantic.In, indexMask);
            curFuncInvocation.PushOperand(worldMatrix, Operand.OpSemantic.In);
            curFuncInvocation.PushOperand(positionTempParameter, Operand.OpSemantic.Out);
            vsMain.AddAtomInstance(curFuncInvocation);

            //check if on first iteration
            if (index == 0)
            {
                //set the local param as the value of the world param
                curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign,
                                                           (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                           funcCounter++);
                curFuncInvocation.PushOperand(positionTempParameter, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(positionRelatedOutputParam, Operand.OpSemantic.Out);
                vsMain.AddAtomInstance(curFuncInvocation);
            }
            else
            {
                //add the local param as the value of the world param
                curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAdd,
                                                           (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                           funcCounter++);
                curFuncInvocation.PushOperand(positionTempParameter, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(positionRelatedOutputParam, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(positionRelatedOutputParam, Operand.OpSemantic.Out);
                vsMain.AddAtomInstance(curFuncInvocation);
            }
        }
Example #3
0
        protected override bool AddFunctionInvocations(ProgramSet programSet)
        {
            Program            vsProgram         = programSet.CpuVertexProgram;
            Program            psProgram         = programSet.CpuFragmentProgram;
            Function           psMain            = psProgram.EntryPointFunction;
            Function           vsMain            = vsProgram.EntryPointFunction;
            FunctionInvocation curFuncInvocation = null;
            //Calculate the position and size of the texture in the atlas in the vertex shader
            int groupOrder = ((int)FFPRenderState.FFPVertexShaderStage.VSTexturing -
                              (int)FFPRenderState.FFPVertexShaderStage.VSLighting) / 2;
            int internalCounter = 0;

            for (int i = 0; i < TextureAtlasSampler.MaxTextures; i++)
            {
                if (this.isAtlasTextureUnits[i] == true)
                {
                    Operand.OpMask textureIndexMask = Operand.OpMask.X;
                    switch (i)
                    {
                    case 1:
                        textureIndexMask = Operand.OpMask.Y;
                        break;

                    case 2:
                        textureIndexMask = Operand.OpMask.Z;
                        break;

                    case 3:
                        textureIndexMask = Operand.OpMask.W;
                        break;
                    }
                    curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign, groupOrder,
                                                               internalCounter++);
                    curFuncInvocation.PushOperand(this.vsTextureTable[i], Operand.OpSemantic.In);
                    curFuncInvocation.PushOperand(this.vsInpTextureTableIndex, Operand.OpSemantic.In, (int)textureIndexMask,
                                                  1);
                    curFuncInvocation.PushOperand(this.vsOutTextureDatas[i], Operand.OpSemantic.Out);
                    vsMain.AddAtomInstance(curFuncInvocation);
                }
            }

            //sample the texture in the fragment shader given the extracted data in the pixel shader
            // groupOrder = (FFP_PS_SAMPLING + FFP_PS_TEXTURING) / 2;
            internalCounter = 0;

            var inpParams   = psMain.InputParameters;
            var localParams = psMain.LocalParameters;

            Parameter psAtlasTextureCoord = psMain.ResolveLocalParameter(Parameter.SemanticType.Unknown, -1,
                                                                         "atlasCoord",
                                                                         GpuProgramParameters.GpuConstantType.Float2);

            for (int j = 0; j < TextureAtlasSampler.MaxTextures; j++)
            {
                if (this.isAtlasTextureUnits[j] == true)
                {
                    //Find the texture coordinates texel and sampler from the original FFPTexturing
                    Parameter texcoord = Function.GetParameterByContent(inpParams,
                                                                        (Parameter.ContentType)
                                                                            ((int)Parameter.ContentType.TextureCoordinate0 +
                                                                            j),
                                                                        GpuProgramParameters.GpuConstantType.Float2);
                    Parameter        texel   = Function.GetParameterByName(localParams, this.paramTexel + j.ToString());
                    UniformParameter sampler =
                        psProgram.GetParameterByType(GpuProgramParameters.GpuConstantType.Sampler2D, j);

                    //TODO
                    string addressUFuncName = GetAddressingFunctionName(this.textureAddressings[j].U);
                    string addressVFuncName = GetAddressingFunctionName(this.textureAddressings[j].V);

                    //Create a function which will replace the texel with the texture texel
                    if ((texcoord != null) && (texel != null) && (sampler != null) &&
                        (addressUFuncName != null) && (addressVFuncName != null))
                    {
                        //calculate the U value due to addressing mode
                        curFuncInvocation = new FunctionInvocation(addressUFuncName, groupOrder, internalCounter++);
                        curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, Operand.OpMask.X);
                        curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.Out, Operand.OpMask.X);
                        psMain.AddAtomInstance(curFuncInvocation);

                        //calculate the V value due to addressing mode
                        curFuncInvocation = new FunctionInvocation(addressVFuncName, groupOrder, internalCounter++);
                        curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, Operand.OpMask.Y);
                        curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.Out, Operand.OpMask.Y);
                        psMain.AddAtomInstance(curFuncInvocation);

                        //sample the texel color
                        curFuncInvocation =
                            new FunctionInvocation(this.autoAdjustPollPosition ? SGXFuncAtlasSampleAutoAdjust : SGXFuncAtlasSampleNormal,
                                                   groupOrder, internalCounter++);
                        curFuncInvocation.PushOperand(sampler, Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, (int)(Operand.OpMask.X | Operand.OpMask.Y));
                        curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(this.psInpTextureData[j], Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(this.psTextureSizes[j], Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(texel, Operand.OpSemantic.Out);
                        psMain.AddAtomInstance(curFuncInvocation);
                    }
                }
            }

            return(true);
        }
Example #4
0
        private void AddIndexedPositionWeight(Function vsMain, int index, ref int funcCounter)
        {
            Operand.OpMask indexMask = IndexToMask(index);

            FunctionInvocation curFuncInvocation;

            var outputMask = (int)(Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z);

            if (paramInWorldMatrices.Type == GpuProgramParameters.GpuConstantType.Matrix_4X4)
            {
                outputMask = (int)Operand.OpMask.All;
            }

            //multiply posiiton with world matrix and put into temporary param
            curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncTransform,
                                                       (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                       funcCounter++);
            curFuncInvocation.PushOperand(paramInWorldMatrix, Operand.OpSemantic.In);
            curFuncInvocation.PushOperand(paramInIndices, Operand.OpSemantic.In, (int)indexMask, 1);
            curFuncInvocation.PushOperand(paramInPosition, Operand.OpSemantic.In);
            curFuncInvocation.PushOperand(paramTempFloat4, Operand.OpSemantic.Out, outputMask);
            vsMain.AddAtomInstance(curFuncInvocation);

            //set w value of temporary param to 1
            curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign,
                                                       (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                       funcCounter++);
            curFuncInvocation.PushOperand(ParameterFactory.CreateConstParamFloat(1.0f), Operand.OpSemantic.In);
            curFuncInvocation.PushOperand(paramTempFloat4, Operand.OpSemantic.Out, (int)Operand.OpMask.W);
            vsMain.AddAtomInstance(curFuncInvocation);

            //multiply temporary param with weight
            curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncModulate,
                                                       (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                       funcCounter++);
            curFuncInvocation.PushOperand(paramTempFloat4, Operand.OpSemantic.In);
            curFuncInvocation.PushOperand(paramInWeights, Operand.OpSemantic.In, (int)indexMask);
            curFuncInvocation.PushOperand(paramTempFloat4, Operand.OpSemantic.Out);
            vsMain.AddAtomInstance(curFuncInvocation);

            //check if on first iteration
            if (index == 0)
            {
                //set the local param as the value of the world param
                curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign,
                                                           (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                           funcCounter++);
                curFuncInvocation.PushOperand(paramTempFloat4, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(paramLocalPositionWorld, Operand.OpSemantic.Out);
                vsMain.AddAtomInstance(curFuncInvocation);
            }
            else
            {
                //add the local param as the value of the world param
                curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAdd,
                                                           (int)FFPRenderState.FFPVertexShaderStage.VSTransform,
                                                           funcCounter++);
                curFuncInvocation.PushOperand(paramTempFloat4, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(paramLocalPositionWorld, Operand.OpSemantic.In);
                curFuncInvocation.PushOperand(paramLocalPositionWorld, Operand.OpSemantic.Out);
                vsMain.AddAtomInstance(curFuncInvocation);
            }
        }
Example #5
0
 public void PushOperand(Parameter parameter, Operand.OpSemantic opSemantic, Operand.OpMask opMask)
 {
     PushOperand(parameter, opSemantic, (int)opMask, 0);
 }