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 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 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); }
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); }