internal virtual bool CreateCpuSubPrograms(ProgramSet programSet) { bool result; //resolve params result = ResolveParameters(programSet); if (result == false) { return(false); } //resolve dependencis result = ResolveDependencies(programSet); if (result == false) { return(false); } //add fuction invocations result = AddFunctionInvocations(programSet); if (result == false) { return(false); } return(true); }
internal virtual bool CreateCpuSubPrograms( ProgramSet programSet ) { bool result; //resolve params result = ResolveParameters( programSet ); if ( result == false ) { return false; } //resolve dependencis result = ResolveDependencies( programSet ); if ( result == false ) { return false; } //add fuction invocations result = AddFunctionInvocations( programSet ); if ( result == false ) { return false; } return true; }
protected override bool ResolveDependencies(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; vsProgram.AddDependency(FFPRenderState.FFPLibCommon); psProgram.AddDependency(SGXLibTextureAtlas); return(true); }
protected override bool ResolveDependencies(Axiom.Components.RTShaderSystem.ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; vsProgram.AddDependency(FFPRenderState.FFPLibCommon); vsProgram.AddDependency(SGXLibInstancedViewports); psProgram.AddDependency(FFPRenderState.FFPLibCommon); psProgram.AddDependency(SGXLibInstancedViewports); return(true); }
internal override bool AddFunctionInvocations(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Function vsMain = vsProgram.EntryPointFunction; int internalCounter = 0; //add functions to calculate position data in wold, object and projective space AddPositionCalculations(vsMain, ref internalCounter); //add functions to calculate normal and normal related data in world and object space AddNormalRelatedCalculations(vsMain, paramInNormal, paramLocalNormalWorld, ref internalCounter); AddNormalRelatedCalculations(vsMain, paramInTangent, paramLocalTangentWorld, ref internalCounter); AddNormalRelatedCalculations(vsMain, paramInBiNormal, paramLocalBiNormalWorld, ref internalCounter); return(true); }
internal override bool PreCreateGpuPrograms( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program fsProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function fsMain = fsProgram.EntryPointFunction; bool success; //Compact vertex shader outputs success = ProgramProcessor.CompactVsOutputs( vsMain, fsMain ); if ( success == false ) { return false; } return true; }
internal override bool PostCreateGpuPrograms(ProgramSet programSet) { Program vsCpuProgram = programSet.CpuVertexProgram; GpuProgram vsGpuProgram = programSet.GpuVertexProgram; Program fsCpuProgram = programSet.CpuVertexProgram; GpuProgram fsGpuProgram = programSet.GpuFragmentProgram; BindAutoParameters(programSet.CpuVertexProgram, programSet.GpuVertexProgram); BindAutoParameters(programSet.CpuFragmentProgram, programSet.GpuFragmentProgram); BindTextureSamplers(vsCpuProgram, vsGpuProgram); BindTextureSamplers(fsCpuProgram, fsGpuProgram); return(true); }
internal override bool PreCreateGpuPrograms(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Program fsProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function fsMain = fsProgram.EntryPointFunction; bool success; //compact vertex shader outputs. success = ProgramProcessor.CompactVsOutputs(vsMain, fsMain); if (success == false) { return(false); } return(true); }
internal override bool PostCreateGpuPrograms( ProgramSet programSet ) { Program vsCpuProgram = programSet.CpuVertexProgram; GpuProgram vsGpuProgram = programSet.GpuVertexProgram; Program fsCpuProgram = programSet.CpuVertexProgram; GpuProgram fsGpuProgram = programSet.GpuFragmentProgram; BindAutoParameters( programSet.CpuVertexProgram, programSet.GpuVertexProgram ); BindAutoParameters( programSet.CpuFragmentProgram, programSet.GpuFragmentProgram ); BindTextureSamplers( vsCpuProgram, vsGpuProgram ); BindTextureSamplers( fsCpuProgram, fsGpuProgram ); return true; }
protected override bool AddFunctionInvocations(Axiom.Components.RTShaderSystem.ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Function vsMain = vsProgram.EntryPointFunction; Program psProgram = programSet.CpuFragmentProgram; Function psMain = psProgram.EntryPointFunction; //Add vertex shader invocations if (!AddVsInvocations(vsMain, (int)FFPRenderState.FFPVertexShaderStage.VSTransform + 1)) { return(false); } //Add pixel shader invocations if (!AddPsInvocations(psMain, (int)FFPRenderState.FFPFragmentShaderStage.PSPreProcess + 1)) { return(false); } return(true); }
protected override bool ResolveParameters(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; //Define vertex shader parameters used to find the positon of the textures in the atlas var indexContent = (Parameter.ContentType)((int)Parameter.ContentType.TextureCoordinate0 + this.atlasTexcoordPos); Axiom.Graphics.GpuProgramParameters.GpuConstantType indexType = GpuProgramParameters.GpuConstantType.Float4; this.vsInpTextureTableIndex = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, this.atlasTexcoordPos, indexContent, indexType); //Define parameters to carry the information on the location of the texture from the vertex to the pixel shader for (int i = 0; i < TextureAtlasSampler.MaxTextures; i++) { if (this.isAtlasTextureUnits[i] == true) { this.vsTextureTable[i] = vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global, "AtlasData", this.atlasTableDatas[i].Count); this.vsOutTextureDatas[i] = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4); this.psInpTextureData[i] = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, this.vsOutTextureDatas[i].Index, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4); this.psTextureSizes[i] = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float2, -1, GpuProgramParameters.GpuParamVariability.PerObject, "AtlasSize"); } } return(true); }
protected override bool AddFunctionInvocations( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; int internalCounter = 0; if ( AddVSInvocation( vsMain, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing + 1, ref internalCounter ) == false ) { return false; } internalCounter = 0; if ( !AddPSInvocation( psProgram, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin + 2, ref internalCounter ) ) { return false; } return true; }
private bool ResolveGlobalParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; //Resolve normal map texture sampler parameter this.normalMapSampler = psProgram.ResolveParameter( Axiom.Graphics.GpuProgramParameters.GpuConstantType.Sampler2D, this.normalMapSamplerIndex, GpuProgramParameters.GpuParamVariability.PerObject, "gNormalMapSampler" ); if ( this.normalMapSampler == null ) { return false; } //Get surface ambient color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) == 0 ) { this.derivedAmbientLightColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedAmbientLightColor, 0 ); if ( this.derivedAmbientLightColor == null ) { return false; } } else { this.lightAmbientColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.AmbientLightColor, 0 ); if ( this.lightAmbientColor == null ) { return false; } this.surfaceAmbientColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceAmbientColor, 0, 0 ); if ( this.surfaceAmbientColor == null ) { return false; } } //Get surface diffuse color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 ) { this.surfaceDiffuseColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceDiffuseColor, 0 ); if ( this.surfaceDiffuseColor == null ) { return false; } } //Get surface specular color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 ) { this.surfaceSpecularColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceSpecularColor, 0 ); if ( this.surfaceSpecularColor == null ) { return false; } } //Get surface emissive color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Emissive ) == 0 ) { this.surfaceEmissiveColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceEmissiveColor, 0 ); if ( this.surfaceEmissiveColor == null ) { return false; } } //Get derived scene color this.derivedSceneColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 ); if ( this.derivedSceneColor == null ) { return false; } //Get surface shininess. this.surfaceShininess = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceShininess, 0 ); if ( this.surfaceShininess == null ) { return false; } //Resolve input vertex shader normal this.vsInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, Axiom.Graphics.GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsInNormal == null ) { return false; } //Resolve input vertex shader tangent if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { this.vsInTangent = vsMain.ResolveInputParameter( Parameter.SemanticType.Tangent, 0, Parameter.ContentType.TangentObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsInTangent == null ) { return false; } //Resolve local vertex shader TNB matrix this.vsTBNMatrix = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lMatTBN", GpuProgramParameters.GpuConstantType.Matrix_3X3 ); if ( this.vsTBNMatrix == null ) { return false; } } //resolve input vertex shader texture coordinates Parameter.ContentType texCoordToUse = Parameter.ContentType.TextureCoordinate0; switch ( this.vsTexCoordSetIndex ) { case 0: texCoordToUse = Parameter.ContentType.TextureCoordinate0; break; case 1: texCoordToUse = Parameter.ContentType.TextureCoordinate1; break; case 2: texCoordToUse = Parameter.ContentType.TextureCoordinate2; break; case 3: texCoordToUse = Parameter.ContentType.TextureCoordinate3; break; case 4: texCoordToUse = Parameter.ContentType.TextureCoordinate4; break; case 5: texCoordToUse = Parameter.ContentType.TextureCoordinate5; break; case 6: texCoordToUse = Parameter.ContentType.TextureCoordinate6; break; case 7: texCoordToUse = Parameter.ContentType.TextureCoordinate7; break; default: throw new AxiomException( "vsTexCoordIndexOut of range", new ArgumentOutOfRangeException() ); } this.vsInTexcoord = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsTexCoordSetIndex, texCoordToUse, GpuProgramParameters.GpuConstantType.Float2 ); if ( this.vsInTexcoord == null ) { return false; } //Resolve output vertex shader texture coordinates this.vsOutTexcoord = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, texCoordToUse, GpuProgramParameters.GpuConstantType.Float2 ); if ( this.vsOutTexcoord == null ) { return false; } //resolve pixel input texture coordinates normal this.psInTexcoord = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutTexcoord.Index, this.vsOutTexcoord.Content, this.vsOutTexcoord.Type ); if ( this.psInTexcoord == null ) { return false; } //Resolve pixel shader normal. if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { this.psNormal = psMain.ResolveLocalParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.psNormal == null ) { return false; } } else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { this.psNormal = psMain.ResolveLocalParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalTangentSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.psNormal == null ) { return false; } } var inputParams = psMain.InputParameters; var localParams = psMain.LocalParameters; this.psDiffuse = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psDiffuse == null ) { this.psDiffuse = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psDiffuse == null ) { return false; } } this.psOutDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psOutDiffuse == null ) { return false; } this.psTempDiffuseColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lNormalMapDiffuse", GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psTempDiffuseColor == null ) { return false; } if ( this.specularEnabled ) { this.psSpecular = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorSpecular, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psSpecular == null ) { this.psSpecular = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorSpecular, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psSpecular == null ) { return false; } } this.psTempSpecularColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lNormalMapSpecular", GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psTempSpecularColor == null ) { return false; } this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { this.vsOutView = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.PostOCameraTangentSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsOutView == null ) { return false; } } else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { this.vsOutView = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.PostOCameraTangentSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsOutView == null ) { return false; } } this.psInView = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutView.Index, this.vsOutView.Content, this.vsOutView.Type ); if ( this.psInView == null ) { return false; } //Resolve camera position world space this.camPosWorldSpace = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.CameraPosition, 0 ); if ( this.camPosWorldSpace == null ) { return false; } this.vsLocalDir = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lNormalMapTempDir", GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsLocalDir == null ) { return false; } this.vsWorldPosition = vsMain.ResolveLocalParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionWorldSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsWorldPosition == null ) { return false; } //Resolve world matrix this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 ); if ( this.worldMatrix == null ) { return false; } //Resolve inverse world rotation matrix this.worldInvRotMatrix = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1, GpuProgramParameters.GpuParamVariability.PerObject, "inv_world_rotation_matrix" ); if ( this.worldInvRotMatrix == null ) { return false; } } return true; }
protected override bool ResolveParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; //Get input position parameter this.vsInPos = Function.GetParameterBySemantic( vsMain.InputParameters, Parameter.SemanticType.Position, 0 ); if ( this.vsInPos == null ) { return false; } //Get output position parameter this.vsOutPos = Function.GetParameterBySemantic( vsMain.OutputParameters, Parameter.SemanticType.Position, 0 ); if ( this.vsOutPos == null ) { return false; } //Resolve vertex shader output depth. this.vsOutDepth = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.DepthViewSpace, GpuProgramParameters.GpuConstantType.Float1 ); if ( this.vsOutDepth == null ) { return false; } //Resolve input depth parameter. this.psInDepth = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutDepth.Index, this.vsOutDepth.Content, GpuProgramParameters.GpuConstantType.Float1 ); if ( this.psInDepth == null ) { return false; } //Get in/local specular paramter this.psSpecular = Function.GetParameterBySemantic( psMain.InputParameters, Parameter.SemanticType.Color, 1 ); if ( this.psSpecular == null ) { this.psSpecular = Function.GetParameterBySemantic( psMain.LocalParameters, Parameter.SemanticType.Color, 1 ); if ( this.psSpecular == null ) { return false; } } //Resolve computed local shadow color parameter. this.psLocalShadowFactor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lShadowFactor", GpuProgramParameters.GpuConstantType.Float1 ); if ( this.psLocalShadowFactor == null ) { return false; } //Resolve computed local shadow color parameter this.psSplitPoints = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global, "pssm_split_points" ); if ( this.psSplitPoints == null ) { return false; } //Get derived scene color this.psDerivedSceneColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 ); if ( this.psDerivedSceneColor == null ) { return false; } int lightIndex = 0; foreach ( var it in this.shadowTextureParamsList ) { it.WorldViewProjMatrix = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1, GpuProgramParameters.GpuParamVariability.PerObject, "world_texture_view_proj" ); if ( it.WorldViewProjMatrix == null ) { return false; } Parameter.ContentType lightSpace = Parameter.ContentType.PositionLightSpace0; switch ( lightIndex ) { case 1: lightSpace = Parameter.ContentType.PositionLightSpace1; break; case 2: lightSpace = Parameter.ContentType.PositionLightSpace2; break; case 3: lightSpace = Parameter.ContentType.PositionLightSpace3; break; case 4: lightSpace = Parameter.ContentType.PositionLightSpace4; break; case 5: lightSpace = Parameter.ContentType.PositionLightSpace5; break; case 6: lightSpace = Parameter.ContentType.PositionLightSpace6; break; case 7: lightSpace = Parameter.ContentType.PositionLightSpace7; break; } it.VSOutLightPosition = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, lightSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( it.VSOutLightPosition == null ) { return false; } it.PSInLightPosition = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, it.VSOutLightPosition.Index, it.VSOutLightPosition.Content, GpuProgramParameters.GpuConstantType.Float4 ); if ( it.PSInLightPosition == null ) { return false; } it.TextureSampler = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Sampler2D, it.TextureSamplerIndex, GpuProgramParameters.GpuParamVariability.Global, "shadow_map" ); if ( it.TextureSampler == null ) { return false; } it.InvTextureSize = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global, "inv_shadow_texture_size" ); if ( it.InvTextureSize == null ) { return false; } lightIndex++; } return true; }
private void SynchronizePixelnToBeVertexOut( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; //first find the vertex shader Function vertexMain = null; Function pixelMain = null; { var functionList = vsProgram.Functions; foreach ( var curFunction in functionList ) { if ( curFunction.FuncType == Function.FunctionType.VsMain ) { vertexMain = curFunction; break; } } } //find pixel shader main { var functionList = psProgram.Functions; foreach ( var curFunction in functionList ) { if ( curFunction.FuncType == Function.FunctionType.PsMain ) { pixelMain = curFunction; break; } } } //save the pixel program original input parameters var pixelOriginalINParams = pixelMain.InputParameters; //set the pixel input to be the same as the vertex prog output pixelMain.DeleteAllInputParameters(); // Loop the vertex shader output parameters and make sure that // all of them exist in the pixel shader input. // If the parameter type exist in the original output - use it // If the parameter doesn't exist - use the parameter from the // vertex shader input. // The order will be based on the vertex shader parameters order // Write output parameters. var outParams = vertexMain.OutputParameters; foreach ( var curOutParameter in outParams ) { Parameter paramToAdd = Function.GetParameterBySemantic( pixelOriginalINParams, curOutParameter.Semantic, curOutParameter.Index ); if ( paramToAdd == null ) { //param not found - we will add the one from the vertex shader paramToAdd = curOutParameter; } pixelMain.AddInputParameter( paramToAdd ); } }
protected bool ResolveGlobalParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; //Resolve world view IT matrix this.worldViewITMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.InverseTransposeWorldViewMatrix, 0 ); if ( this.worldViewITMatrix == null ) { return false; } //Get surface ambient color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) == 0 ) { this.derivedAmbientLightColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedAmbientLightColor, 0 ); if ( this.derivedAmbientLightColor == null ) { return false; } } else { this.lightAmbientColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.AmbientLightColor, 0 ); if ( this.lightAmbientColor == null ) { return false; } this.surfaceAmbientColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceAmbientColor, 0 ); if ( this.surfaceAmbientColor == null ) { return false; } } //Get surface diffuse color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 ) { this.surfaceDiffuseColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceDiffuseColor, 0 ); if ( this.surfaceDiffuseColor == null ) { return false; } } //Get surface emissive color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Emissive ) == 0 ) { this.surfaceEmissiveColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceEmissiveColor, 0 ); if ( this.surfaceEmissiveColor == null ) { return false; } } //Get derived scene color this.derivedSceneColor = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 ); if ( this.derivedSceneColor == null ) { return false; } //Get surface shininess this.surfaceShininess = psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceShininess, 0 ); if ( this.surfaceShininess == null ) { return false; } //Resolve input vertex shader normal this.vsInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsInNormal == null ) { return false; } this.vsOutNormal = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.NormalViewSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsOutNormal == null ) { return false; } //Resolve input pixel shader normal. this.psInNormal = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutNormal.Index, this.vsOutNormal.Content, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.psInNormal == null ) { return false; } var inputParams = psMain.InputParameters; var localParams = psMain.LocalParameters; this.psDiffuse = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psDiffuse == null ) { this.psDiffuse = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psDiffuse == null ) { return false; } } this.psOutDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psOutDiffuse == null ) { return false; } this.psTempDiffuseColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lPerPixelDiffuse", GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psTempDiffuseColor == null ) { return false; } if ( this.specularEnable ) { this.psSpecular = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorSpecular, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psSpecular == null ) { this.psSpecular = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorSpecular, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psSpecular == null ) { return false; } } this.psTempSpecularColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lPerPixelSpecular", GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psTempSpecularColor == null ) { return false; } this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } this.vsOutViewPos = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.PositionViewSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsOutViewPos == null ) { return false; } this.psInViewPos = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutViewPos.Index, this.vsOutViewPos.Content, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.psInViewPos == null ) { return false; } this.worldViewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 ); if ( this.worldViewMatrix == null ) { return false; } } return true; }
protected override bool AddFunctionInvocations( ProgramSet programSet ) { if ( this.fogMode == FogMode.None ) { return true; } Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; FunctionInvocation curFuncInvocation = null; int internalCounter = 0; //Per pixel fog if ( this.calcMode == CalcMode.PerPixel ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogDepth, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); curFuncInvocation.PushOperand( this.worldViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutDepth, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); internalCounter = 0; switch ( this.fogMode ) { case FogMode.Exp: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogLinear, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); break; case FogMode.Exp2: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogExp, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); break; case FogMode.Linear: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogExp2, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); break; default: break; } curFuncInvocation.PushOperand( this.psInDepth, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.fogParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.fogColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } else //Per vertex fog { internalCounter = 0; switch ( this.fogMode ) { case FogMode.Exp: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncVertexFogLinear, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); break; case FogMode.Exp2: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncVertexFogExp, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); break; case FogMode.Linear: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncVertexFogExp2, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); break; default: break; } curFuncInvocation.PushOperand( this.worldViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.fogParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutFogFactor, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); internalCounter = 0; curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLerp, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); curFuncInvocation.PushOperand( this.fogColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInFogFactor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } return true; }
/// <summary> /// Called after cretaion of the GPU programs. /// </summary> /// <param name="programSet"> The program set container </param> /// <returns> True on success </returns> internal virtual bool PostCreateGpuPrograms(ProgramSet programSet) { return(false); }
protected override bool ResolveDependencies( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; vsProgram.AddDependency( FFPRenderState.FFPLibCommon ); vsProgram.AddDependency( FFPRenderState.FFPLibCommon ); return true; }
protected override bool AddFunctionInvocations( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Function vsMain = vsProgram.EntryPointFunction; int internalCounter = 0; //Add the global illumination functions if ( !AddGlobalIlluminationInvocation( vsMain, (int)FFPRenderState.FFPVertexShaderStage.VSLighting, ref internalCounter ) ) { return false; } //Add per light funcitons for ( int i = 0; i < this.lightParamsList.Count; i++ ) { if ( !AddIlluminationInvocation( this.lightParamsList[ i ], vsMain, (int)FFPRenderState.FFPVertexShaderStage.VSLighting, ref internalCounter ) ) { return false; } } return true; }
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); }
protected override bool ResolveParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Function vsMain = vsProgram.EntryPointFunction; //REsolve world view IT matrix this.worldViewITMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.InverseTransposeWorldViewMatrix, 0 ); if ( this.worldViewITMatrix == null ) { return false; } //Get surface ambient color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) == 0 ) { this.derivedAmbientLightColor = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedAmbientLightColor, 0 ); if ( this.derivedAmbientLightColor == null ) { return false; } } else { this.lightAmbientColor = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.AmbientLightColor, 0 ); if ( this.lightAmbientColor == null ) { return false; } this.surfaceAmbientColor = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceAmbientColor, 0 ); if ( this.surfaceAmbientColor == null ) { return false; } } //Get surface diffuse color if need to. if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 ) { this.surfaceDiffuseColor = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceDiffuseColor, 0 ); if ( this.surfaceDiffuseColor == null ) { return false; } } //Get surface specular color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 ) { this.surfaceSpecularColor = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceSpecularColor, 0 ); if ( this.surfaceSpecularColor == null ) { return false; } } //Get surface emissive color if need to. if ( ( this.trackVertexColorType & TrackVertexColor.Emissive ) == 0 ) { this.surfaceEmissiveCoilor = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceEmissiveColor, 0 ); if ( this.surfaceEmissiveCoilor == null ) { return false; } } //Get derived scene color this.derivedSceneColor = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 ); if ( this.derivedSceneColor == null ) { return false; } //get surface shininess this.surfaceShininess = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceShininess, 0 ); if ( this.surfaceShininess == null ) { return false; } //Resolve input vertex shader normal this.vsInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsInNormal == null ) { return false; } if ( this.trackVertexColorType != 0 ) { this.vsDiffuse = vsMain.ResolveInputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsDiffuse == null ) { return false; } } //Resolve output vertex shader diffuse color. this.vsOutDiffuse = vsMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsOutDiffuse == null ) { return false; } //Resolve per light parameters for ( int i = 0; i < this.lightParamsList.Count; i++ ) { switch ( this.lightParamsList[ i ].Type ) { case LightType.Directional: this.lightParamsList[ i ].Direction = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_position_view_space" ); if ( this.lightParamsList[ i ].Direction == null ) { return false; } break; case LightType.Point: this.worldViewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 ); if ( this.worldViewMatrix == null ) { return false; } this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } this.lightParamsList[ i ].Position = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_position_view_space" ); if ( this.lightParamsList[ i ].Position == null ) { return false; } this.lightParamsList[ i ].AttenuatParams = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_attenuation" ); if ( this.lightParamsList[ i ].AttenuatParams == null ) { return false; } break; case LightType.Spotlight: this.worldViewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 ); if ( this.worldViewMatrix == null ) { return false; } this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } this.lightParamsList[ i ].Position = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_position_view_space" ); if ( this.lightParamsList[ i ].Position == null ) { return false; } this.lightParamsList[ i ].Direction = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_direction_view_space" ); if ( this.lightParamsList[ i ].Direction == null ) { return false; } this.lightParamsList[ i ].AttenuatParams = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_attenuation" ); if ( this.lightParamsList[ i ].AttenuatParams == null ) { return false; } this.lightParamsList[ i ].SpotParams = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float3, -1, GpuProgramParameters.GpuParamVariability.Lights, "spotlight_params" ); if ( this.lightParamsList[ i ].SpotParams == null ) { return false; } break; } //Resolve diffuse color if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 ) { this.lightParamsList[ i ].DiffuseColor = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global | GpuProgramParameters.GpuParamVariability.Lights, "derived_light_diffuse" ); if ( this.lightParamsList[ i ].DiffuseColor == null ) { return false; } } else { this.lightParamsList[ i ].DiffuseColor = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_diffuse" ); if ( this.lightParamsList[ i ].DiffuseColor == null ) { return false; } } if ( this.specularEnable ) { //Resolve specular color if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 ) { this.lightParamsList[ i ].SpecularColor = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global | GpuProgramParameters.GpuParamVariability.Lights, "derived_light_specular" ); if ( this.lightParamsList[ i ].SpecularColor == null ) { return false; } } else { this.lightParamsList[ i ].SpecularColor = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_specular" ); if ( this.lightParamsList[ i ].SpecularColor == null ) { return false; } } if ( this.vsOutSpecular == null ) { this.vsOutSpecular = vsMain.ResolveOutputParameter( Parameter.SemanticType.Color, 1, Parameter.ContentType.ColorSpecular, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsOutSpecular == null ) { return false; } } if ( this.vsInPosition == null ) { this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } } if ( this.worldViewMatrix == null ) { this.worldViewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 ); if ( this.worldViewMatrix == null ) { return false; } } } } return true; }
protected override bool ResolveParameters( ProgramSet programSet ) { for ( int i = 0; i < this.textureUnitParamsList.Count; i++ ) { TextureUnitParams curParams = this.textureUnitParamsList[ i ]; if ( !ResolveUniformParams( curParams, programSet ) ) { return false; } if ( !ResolveFunctionsParams( curParams, programSet ) ) { return false; } } return true; }
protected virtual bool AddFunctionInvocations(ProgramSet programSet) { return(true); }
/// <summary> /// Called after cretaion of the GPU programs. /// </summary> /// <param name="programSet"> The program set container </param> /// <returns> True on success </returns> internal virtual bool PostCreateGpuPrograms( ProgramSet programSet ) { return false; }
protected override bool ResolveParameters( ProgramSet programSet ) { if ( this.fogMode == FogMode.None ) { return true; } Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; //Resolve world view matrix. this.worldViewProjMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0 ); if ( this.worldViewProjMatrix == null ) { return false; } //Resolve vertex shader input position this.vsInPos = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPos == null ) { return false; } //Resolve fog color this.fogColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global, "gFogColor" ); if ( this.fogColor == null ) { return false; } //Resolve pixel shader output diffuse color this.psOutDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psOutDiffuse == null ) { return false; } //Per pixel fog if ( this.calcMode == CalcMode.PerPixel ) { //Resolve fog params this.fogParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global, "gFogParams" ); if ( this.fogParams == null ) { return false; } //Resolve vertex shader output depth this.vsOutDepth = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.DepthViewSpace, GpuProgramParameters.GpuConstantType.Float1 ); if ( this.vsOutDepth == null ) { return false; } //Resolve pixel shader input depth. this.psInDepth = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutDepth.Index, this.vsOutDepth.Content, GpuProgramParameters.GpuConstantType.Float1 ); if ( this.psInDepth == null ) { return false; } } //per vertex fog else { this.fogParams = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global, "gFogParams" ); if ( this.fogParams == null ) { return false; } //Resolve vertex shader output fog factor this.vsOutFogFactor = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float1 ); if ( this.vsOutFogFactor == null ) { return false; } //Resolve pixel shader input fog factor this.psInFogFactor = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutFogFactor.Index, this.vsOutFogFactor.Content, GpuProgramParameters.GpuConstantType.Float1 ); if ( this.psInFogFactor == null ) { return false; } } return true; }
protected override bool ResolveDependencies( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; vsProgram.AddDependency( FFPRenderState.FFPLibCommon ); vsProgram.AddDependency( SGXLibPerPixelLighting ); psProgram.AddDependency( FFPRenderState.FFPLibCommon ); psProgram.AddDependency( SGXLibPerPixelLighting ); return true; }
protected override bool ResolveDependencies( ProgramSet programSet ) { if ( this.fogMode == FogMode.None ) { return true; } Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; vsProgram.AddDependency( FFPRenderState.FFPLibFog ); psProgram.AddDependency( FFPRenderState.FFPLibCommon ); //Per pixel fog. if ( this.calcMode == CalcMode.PerPixel ) { psProgram.AddDependency( FFPRenderState.FFPLibFog ); } return true; }
protected override bool ResolveParameters( ProgramSet programSet ) { //resolve parameter for normal texturing procedures bool isSuccess = base.ResolveParameters( programSet ); if ( isSuccess ) { //resolve source modification parameters Program psProgram = programSet.CpuFragmentProgram; for ( int i = this.textureBlends.Count - 1; i >= 0; i-- ) { TextureBlend texBlend = this.textureBlends[ i ]; if ( ( texBlend.SourceModifier != SourceModifier.Invalid ) && ( texBlend.SourceModifier != SourceModifier.None ) ) { texBlend.ModControlParam = psProgram.ResolveAutoParameterInt( Graphics.GpuProgramParameters.AutoConstantType.Custom, texBlend.CustomNum ); if ( texBlend.ModControlParam == null ) { isSuccess = false; break; } } } } return isSuccess; }
protected override bool AddFunctionInvocations( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; int internalCounter = 0; for ( int i = 0; i < this.textureUnitParamsList.Count; i++ ) { TextureUnitParams curParams = this.textureUnitParamsList[ i ]; if ( !AddVSFunctionInvocations( curParams, vsMain ) ) { return false; } if ( !AddPSFunctionInvocations( curParams, psMain, ref internalCounter ) ) { return false; } } return true; }
internal override bool AddFunctionInvocations( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Function vsMain = vsProgram.EntryPointFunction; int internalCounter = 0; //add functions to calculate position data in wold, object and projective space AddPositionCalculations( vsMain, ref internalCounter ); //add functions to calculate normal and normal related data in world and object space AddNormalRelatedCalculations( vsMain, paramInNormal, paramLocalNormalWorld, ref internalCounter ); AddNormalRelatedCalculations( vsMain, paramInTangent, paramLocalTangentWorld, ref internalCounter ); AddNormalRelatedCalculations( vsMain, paramInBiNormal, paramLocalBiNormalWorld, ref internalCounter ); return true; }
private bool CreateGpuPrograms( ProgramSet programSet ) { // Before we start we need to make sure that the pixel shader input // parameters are the same as the vertex output, this required by // shader models 4 and 5. // This change may incrase the number of register used in older shader // models - this is why the check is present here. bool isVs4 = GpuProgramManager.Instance.IsSyntaxSupported( "vs_4_0" ); if ( isVs4 ) { SynchronizePixelnToBeVertexOut( programSet ); } //Grab the matching writer string language = ShaderGenerator.Instance.TargetLangauge; ProgramWriter programWriter = null; if ( this.programWritersMap.ContainsKey( language ) ) { programWriter = this.programWritersMap[ language ]; } else { programWriter = ProgramWriterManager.Instance.CreateProgramWriter( language ); this.programWritersMap.Add( language, programWriter ); } ProgramProcessor programProcessor = null; if ( this.programProcessorMap.ContainsKey( language ) == false ) { throw new AxiomException( "Could not find processor for language " + language ); } programProcessor = this.programProcessorMap[ language ]; bool success; //Call the pre creation of GPU programs method success = programProcessor.PreCreateGpuPrograms( programSet ); if ( success == false ) { return false; } //Create the vertex shader program GpuProgram vsGpuProgram; vsGpuProgram = CreateGpuProgram( programSet.CpuVertexProgram, programWriter, language, ShaderGenerator.Instance.VertexShaderProfiles, ShaderGenerator.Instance.VertexShaderProfilesList, ShaderGenerator.Instance.ShaderChachePath ); if ( vsGpuProgram == null ) { return false; } programSet.GpuVertexProgram = vsGpuProgram; //update flags programSet.GpuVertexProgram.IsSkeletalAnimationIncluded = programSet.CpuVertexProgram.SkeletalAnimationIncluded; //Create the fragment shader program. GpuProgram psGpuProgram; psGpuProgram = CreateGpuProgram( programSet.CpuFragmentProgram, programWriter, language, ShaderGenerator.Instance.FragmentShaderProfiles, ShaderGenerator.Instance.FragmentShaderProfilesList, ShaderGenerator.Instance.ShaderChachePath ); if ( psGpuProgram == null ) { return false; } programSet.GpuFragmentProgram = psGpuProgram; //Call the post creation of GPU programs method. success = programProcessor.PostCreateGpuPrograms( programSet ); if ( success == false ) { return false; } return true; }
private bool ResolveUniformParams( TextureUnitParams textureUnitParams, ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; //Resolve texture sampler parameter. textureUnitParams.TextureSampler = psProgram.ResolveParameter( textureUnitParams.TextureSamplerType, textureUnitParams.TextureSamplerIndex, GpuProgramParameters.GpuParamVariability. Global, "gTextureSampler" ); if ( textureUnitParams.TextureSampler == null ) { return false; } //Resolve texture matrix parameter if ( NeedsTextureMatrix( textureUnitParams.TextureUnitState ) ) { textureUnitParams.TextureMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.TextureMatrix, textureUnitParams.TextureSamplerIndex ); if ( textureUnitParams.TextureMatrix == null ) { return false; } } switch ( textureUnitParams.TexCoordCalcMethod ) { case TexCoordCalcMethod.None: break; case TexCoordCalcMethod.EnvironmentMap: case TexCoordCalcMethod.EnvironmentMapNormal: case TexCoordCalcMethod.EnvironmentMapPlanar: 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; } break; case TexCoordCalcMethod.EnvironmentMapReflection: 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; } break; case TexCoordCalcMethod.ProjectiveTexture: this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 ); if ( this.worldMatrix == null ) { return false; } textureUnitParams.TextureViewProjImageMatrix = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1, GpuProgramParameters.GpuParamVariability.Lights, "gTexViewProjImageMatrix" ); if ( textureUnitParams.TextureViewProjImageMatrix == null ) { return false; } var effects = new List<TextureEffect>(); for ( int i = 0; i < textureUnitParams.TextureUnitState.NumEffects; i++ ) { var curEffect = textureUnitParams.TextureUnitState.GetEffect( i ); effects.Add( curEffect ); } foreach ( var effi in effects ) { if ( effi.type == TextureEffectType.ProjectiveTexture ) { textureUnitParams.TextureProjector = effi.frustum; break; } } if ( textureUnitParams.TextureProjector == null ) { return false; } break; } return true; }
protected override bool ResolveParameters( ProgramSet programSet ) { if ( ResolveGlobalParameters( programSet ) == false ) { return false; } if ( ResolveParameters( programSet ) == false ) { return false; } return true; }
internal override bool ResolveParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Function vsMain = vsProgram.EntryPointFunction; //if needed mark this vertex program as hardware skinned if ( DoBoneCalculations ) { vsProgram.SkeletalAnimationIncluded = true; } //get the parameters we need whther we are doing bone calculations or not //note in order t be consistent we will always output position, normal, //tangent, and binormal in both object and world space. And output position //in projective space to cover the responsibility of the transform stage //input param paramInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); paramInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3 ); paramInBiNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Binormal, 0, Parameter.ContentType.BinormalObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3 ); paramInTangent = vsMain.ResolveInputParameter( Parameter.SemanticType.Tangent, 0, Parameter.ContentType.TangentObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3 ); //local param paramLocalPositionWorld = vsMain.ResolveLocalParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); paramLocalNormalWorld = vsMain.ResolveLocalParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3 ); paramLocalTangentWorld = vsMain.ResolveLocalParameter( Parameter.SemanticType.Tangent, 0, Parameter.ContentType.TangentWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3 ); paramLocalBiNormalWorld = vsMain.ResolveLocalParameter( Parameter.SemanticType.Binormal, 0, Parameter.ContentType.BinormalWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3 ); //output param paramOutPositionProj = vsMain.ResolveOutputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionProjectiveSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); //check if parameter retrieval went well bool isValid = ( paramInPosition != null && paramInNormal != null && paramInBiNormal != null && paramInTangent != null && paramLocalPositionWorld != null && paramLocalNormalWorld != null && paramLocalTangentWorld != null && paramLocalBiNormalWorld != null && paramOutPositionProj != null ); if ( doBoneCalculations ) { GpuProgramParameters.AutoConstantType worldMatrixType = GpuProgramParameters.AutoConstantType.WorldMatrixArray3x4; if ( ShaderGenerator.Instance.TargetLangauge == "hlsl" ) { //given that hlsl shaders use column major matrices which are not compatible with the cg //and glsl method of row major matrices, we will use a full matrix instead worldMatrixType = GpuProgramParameters.AutoConstantType.WorldMatrixArray; } //input parameters paramInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); paramInBiNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Binormal, 0, Parameter.ContentType.BinormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); paramInTangent = vsMain.ResolveInputParameter( Parameter.SemanticType.Tangent, 0, Parameter.ContentType.TangentObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); paramInIndices = vsMain.ResolveInputParameter( Parameter.SemanticType.BlendIndicies, 0, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4 ); paramInWeights = vsMain.ResolveInputParameter( Parameter.SemanticType.BlendWeights, 0, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4 ); paramInWorldMatrices = vsProgram.ResolveAutoParameterInt( worldMatrixType, 0, boneCount ); paramInInvWorldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.InverseWorldMatrix, 0 ); paramInViewProjMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.ViewProjMatrix, 0 ); paramTempFloat4 = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, -1, "TempVal4", GpuProgramParameters.GpuConstantType.Float3 ); paramTempFloat3 = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, -1, "TempVal3", GpuProgramParameters.GpuConstantType.Float3 ); //check if parameter retrival went well isValid &= ( paramInIndices != null && paramInWeights != null && paramInWorldMatrices != null && paramInViewProjMatrix != null && paramInInvWorldMatrix != null && paramTempFloat4 != null && paramTempFloat3 != null ); } else { paramInWorldMatrices = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 ); paramInWorldViewProjMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0 ); //check if parameter retrieval went well isValid &= ( paramInWorldMatrix != null && paramInWorldViewProjMatrix != null ); } return isValid; }
protected bool ResolvePerLightParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; //Resolve per light parameters for ( int i = 0; i < this.lightParamsList.Count; i++ ) { switch ( this.lightParamsList[ i ].Type ) { case LightType.Directional: this.lightParamsList[ i ].Direction = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_direction_view_space" ); if ( this.lightParamsList[ i ].Direction == null ) { return false; } break; case LightType.Point: this.worldViewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 ); if ( this.worldViewMatrix == null ) { return false; } this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } this.lightParamsList[ i ].Position = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_position_view_space" ); if ( this.lightParamsList[ i ].Position == null ) { return false; } this.lightParamsList[ i ].AttenuatParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_attenuation" ); if ( this.lightParamsList[ i ].AttenuatParams == null ) { return false; } if ( this.vsOutViewPos == null ) { this.vsOutViewPos = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.PositionViewSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsOutViewPos == null ) { return false; } this.psInViewPos = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutViewPos.Index, this.vsOutViewPos.Content, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.psInViewPos == null ) { return false; } } break; case LightType.Spotlight: this.worldViewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 ); if ( this.worldViewMatrix == null ) { return false; } this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } this.lightParamsList[ i ].Position = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_position_view_space" ); if ( this.lightParamsList[ i ].Position == null ) { return false; } this.lightParamsList[ i ].Direction = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_direction_view_space" ); if ( this.lightParamsList[ i ].Direction == null ) { return false; } this.lightParamsList[ i ].AttenuatParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_attenuation" ); if ( this.lightParamsList[ i ].AttenuatParams == null ) { return false; } this.lightParamsList[ i ].SpotParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float3, -1, GpuProgramParameters.GpuParamVariability.Lights, "spotlight_params" ); if ( this.lightParamsList[ i ].SpotParams == null ) { return false; } if ( this.vsOutViewPos == null ) { this.vsOutViewPos = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.PositionViewSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsOutViewPos == null ) { return false; } this.psInViewPos = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutViewPos.Index, this.vsOutViewPos.Content, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.psInViewPos == null ) { return false; } } break; } //Resolve diffuse color if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 ) { this.lightParamsList[ i ].DiffuseColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights | GpuProgramParameters.GpuParamVariability.Global, "derived_light_diffuse" ); if ( this.lightParamsList[ i ].DiffuseColor == null ) { return false; } } else { this.lightParamsList[ i ].DiffuseColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_diffuse" ); if ( this.lightParamsList[ i ].DiffuseColor == null ) { return false; } } if ( this.specularEnable ) { //Resolve specular color if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 ) { this.lightParamsList[ i ].SpecularColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights | GpuProgramParameters.GpuParamVariability.Global, "derived_light_specular" ); if ( this.lightParamsList[ i ].SpecularColor == null ) { return false; } } else { this.lightParamsList[ i ].SpecularColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_specular" ); if ( this.lightParamsList[ i ].SpecularColor == null ) { return false; } } } } return true; }
private bool ResolvePerLightParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; for ( int i = 0; i < this.lightParamsList.Count; i++ ) { switch ( this.lightParamsList[ i ].Type ) { case LightType.Directional: this.lightParamsList[ i ].Direction = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.PerObject, "light_direction_obj_space" ); if ( this.lightParamsList[ i ].Direction == null ) { return false; } Parameter.ContentType pctToUse; if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { switch ( i ) { case 0: pctToUse = Parameter.ContentType.LightDirectionTangentSpace0; break; case 1: pctToUse = Parameter.ContentType.LightDirectionTangentSpace1; break; case 2: pctToUse = Parameter.ContentType.LightDirectionTangentSpace2; break; case 3: pctToUse = Parameter.ContentType.LightDirectionTangentSpace3; break; case 4: pctToUse = Parameter.ContentType.LightDirectionTangentSpace4; break; case 5: pctToUse = Parameter.ContentType.LightDirectionTangentSpace5; break; case 6: pctToUse = Parameter.ContentType.LightDirectionTangentSpace6; break; default: throw new AxiomException( "Index out of range" ); } this.lightParamsList[ i ].VSOutDirection = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, pctToUse, GpuProgramParameters.GpuConstantType.Float3 ); } else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { switch ( i ) { case 0: pctToUse = Parameter.ContentType.LightDirectionTangentSpace0; break; case 1: pctToUse = Parameter.ContentType.LightDirectionTangentSpace1; break; case 2: pctToUse = Parameter.ContentType.LightDirectionObjectSpace2; break; case 3: pctToUse = Parameter.ContentType.LightDirectionObjectSpace3; break; case 4: pctToUse = Parameter.ContentType.LightDirectionObjectSpace4; break; case 5: pctToUse = Parameter.ContentType.LightDirectionObjectSpace5; break; case 6: pctToUse = Parameter.ContentType.LightDirectionObjectSpace6; break; default: throw new AxiomException( "Index out of range" ); } this.lightParamsList[ i ].VSOutToLightDir = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, pctToUse, GpuProgramParameters.GpuConstantType.Float3 ); } if ( this.lightParamsList[ i ].VSOutToLightDir == null ) { return false; } this.lightParamsList[ i ].PSInDirection = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.lightParamsList[ i ].VSOutToLightDir.Index, this.lightParamsList[ i ].VSOutToLightDir.Content, this.lightParamsList[ i ].VSOutToLightDir.Type ); if ( this.lightParamsList[ i ].PSInDirection == null ) { return false; } break; case LightType.Point: this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } this.lightParamsList[ i ].Position = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights | GpuProgramParameters.GpuParamVariability.PerObject, "light_position_world_space" ); if ( this.lightParamsList[ i ].Position == null ) { return false; } if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { this.lightParamsList[ i ].VSOutToLightDir = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, IntToEnum( RTShaderSystem.NormalMapSpace.Tangent, i ), GpuProgramParameters.GpuConstantType.Float3 ); } else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { this.lightParamsList[ i ].VSOutToLightDir = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, IntToEnum( RTShaderSystem.NormalMapSpace.Object, i ), GpuProgramParameters.GpuConstantType.Float3 ); } if ( this.lightParamsList[ i ].VSOutToLightDir == null ) { return false; } this.lightParamsList[ i ].PSInToLightDir = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.lightParamsList[ i ].VSOutToLightDir.Index, this.lightParamsList[ i ].VSOutToLightDir.Content, this.lightParamsList[ i ].VSOutToLightDir.Type ); if ( this.lightParamsList[ i ].PSInToLightDir == null ) { return false; } this.lightParamsList[ i ].AttenuatParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_attenuation" ); if ( this.lightParamsList[ i ].AttenuatParams == null ) { return false; } //Resolve local dir if ( this.vsLocalDir == null ) { this.vsLocalDir = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lNormalMapTempDir", GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsLocalDir == null ) { return false; } } //Resolve world position if ( this.vsWorldPosition == null ) { this.vsWorldPosition = vsMain.ResolveLocalParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionWorldSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsWorldPosition == null ) { return false; } } //resolve world matrix if ( this.worldMatrix == null ) { this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 ); if ( this.worldMatrix == null ) { return false; } } //resolve inverse world rotation matrix if ( this.worldInvRotMatrix == null ) { this.worldInvRotMatrix = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1, GpuProgramParameters.GpuParamVariability.PerObject, "inv_world_rotation_matrix" ); if ( this.worldInvRotMatrix == null ) { return false; } } break; case LightType.Spotlight: this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInPosition == null ) { return false; } this.lightParamsList[ i ].Position = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights | GpuProgramParameters.GpuParamVariability.PerObject, "light_position_world_space" ); if ( this.lightParamsList[ i ].Position == null ) { return false; } if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { this.lightParamsList[ i ].VSOutToLightDir = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, IntToEnum( RTShaderSystem.NormalMapSpace.Tangent, i ), GpuProgramParameters.GpuConstantType.Float3 ); } if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { this.lightParamsList[ i ].VSOutToLightDir = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, IntToEnum( RTShaderSystem.NormalMapSpace.Object, i ), GpuProgramParameters.GpuConstantType.Float3 ); } if ( this.lightParamsList[ i ].VSOutToLightDir == null ) { return false; } this.lightParamsList[ i ].PSInToLightDir = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.lightParamsList[ i ].VSOutToLightDir.Index, this.lightParamsList[ i ].VSOutToLightDir.Content, this.lightParamsList[ i ].VSOutToLightDir.Type ); if ( this.lightParamsList[ i ].PSInToLightDir == null ) { return false; } this.lightParamsList[ i ].Direction = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights | GpuProgramParameters.GpuParamVariability.PerObject, "light_direction_obj_space" ); if ( this.lightParamsList[ i ].Direction == null ) { return false; } if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { this.lightParamsList[ i ].VSOutDirection = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, IntToEnum( RTShaderSystem.NormalMapSpace.Tangent, i ), GpuProgramParameters.GpuConstantType.Float3 ); if ( this.lightParamsList[ i ].VSOutDirection == null ) { return false; } } else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { this.lightParamsList[ i ].VSOutDirection = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, IntToEnum( RTShaderSystem.NormalMapSpace.Object, i ), GpuProgramParameters.GpuConstantType.Float3 ); if ( this.lightParamsList[ i ].VSOutDirection == null ) { return false; } } if ( this.lightParamsList[ i ].VSOutDirection == null ) { return false; } this.lightParamsList[ i ].PSInDirection = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.lightParamsList[ i ].VSOutDirection.Index, this.lightParamsList[ i ].VSOutDirection.Content, this.lightParamsList[ i ].VSOutDirection.Type ); if ( this.lightParamsList[ i ].PSInDirection == null ) { return false; } this.lightParamsList[ i ].AttenuatParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_attenuation" ); if ( this.lightParamsList[ i ].AttenuatParams == null ) { return false; } this.lightParamsList[ i ].SpotParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float3, -1, GpuProgramParameters.GpuParamVariability.Lights, "spotlight_params" ); if ( this.lightParamsList[ i ].SpotParams == null ) { return false; } //Resolve local dir if ( this.vsLocalDir == null ) { this.vsLocalDir = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lNormalMapTempDir", GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsLocalDir == null ) { return false; } } //resolve world postion if ( this.vsWorldPosition == null ) { this.vsWorldPosition = vsMain.ResolveLocalParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionWorldSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsWorldPosition == null ) { return false; } } //resolve world matrix if ( this.worldMatrix == null ) { this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 ); if ( this.worldMatrix == null ) { return false; } } //resovle inverse world rotation matrix if ( this.worldInvRotMatrix == null ) { this.worldInvRotMatrix = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1, GpuProgramParameters.GpuParamVariability.PerObject, "inv_world_rotation_matrix" ); if ( this.worldInvRotMatrix == null ) { return false; } } break; } //resolve diffuse color if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 ) { this.lightParamsList[ i ].DiffuseColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "derived_light_diffuse" ); if ( this.lightParamsList[ i ].DiffuseColor == null ) { return false; } } else { this.lightParamsList[ i ].DiffuseColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_diffuse" ); if ( this.lightParamsList[ i ].DiffuseColor == null ) { return false; } } if ( this.specularEnabled ) { //resolve specular color if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 ) { this.lightParamsList[ i ].SpecularColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "derived_light_specular" ); if ( this.lightParamsList[ i ].SpecularColor == null ) { return false; } } else { this.lightParamsList[ i ].SpecularColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Lights, "light_specular" ); if ( this.lightParamsList[ i ].SpecularColor == null ) { return false; } } } } return true; }
protected override bool AddFunctionInvocations( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; int internalCounter = 0; //Add the global illumination functions. if ( AddVSInvocation( vsMain, (int)FFPRenderState.FFPVertexShaderStage.VSLighting, ref internalCounter ) == false ) { return false; } internalCounter = 0; //Add the global illumination fuctnions if ( AddPSGlobalIlluminationInvocation( psMain, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin + 1, ref internalCounter ) == false ) { return false; } //Add per light functions for ( int i = 0; i < this.lightParamsList.Count; i++ ) { if ( AddPSIlluminationInvocation( this.lightParamsList[ i ], psMain, -1, ref internalCounter ) == false ) { return false; } } //Assign back temporary variables to the ps diffuse and specular components. if ( AddPSFinalAssignmentInvocation( psMain, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin + 1, ref internalCounter ) == false ) { return false; } return true; }
protected override bool ResolveParameters( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; bool success = ( this.resolveStageFlags & (int)StageFlags.VsInputDiffuse ) == 1; if ( success ) { this.vsInputDiffuse = vsMain.ResolveInputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); } success = ( this.resolveStageFlags & (int)StageFlags.VsInputSpecular ) == 1; if ( success ) { this.vsInputSpecular = vsMain.ResolveInputParameter( Parameter.SemanticType.Color, 1, Parameter.ContentType.ColorSpecular, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); } //Resolve VS color outputs if have inputs from vertex stream if ( this.vsInputDiffuse != null || ( this.resolveStageFlags & (int)StageFlags.VsOutputdiffuse ) == 1 ) { this.vsOutputDiffuse = vsMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); } if ( this.vsInputSpecular != null || ( this.resolveStageFlags & (int)StageFlags.VsOutputSpecular ) == 1 ) { this.vsOutputSpecular = vsMain.ResolveOutputParameter( Parameter.SemanticType.Color, 1, Parameter.ContentType.ColorSpecular, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); } //Resolve PS color inputs if we have inputs from vertex shader. if ( this.vsOutputDiffuse != null || ( this.resolveStageFlags & (int)StageFlags.PsInputDiffuse ) == 1 ) { this.psInputDiffuse = psMain.ResolveInputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); } if ( this.vsOutputSpecular != null || ( this.resolveStageFlags & (int)StageFlags.PsInputSpecular ) == 1 ) { this.psInputDiffuse = psMain.ResolveInputParameter( Parameter.SemanticType.Color, 1, Parameter.ContentType.ColorSpecular, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); } //Resolve PS output diffuse color if ( ( this.resolveStageFlags & (int)StageFlags.PsOutputDiffuse ) == 1 ) { this.psOutputDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psOutputDiffuse == null ) { return false; } } //Resolve PS output specular color if ( ( this.resolveStageFlags & (int)StageFlags.PsOutputSpecular ) == 1 ) { this.psOutputSpecular = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 1, Parameter.ContentType.ColorSpecular, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psOutputSpecular == null ) { return false; } } return true; }
protected override bool ResolveDependencies( ProgramSet programSet ) { base.ResolveDependencies( programSet ); Program psProgram = programSet.CpuFragmentProgram; psProgram.AddDependency( SGXLibLayeredBlending ); return true; }
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); }
internal override bool ResolveParameters(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Function vsMain = vsProgram.EntryPointFunction; //if needed mark this vertex program as hardware skinned if (DoBoneCalculations) { vsProgram.SkeletalAnimationIncluded = true; } //get the parameters we need whther we are doing bone calculations or not //note in order t be consistent we will always output position, normal, //tangent, and binormal in both object and world space. And output position //in projective space to cover the responsibility of the transform stage //input param paramInPosition = vsMain.ResolveInputParameter(Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4); paramInNormal = vsMain.ResolveInputParameter(Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3); paramInBiNormal = vsMain.ResolveInputParameter(Parameter.SemanticType.Binormal, 0, Parameter.ContentType.BinormalObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3); paramInTangent = vsMain.ResolveInputParameter(Parameter.SemanticType.Tangent, 0, Parameter.ContentType.TangentObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3); //local param paramLocalPositionWorld = vsMain.ResolveLocalParameter(Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4); paramLocalNormalWorld = vsMain.ResolveLocalParameter(Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3); paramLocalTangentWorld = vsMain.ResolveLocalParameter(Parameter.SemanticType.Tangent, 0, Parameter.ContentType.TangentWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3); paramLocalBiNormalWorld = vsMain.ResolveLocalParameter(Parameter.SemanticType.Binormal, 0, Parameter.ContentType.BinormalWorldSpace, Graphics.GpuProgramParameters.GpuConstantType.Float3); //output param paramOutPositionProj = vsMain.ResolveOutputParameter(Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionProjectiveSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4); //check if parameter retrieval went well bool isValid = (paramInPosition != null && paramInNormal != null && paramInBiNormal != null && paramInTangent != null && paramLocalPositionWorld != null && paramLocalNormalWorld != null && paramLocalTangentWorld != null && paramLocalBiNormalWorld != null && paramOutPositionProj != null); if (doBoneCalculations) { GpuProgramParameters.AutoConstantType worldMatrixType = GpuProgramParameters.AutoConstantType.WorldMatrixArray3x4; if (ShaderGenerator.Instance.TargetLangauge == "hlsl") { //given that hlsl shaders use column major matrices which are not compatible with the cg //and glsl method of row major matrices, we will use a full matrix instead worldMatrixType = GpuProgramParameters.AutoConstantType.WorldMatrixArray; } //input parameters paramInNormal = vsMain.ResolveInputParameter(Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3); paramInBiNormal = vsMain.ResolveInputParameter(Parameter.SemanticType.Binormal, 0, Parameter.ContentType.BinormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3); paramInTangent = vsMain.ResolveInputParameter(Parameter.SemanticType.Tangent, 0, Parameter.ContentType.TangentObjectSpace, GpuProgramParameters.GpuConstantType.Float3); paramInIndices = vsMain.ResolveInputParameter(Parameter.SemanticType.BlendIndicies, 0, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4); paramInWeights = vsMain.ResolveInputParameter(Parameter.SemanticType.BlendWeights, 0, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4); paramInWorldMatrices = vsProgram.ResolveAutoParameterInt(worldMatrixType, 0, boneCount); paramInInvWorldMatrix = vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.InverseWorldMatrix, 0); paramInViewProjMatrix = vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.ViewProjMatrix, 0); paramTempFloat4 = vsMain.ResolveLocalParameter(Parameter.SemanticType.Unknown, -1, "TempVal4", GpuProgramParameters.GpuConstantType.Float3); paramTempFloat3 = vsMain.ResolveLocalParameter(Parameter.SemanticType.Unknown, -1, "TempVal3", GpuProgramParameters.GpuConstantType.Float3); //check if parameter retrival went well isValid &= (paramInIndices != null && paramInWeights != null && paramInWorldMatrices != null && paramInViewProjMatrix != null && paramInInvWorldMatrix != null && paramTempFloat4 != null && paramTempFloat3 != null); } else { paramInWorldMatrices = vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.WorldMatrix, 0); paramInWorldViewProjMatrix = vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0); //check if parameter retrieval went well isValid &= (paramInWorldMatrix != null && paramInWorldViewProjMatrix != null); } return(isValid); }
private bool ResolveFunctionsParams( TextureUnitParams curParams, ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; Parameter.ContentType texCoordContent = Parameter.ContentType.Unknown; switch ( curParams.TexCoordCalcMethod ) { case TexCoordCalcMethod.None: //Resolve explicit vs input texture coordinates if ( curParams.TextureMatrix == null ) { switch ( curParams.TextureUnitState.TextureCoordSet ) { case 0: texCoordContent = Parameter.ContentType.TextureCoordinate0; break; case 1: texCoordContent = Parameter.ContentType.TextureCoordinate1; break; case 2: texCoordContent = Parameter.ContentType.TextureCoordinate2; break; case 3: texCoordContent = Parameter.ContentType.TextureCoordinate3; break; case 4: texCoordContent = Parameter.ContentType.TextureCoordinate4; break; case 5: texCoordContent = Parameter.ContentType.TextureCoordinate5; break; case 6: texCoordContent = Parameter.ContentType.TextureCoordinate6; break; case 7: texCoordContent = Parameter.ContentType.TextureCoordinate7; break; } } Parameter.ContentType texCoordToUse = Parameter.ContentType.TextureCoordinate0; switch ( curParams.TextureUnitState.TextureCoordSet ) { case 0: texCoordToUse = Parameter.ContentType.TextureCoordinate0; break; case 1: texCoordToUse = Parameter.ContentType.TextureCoordinate1; break; case 2: texCoordToUse = Parameter.ContentType.TextureCoordinate2; break; case 3: texCoordToUse = Parameter.ContentType.TextureCoordinate3; break; case 4: texCoordToUse = Parameter.ContentType.TextureCoordinate4; break; case 5: texCoordToUse = Parameter.ContentType.TextureCoordinate5; break; case 6: texCoordToUse = Parameter.ContentType.TextureCoordinate6; break; case 7: texCoordToUse = Parameter.ContentType.TextureCoordinate7; break; } curParams.VSInputTexCoord = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, curParams.TextureUnitState.TextureCoordSet, texCoordToUse, curParams.VSInTextureCoordinateType ); if ( curParams.VSInputTexCoord == null ) { return false; } break; case TexCoordCalcMethod.EnvironmentMap: case TexCoordCalcMethod.EnvironmentMapNormal: case TexCoordCalcMethod.EnvironmentMapPlanar: //Resolve vertex normal this.vsInputNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsInputNormal == null ) { return false; } break; case TexCoordCalcMethod.EnvironmentMapReflection: //Resolve vertex normal this.vsInputNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0, Parameter.ContentType.NormalObjectSpace, GpuProgramParameters.GpuConstantType.Float3 ); if ( this.vsInputNormal == null ) { return false; } //Resovle vertex position this.vsInputPos = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInputPos == null ) { return false; } break; case TexCoordCalcMethod.ProjectiveTexture: //Resolve vertex position this.vsInputPos = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.vsInputPos == null ) { return false; } break; } //Resolve vs output texture coordinates curParams.PSInputTexCoord = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, curParams.VSOutputTexCoord.Index, curParams.VSOutputTexCoord.Content, curParams.VSOutTextureCoordinateType ); if ( curParams.PSInputTexCoord == null ) { return false; } var inputParams = psMain.InputParameters; var localParams = psMain.LocalParameters; this.psDiffuse = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psDiffuse == null ) { this.psDiffuse = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorDiffuse, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psDiffuse == null ) { return false; } } this.psSpecular = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorSpecular, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psSpecular == null ) { this.psSpecular = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorSpecular, GpuProgramParameters.GpuConstantType.Float4 ); if ( this.psSpecular == 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; }