public bool CreateCpuPrograms() { SortSubRenderStates(); ProgramSet cProgramSet = CreateProgramSet(); Program vsProgram = ProgramManager.Instance.CreateCpuProgram(GpuProgramType.Vertex); Program psProgram = ProgramManager.Instance.CreateCpuProgram(GpuProgramType.Fragment); Function vsMainFunc = null; Function psMainFunc = null; cProgramSet.CpuVertexProgram = vsProgram; cProgramSet.CpuFragmentProgram = psProgram; //Create entry point functions vsMainFunc = vsProgram.CreateFunction("main", "Vertex Program Entry point", Function.FunctionType.VsMain); vsProgram.EntryPointFunction = vsMainFunc; psMainFunc = psProgram.CreateFunction("main", "Pixel Program Entry point", Function.FunctionType.PsMain); psProgram.EntryPointFunction = psMainFunc; for (int i = 0; i < SubRenderStateList.Count; i++) { SubRenderState srcSubRenderState = SubRenderStateList[i]; if (srcSubRenderState.CreateCpuSubPrograms(this.programSet) == false) { Axiom.Core.LogManager.Instance.Write( "RTShader.TargetRenderState: Could not generate sub render program of type: {0}", srcSubRenderState.Type); return(false); } } return(true); }
public virtual void AddTemplateSubRenderState(SubRenderState subRenderState) { bool addSubRenderState = true; for (int i = 0; i < this.SubRenderStateList.Count; i++) { SubRenderState it = this.SubRenderStateList[i]; //Case the same instance already exists-> do not add to list if (it == subRenderState) { addSubRenderState = false; break; } //Case it is different sub render state instance with the same type, use the new sub render state, //instead of the previous sub render stet. This scenario is usually cause by material inheritance, so we use the derived material sub render state //and destroy the base sub render state else if (it.Type == subRenderState.Type) { RemoveTemplateSubRenderState(it); break; } } if (addSubRenderState) { this.SubRenderStateList.Add(subRenderState); } }
private void TranslateTextureUnit(Scripting.Compiler.ScriptCompiler compiler, AbstractNode node) { var obj = (ObjectAbstractNode)node; var texState = (TextureUnitState)obj.Parent.Context; Pass pass = texState.Parent; Technique technique = pass.Parent; Material material = technique.Parent; ShaderGenerator shaderGenerator = ShaderGenerator.Instance; string dstTechniqueSchemeName = obj.Name; bool techniqueCreated; //Make sure teh scheme is valid - use default if none exists if (dstTechniqueSchemeName == string.Empty) { dstTechniqueSchemeName = ShaderGenerator.DefaultSchemeName; } //check if technique already created techniqueCreated = shaderGenerator.HasShaderBasedTechnique(material.Name, material.Group, technique.SchemeName, dstTechniqueSchemeName); if (techniqueCreated == false) { //Create the shader based techniqe techniqueCreated = shaderGenerator.CreateShaderBasedTechnique(material.Name, material.Group, technique.SchemeName, dstTechniqueSchemeName, shaderGenerator. CreateShaderOverProgrammablePass); } if (techniqueCreated) { //Attempt to get the render state which might have been created by the pass parsing this.generatedRenderState = shaderGenerator.GetRenderState(dstTechniqueSchemeName, material.Name, material.Group, (ushort)pass.Index); //Go over all the render state properties for (int i = 0; i < obj.Children.Count; i++) { if (obj.Children[i] is PropertyAbstractNode) { var prop = obj.Children[i] as PropertyAbstractNode; SubRenderState subRenderState = ShaderGenerator.Instance.createSubRenderState(compiler, prop, texState, this); if (subRenderState != null) { AddSubRenderState(subRenderState, dstTechniqueSchemeName, material.Name, material.Group, pass.Index); } } else { processNode(compiler, obj.Children[i]); } } } }
public virtual void RemoveTemplateSubRenderState(SubRenderState subRenderState) { for (int i = 0; i < this.SubRenderStateList.Count; i++) { if (this.SubRenderStateList[i] == subRenderState) { ShaderGenerator.Instance.DestroySubRenderState(this.SubRenderStateList[i]); this.SubRenderStateList.RemoveAt(i); break; } } }
internal virtual SubRenderState CreateOrRetrieveInstance(ScriptTranslator translator) { //check if we already creaet a srs SubRenderState subRenderState = translator.GetGeneratedSubRenderState(Type); if (subRenderState == null) { //create a new sub render state subRenderState = CreateInstance(); } return(subRenderState); }
public virtual void DestroyInstance(SubRenderState subRenderState) { for (int i = 0; i < this.subRenderStateList.Count; i++) { SubRenderState it = this.subRenderStateList[i]; if (it == subRenderState) { it.Dispose(); this.subRenderStateList.Remove(it); break; } } }
protected void RemoveSubRenderStateInstance(SubRenderState subRenderState) { for (int i = 0; i < SubRenderStateList.Count; i++) { SubRenderState it = SubRenderStateList[i]; if (it == subRenderState) { ShaderGenerator.Instance.DestroySubRenderState(it); SubRenderStateList.RemoveAt(i); break; } } }
public override void WriteInstance(Serialization.MaterialSerializer ser, SubRenderState subRenderState, Pass srcPass, Pass dstPass) { //TODO //ser.WriteAttribute(4, "hardware_skinning"); //HardwareSkinning hardSkkinSrs = subRenderState as HardwareSkinning; //ser.WriteValue(hardSkkinSrs.BoneCount.ToString()); //ser.WriteValue(hardSkkinSrs.WeightCount.ToString()); ////Correct antipodality handling and scaling shearing support are only really valid for dual quaternion skinning //if (hardSkkinSrs.SkinningType == SkinningType.DualQuaternion) //{ // ser.WriteValue("dual_quaternion"); // ser.WriteValue(hardSkkinSrs.HasCorrectAntipodalityHandling.ToString()); // ser.WriteValue(hardSkkinSrs.HasScalingShearingSupport.ToString()); //} }
private void AddSubRenderState(SubRenderState newSubRenderState, string dstTechniqueSchemeName, string materialNem, string groupName, int passIndex) { //Check if a different sub render state of the same type already exists ShaderGenerator shaderGenerator = ShaderGenerator.Instance; //Create a new scheme if needed shaderGenerator.CreateScheme(dstTechniqueSchemeName); //Update the active render state this.generatedRenderState = shaderGenerator.GetRenderState(dstTechniqueSchemeName, materialNem, (ushort)passIndex); //add the new sub render state this.generatedRenderState.AddTemplateSubRenderState(newSubRenderState); }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, Scripting.Compiler.AST.PropertyAbstractNode prop, Graphics.Pass pass, SGScriptTranslator stranslator) { if (prop.Name == "fog_stage") { if (prop.Values.Count >= 1) { string strValue; if (!SGScriptTranslator.GetString(prop.Values[0], out strValue)) { //compiler.AddError(...); return(null); } if (strValue == "ffp") { SubRenderState subRenderState = CreateOrRetrieveInstance(stranslator); var fogSubRenderState = (FFPFog)subRenderState; int it = 0; if (prop.Values.Count >= 2) { it++; if (!SGScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...); return(null); } if (strValue == "per_vertex") { fogSubRenderState.CalculationMode = FFPFog.CalcMode.PerVertex; } else if (strValue == "per_pixel") { fogSubRenderState.CalculationMode = FFPFog.CalcMode.PerPixel; } } return(subRenderState); } } } return(null); }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, Scripting.Compiler.AST.PropertyAbstractNode prop, Graphics.Pass pass, SGScriptTranslator stranslator) { if (prop.Name == "integrated_pssm4") { if (prop.Values.Count != 4) { //TODO // compiler.AddError(...); } else { var splitPointList = new List <Real>(); foreach (var it in prop.Values) { Real curSplitValue; if (!SGScriptTranslator.GetReal(it, out curSplitValue)) { //TODO //compiler.AddError(...); break; } splitPointList.Add(curSplitValue); } if (splitPointList.Count == 4) { SubRenderState subRenderState = CreateOrRetrieveInstance(stranslator); var pssmSubRenderState = (IntegratedPSSM3)subRenderState; pssmSubRenderState.SetSplitPoints(splitPointList); return(pssmSubRenderState); } } } return(null); }
public override void WriteInstance(Serialization.MaterialSerializer ser, SubRenderState subRenderState, Graphics.Pass srcPass, Graphics.Pass dstPass) { throw new NotImplementedException(); var normalMapSubRenderState = (NormalMapLighting)subRenderState; //ser.WriteAtrribute(4, "lighting_stage"); //ser.WriteValue("normal_map"); //ser.WriteValue(normalMapSubRenderState.NormalMapTextureName); //if (normalMapSubRenderState.NormalMapSpace == NormalMapSpace.Tangent) //{ // ser.WriteValue("tangent_space"); //} //else if (normalMapSubRenderState.NormalMapSpace == NormalMapSpace.Object) //{ // ser.WriteValue("object_space"); //} //ser.WriteValue(normalMapSubRenderState.TexCoordIndex.ToString()); }
public ShaderSample() { this.layeredBlendingEntity = null; Metadata[ "Title" ] = "Shader System"; Metadata[ "Description" ] = "Demonstrate the capabilities of the RT Shader System component." + "1. Fixed Function Pipeline emulation." + "2. On the fly shader generation based on existing material." + "3. On the fly shader synchronization with scene state (Lights, Fog)." + "4. Built in lighting models: Per vertex, Per pixel, Normal map tangent and object space." + "5. Pluggable custom shaders extensions." + "6. Built in material script parsing that includes extended attributes." + "7. Built in material script serialization."; Metadata[ "Thumbnail" ] = "thumb_shadersystem.png"; Metadata[ "Category" ] = "Lighting"; Metadata[ "Help" ] = "F2 Toggle Shader System globally. " + "F3 Toggles Global Lighting Model. " + "Modify target model attributes and scene settings and observe the generated shaders count. " + "Press the export button in order to export current target model material. " + "The model above the target will import this material next time the sample reloads. " + "Right click on object to see the shaders it currently uses. "; this.pointLightNode = null; this.reflectionMapFactory = null; this.instancedViewportsEnable = false; this.instancedViewportsSubRenderState = null; this.instancedViewportsFactory = null; this.bbsFlare = null; this.addedLotsOfModels = false; this.numberOfModelsAdded = 0; }
public void AddSubRenderStateInstance(SubRenderState subRenderState) { base.SubRenderStateList.Add(subRenderState); this.subRenderStateSortValid = false; }
public virtual void CopyFrom( SubRenderState other ) { }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, PropertyAbstractNode prop, Graphics.Pass pass, SGScriptTranslator stranslator) { if (prop.Name == "lighting_stage") { if (prop.Values.Count >= 2) { string strValue; int it = 0; //Read light model type. if (!SGScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...) return(null); } //Case light model type is normal map if (strValue == "normal_map") { it++; if (!SGScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...) return(null); } SubRenderState subRenderState = CreateOrRetrieveInstance(stranslator); var normalMapSubRenderState = subRenderState as NormalMapLighting; normalMapSubRenderState.NormalMapTextureName = strValue; //Read normal map space type. if (prop.Values.Count >= 3) { it++; if (!SGScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...) return(null); } //Normal map defines normals in tangent space. if (strValue == "tangent_space") { normalMapSubRenderState.NormalMapSpace = NormalMapSpace.Tangent; } //Normal map defines normals in object space if (strValue == "object_space") { normalMapSubRenderState.NormalMapSpace = NormalMapSpace.Object; } } //Read texture coordinate index. if (prop.Values.Count >= 4) { int textureCoordinatesIndex = 0; it++; if (!SGScriptTranslator.GetInt(prop.Values[it], out textureCoordinatesIndex)) { normalMapSubRenderState.TexCoordIndex = textureCoordinatesIndex; } } //Read texture filtering format if (prop.Values.Count >= 5) { it++; if (!SGScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...) return(null); } if (strValue == "none") { normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Point, Graphics.FilterOptions.Point, Graphics.FilterOptions.None); } else if (strValue == "bilinear") { normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Linear, Graphics.FilterOptions.Linear, Graphics.FilterOptions.Point); } else if (strValue == "trilinear") { normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Linear, Graphics.FilterOptions.Linear, Graphics.FilterOptions.Linear); } else if (strValue == "anisotropic") { normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Anisotropic, Graphics.FilterOptions.Anisotropic, Graphics.FilterOptions.Linear); } } //Read max anisotropy value if (prop.Values.Count >= 6) { int maxAnisotropy = 0; it++; if (SGScriptTranslator.GetInt(prop.Values[it], out maxAnisotropy)) { normalMapSubRenderState.NormalMapAnisotropy = maxAnisotropy; } } //Read mip bias value. if (prop.Values.Count >= 7) { Real mipBias = 0; it++; if (SGScriptTranslator.GetReal(prop.Values[it], out mipBias)) { normalMapSubRenderState.NormalMapMipBias = mipBias; } } return(subRenderState); } } } return(null); }
public override void WriteInstance( Serialization.MaterialSerializer ser, SubRenderState subRenderState, Graphics.Pass srcPass, Graphics.Pass dstPass ) { throw new NotImplementedException(); var normalMapSubRenderState = (NormalMapLighting)subRenderState; //ser.WriteAtrribute(4, "lighting_stage"); //ser.WriteValue("normal_map"); //ser.WriteValue(normalMapSubRenderState.NormalMapTextureName); //if (normalMapSubRenderState.NormalMapSpace == NormalMapSpace.Tangent) //{ // ser.WriteValue("tangent_space"); //} //else if (normalMapSubRenderState.NormalMapSpace == NormalMapSpace.Object) //{ // ser.WriteValue("object_space"); //} //ser.WriteValue(normalMapSubRenderState.TexCoordIndex.ToString()); }
public override void WriteInstance( Serialization.MaterialSerializer ser, SubRenderState subRenderState, Pass srcPass, Pass dstPass ) { //TODO //ser.WriteAttribute(4, "rtss_ext_reflection_map"); //ReflectionMap reflectionMapSubRenderState = subRenderState as ReflectionMap; //if (reflectionMapSubRenderState.ReflectionMapType == TextureType.CubeMap) //{ // ser.WriteValue("cube_map"); //} //else if (reflectionMapSubRenderState.ReflectionMapType == TextureType.TwoD) //{ // ser.WriteValue("2d_map"); //} //ser.WriteValue(reflectionMapSubRenderState.MaskMapTextureName); //ser.WriteValue(reflectionMapSubRenderState.ReflectionMapTextureName); //ser.WriteValue(reflectionMapSubRenderState.ReflectionPower.ToString()); }
public virtual void CopyFrom(SubRenderState other) { }
public virtual void WriteInstance(MaterialSerializer ser, SubRenderState subRenderState, TextureUnitState srcTextureUnit, TextureUnitState dstTextureUnit) { }
public virtual void WriteInstance(MaterialSerializer ser, SubRenderState subRenderState, Pass srcPass, Pass dstPass) { }
public virtual void DestroyInstance( SubRenderState subRenderState ) { for ( int i = 0; i < this.subRenderStateList.Count; i++ ) { SubRenderState it = this.subRenderStateList[ i ]; if ( it == subRenderState ) { it.Dispose(); this.subRenderStateList.Remove( it ); break; } } }
public virtual void WriteInstance( MaterialSerializer ser, SubRenderState subRenderState, Pass srcPass, Pass dstPass ) { }
protected override void SetupContent() { //Setup default effects values. this.curLightingModel = ShaderSystemLightingModel.PerVertexLighting; this.perPixelFogEnable = false; this.specularEnable = false; this.reflectionMapEnable = false; this.reflectionMapSubRS = null; this.layerBlendSubRS = null; this.rayQuery = SceneManager.CreateRayQuery( new Ray() ); this.targetObj = null; //Set ambient SceneManager.AmbientLight = new ColorEx( 0.2f, 0.2f, 0.2f ); SceneManager.SetSkyBox( true, "Examples/SceneCubeMap2", 10000 ); MeshManager.Instance.CreatePlane( "Myplane", ResourceGroupManager.DefaultResourceGroupName, new Plane( Vector3.UnitY, 0 ), 1500, 1500, 25, 25, true, 1, 60, 60, Vector3.UnitZ ); Entity planeEnt = SceneManager.CreateEntity( "plane", "Myplane" ); planeEnt.MaterialName = "Examples/Rockwall"; planeEnt.CastShadows = false; SceneManager.RootSceneNode.CreateChildSceneNode( Vector3.Zero ).AttachObject( planeEnt ); //Load sample meshes an generate tangent vectors. for ( int i = 0; i < this.meshArray.Length; i++ ) { string curMeshName = this.meshArray[ i ]; Mesh mesh = MeshManager.Instance.Load( curMeshName, ResourceGroupManager.DefaultResourceGroupName, BufferUsage.DynamicWriteOnly, BufferUsage.StaticWriteOnly ); //Build tangent vectors, all our meshes use only 1 texture coordset //Note we can build into ves_tangent now (sm2+) short src, dst; if ( !mesh.SuggestTangentVectorBuildParams( out src, out dst ) ) { mesh.BuildTangentVectors( src, dst ); } } Entity entity; SceneNode childNode; //Create the main entity and mark it as the current target object entity = SceneManager.CreateEntity( MainEntityName, MainEntityMesh ); this.targetEntities.Add( entity ); childNode = SceneManager.RootSceneNode.CreateChildSceneNode(); childNode.AttachObject( entity ); this.targetObj = entity; childNode.ShowBoundingBox = true; //Create reflection entity that will show the exported material. string mainExportedMaterial = SceneManager.GetEntity( MainEntityName ).GetSubEntity( 0 ).MaterialName + "_RTSS_Export"; var matMainEnt = (Material)MaterialManager.Instance.GetByName( mainExportedMaterial ); entity = SceneManager.CreateEntity( "ExportedMaterialEntity", MainEntityMesh ); entity.GetSubEntity( 0 ).Material = matMainEnt; childNode = SceneManager.RootSceneNode.CreateChildSceneNode(); childNode.Position = new Vector3( 0, 200, -200 ); childNode.AttachObject( entity ); //Create texture layer blending demonstration entity this.layeredBlendingEntity = SceneManager.CreateEntity( "LayeredBlendingMaterialEntity", MainEntityMesh ); this.layeredBlendingEntity.MaterialName = "RTSS/LayeredBlending"; this.layeredBlendingEntity.GetSubEntity( 0 ).SetCustomParameter( 2, Vector4.Zero ); childNode = SceneManager.RootSceneNode.CreateChildSceneNode(); childNode.Position = new Vector3( 300, 200, -200 ); childNode.AttachObject( this.layeredBlendingEntity ); //Grab the render state of the material RenderState renderState = ShaderGenerator.Instance.GetRenderState( ShaderGenerator.DefaultSchemeName, "RTSS/LayeredBlending", 0 ); if ( renderState != null ) { var subRenderStateList = renderState.TemplateSubRenderStateList; for ( int i = 0; i < subRenderStateList.Count; i++ ) { SubRenderState curSubRenderState = subRenderStateList[ i ]; if ( curSubRenderState.Type == FFPTexturing.FFPType ) { this.layerBlendSubRS = curSubRenderState as LayeredBlending; break; } } } //Create per pixel lighting demo entity entity = SceneManager.CreateEntity( "PerPixelEntity", "knot.mesh" ); entity.MaterialName = "RTSS/PerPixel_SinglePass"; childNode = SceneManager.RootSceneNode.CreateChildSceneNode(); childNode.Position = new Vector3( 300, 100, -100 ); childNode.AttachObject( entity ); //Create normal map lighting demo entity entity = SceneManager.CreateEntity( "NormalMapEntity", "knot.mesh" ); entity.MaterialName = "RTSS/NormalMapping_SinglePass"; childNode = SceneManager.RootSceneNode.CreateChildSceneNode(); childNode.Position = new Vector3( -300, 100, -100 ); childNode.AttachObject( entity ); //OpenGL ES 2.0 does not support texture atlases if ( !Root.Instance.RenderSystem.Name.Contains( "OpenGL ES 2" ) ) { RenderState mainRenderState = ShaderGenerator.Instance.CreateOrRetrieveRenderState( ShaderGenerator.DefaultSchemeName ).Item1; mainRenderState.AddTemplateSubRenderState( ShaderGenerator.Instance.CreateSubRenderState( TextureAtlasSampler.SGXType ) ); //Create texture atlas object and node ManualObject atlasObject = CreateTextureAtlasObject(); childNode = SceneManager.RootSceneNode.CreateChildSceneNode(); childNode.AttachObject( atlasObject ); } CreateDirectionalLight(); CreatePointLight(); CreateSpotLight(); RenderState schemeRenderState = ShaderGenerator.Instance.GetRenderState( ShaderGenerator.DefaultSchemeName ); //take responsibility for updating the light count manually schemeRenderState.LightCountAutoUpdate = false; SetupUI(); Camera.Position = new Vector3( 0, 300, 450 ); Viewport.MaterialScheme = ShaderGenerator.DefaultSchemeName; //Mark system as on DetailsPanel.SetParamValue( 11, "On" ); // a friendly reminder var names = new List<string>(); names.Add( "Help" ); TrayManager.CreateParamsPanel( TrayLocation.TopLeft, "Help", 100, names ).SetParamValue( 0, "H/F1" ); UpdateSystemShaders(); }
private void GenerateShaders( Entity entity ) { for ( int i = 0; i < entity.SubEntityCount; i++ ) { SubEntity curSubEntity = entity.GetSubEntity( i ); string curMaterialName = curSubEntity.MaterialName; bool success; //Create the shader based technique of this material. success = ShaderGenerator.Instance.CreateShaderBasedTechnique( curMaterialName, MaterialManager.DefaultSchemeName, ShaderGenerator.DefaultSchemeName, false ); //Setup custmo shader sub render states according to current setup. if ( success ) { var curMaterial = (Material)MaterialManager.Instance.GetByName( curMaterialName ); Pass curPass = curMaterial.GetTechnique( 0 ).GetPass( 0 ); if ( this.specularEnable ) { curPass.Specular = ColorEx.White; curPass.Shininess = 32; } else { curPass.Specular = ColorEx.Beige; curPass.Shininess = 0; } // Grab the first pass render state. // NOTE: For more complicated samples iterate over the passes and build each one of them as desired. RenderState renderState = ShaderGenerator.Instance.GetRenderState( ShaderGenerator.DefaultSchemeName, curMaterialName, 0 ); //Remove all sub render states renderState.Reset(); if ( this.curLightingModel == ShaderSystemLightingModel.PerVertexLighting ) { SubRenderState perPerVertexLightModel = ShaderGenerator.Instance.CreateSubRenderState( FFPLighting.FFPType ); renderState.AddTemplateSubRenderState( perPerVertexLightModel ); } else if ( this.curLightingModel == ShaderSystemLightingModel.PerVertexLighting ) { SubRenderState perPixelLightModel = ShaderGenerator.Instance.CreateSubRenderState( PerPixelLighting.SGXType ); renderState.AddTemplateSubRenderState( perPixelLightModel ); } else if ( this.curLightingModel == ShaderSystemLightingModel.NormalMapLightingTangentSpace ) { //Apply normal map only on main entity. if ( entity.Name == MainEntityName ) { SubRenderState subRenderState = ShaderGenerator.Instance.CreateSubRenderState( NormalMapLighting.SGXType ); var normalMapSubRS = subRenderState as NormalMapLighting; normalMapSubRS.NormalMapSpace = NormalMapSpace.Tangent; normalMapSubRS.NormalMapTextureName = "Panels_Normal_Tangent.png"; renderState.AddTemplateSubRenderState( normalMapSubRS ); } //It is secondary entity -> use simple per pixel lighting else { SubRenderState perPixelLightModel = ShaderGenerator.Instance.CreateSubRenderState( PerPixelLighting.SGXType ); renderState.AddTemplateSubRenderState( perPixelLightModel ); } } else if ( this.curLightingModel == ShaderSystemLightingModel.NormalMapLightingObjectSpace ) { //Apply normal map only on main entity if ( entity.Name == MainEntityName ) { SubRenderState subRenderState = ShaderGenerator.Instance.CreateSubRenderState( NormalMapLighting.SGXType ); var normalMapSubRS = subRenderState as NormalMapLighting; normalMapSubRS.NormalMapSpace = NormalMapSpace.Object; normalMapSubRS.NormalMapTextureName = "Panels_Normal_Obj.png"; renderState.AddTemplateSubRenderState( normalMapSubRS ); } //It is secondary entity -> use simple per pixel lighting. else { SubRenderState perPixelLightModel = ShaderGenerator.Instance.CreateSubRenderState( PerPixelLighting.SGXType ); renderState.AddTemplateSubRenderState( perPixelLightModel ); } } if ( this.reflectionMapEnable ) { SubRenderState subRenderState = ShaderGenerator.Instance.CreateSubRenderState( ReflectionMap.SGXType ); var reflectMapSubRs = subRenderState as ReflectionMap; reflectMapSubRs.ReflectionMapType = TextureType.CubeMap; reflectMapSubRs.ReflectionPower = this.reflectionPowerSlider.Value; //Setup the textures needed by the reflection effect reflectMapSubRs.MaskMapTextureName = "Panels_refmask.png"; reflectMapSubRs.ReflectionMapTextureName = "cubescene.jpg"; renderState.AddTemplateSubRenderState( subRenderState ); this.reflectionMapSubRS = subRenderState; } else { this.reflectionMapSubRS = null; } //Invalidate this material in order to regen its shaders ShaderGenerator.Instance.InvalidateMaterial( ShaderGenerator.DefaultSchemeName, curMaterialName ); } } }
private void DestroyInstancedViewports() { if ( this.instancedViewportsSubRenderState != null ) { RenderState renderState = ShaderGenerator.Instance.GetRenderState( ShaderGenerator.DefaultSchemeName ); renderState.RemoveTemplateSubRenderState( this.instancedViewportsSubRenderState ); this.instancedViewportsSubRenderState = null; } if ( Root.RenderSystem.GlobalInstanceVertexBufferVertexDeclaration != null ) { //todo //HardwareBufferManager.Instance.DestroyVertexBufferBinding(Root.RenderSystem.GlobalInstanceVertexBufferVertexDeclaration); //Root.RenderSystem.GlobalInstanceVertexBufferVertexDeclaration = null; } Root.RenderSystem.GlobalNumberOfInstances = 1; //todo //Root.RenderSystem.GlobalInstanceVertexBuffer = new HardwareVertexBuffer(); ShaderGenerator.Instance.InvalidateScheme( ShaderGenerator.DefaultSchemeName ); ShaderGenerator.Instance.ValidateScheme( ShaderGenerator.DefaultSchemeName ); DestroyInstancedViewportsFactory(); }
public override void WriteInstance( Serialization.MaterialSerializer ser, SubRenderState subRenderState, Pass srcPass, Pass dstPass ) { //TODO //ser.WriteAttribute(4, "hardware_skinning"); //HardwareSkinning hardSkkinSrs = subRenderState as HardwareSkinning; //ser.WriteValue(hardSkkinSrs.BoneCount.ToString()); //ser.WriteValue(hardSkkinSrs.WeightCount.ToString()); ////Correct antipodality handling and scaling shearing support are only really valid for dual quaternion skinning //if (hardSkkinSrs.SkinningType == SkinningType.DualQuaternion) //{ // ser.WriteValue("dual_quaternion"); // ser.WriteValue(hardSkkinSrs.HasCorrectAntipodalityHandling.ToString()); // ser.WriteValue(hardSkkinSrs.HasScalingShearingSupport.ToString()); //} }
public override void WriteInstance(Serialization.MaterialSerializer ser, SubRenderState subRenderState, Graphics.Pass srcPass, Graphics.Pass dstPass) { }
private void AddSubRenderState( SubRenderState newSubRenderState, string dstTechniqueSchemeName, string materialNem, string groupName, int passIndex ) { //Check if a different sub render state of the same type already exists ShaderGenerator shaderGenerator = ShaderGenerator.Instance; //Create a new scheme if needed shaderGenerator.CreateScheme( dstTechniqueSchemeName ); //Update the active render state this.generatedRenderState = shaderGenerator.GetRenderState( dstTechniqueSchemeName, materialNem, (ushort)passIndex ); //add the new sub render state this.generatedRenderState.AddTemplateSubRenderState( newSubRenderState ); }
/// <summary> /// Link this target render state with the given render state. Only sub render states with execution order that don't exist in this render state will be added. /// </summary> /// <param name="other"> The other render state to append to this state. </param> /// <param name="srcPass"> The source pass that this render state is constructed from. </param> /// <param name="dstPass"> The destination pass that constructed from this render state </param> public void Link(RenderState other, Pass srcPass, Pass dstPass) { var customSubRenderStates = new List <SubRenderState>(); SortSubRenderStates(); //insert all custom render states. (I.E. Not FFP sub render states). var subRenderStateList = other.TemplateSubRenderStateList; for (int i = 0; i < subRenderStateList.Count; i++) { var srcSubRenderState = subRenderStateList[i]; bool isCustomRenderState = true; if (srcSubRenderState.ExecutionOrder == (int)FFPRenderState.FFPShaderStage.Transform || srcSubRenderState.ExecutionOrder == (int)FFPRenderState.FFPShaderStage.Color || srcSubRenderState.ExecutionOrder == (int)FFPRenderState.FFPShaderStage.Lighting || srcSubRenderState.ExecutionOrder == (int)FFPRenderState.FFPShaderStage.Texturing || srcSubRenderState.ExecutionOrder == (int)FFPRenderState.FFPShaderStage.Fog) { isCustomRenderState = false; } if (isCustomRenderState) { bool subStateTypeExists = false; //check if this type of render state already exist for (int j = 0; j < SubRenderStateList.Count; j++) { var itDst = SubRenderStateList[j]; if (itDst.Type == srcSubRenderState.Type) { subStateTypeExists = true; break; } } //Case custom sub render state not exists -> add it to custom list if (subStateTypeExists == false) { SubRenderState newSubRenderState = null; newSubRenderState = ShaderGenerator.Instance.CreateSubRenderState(srcSubRenderState.Type); customSubRenderStates.Add(newSubRenderState); } } } //merge the local custom sub render states for (int itSrc = 0; itSrc < customSubRenderStates.Count; itSrc++) { var customSubRenderState = customSubRenderStates[itSrc]; if (customSubRenderState.PreAddToRenderState(this, srcPass, dstPass)) { AddSubRenderStateInstance(customSubRenderState); } else { ShaderGenerator.Instance.DestroySubRenderState(customSubRenderState); } } }
public override void WriteInstance( Serialization.MaterialSerializer ser, SubRenderState subRenderState, Graphics.Pass srcPass, Graphics.Pass dstPass ) { base.WriteInstance( ser, subRenderState, srcPass, dstPass ); }
public virtual void WriteInstance( MaterialSerializer ser, SubRenderState subRenderState, TextureUnitState srcTextureUnit, TextureUnitState dstTextureUnit ) { }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, Scripting.Compiler.AST.PropertyAbstractNode prop, Pass pass, SGScriptTranslator stranslator) { if (prop.Name == "hardware_skinning") { bool hasError = false; int boneCount = 0; int weightCount = 0; string skinningType = string.Empty; SkinningType skinType = SkinningType.Linear; bool correctAntipodalityHandling = false; bool scalingShearingSupport = false; if (prop.Values.Count >= 2) { int it = 0; if (SGScriptTranslator.GetInt(prop.Values[it], out boneCount) == false) { hasError = true; } it++; if (SGScriptTranslator.GetInt(prop.Values[it], out weightCount) == false) { hasError = true; } if (prop.Values.Count >= 5) { it++; SGScriptTranslator.GetString(prop.Values[it], out skinningType); it++; SGScriptTranslator.GetBoolean(prop.Values[it], out correctAntipodalityHandling); it++; SGScriptTranslator.GetBoolean(prop.Values[it], out scalingShearingSupport); } //If the skinningType is not specified or is specified incorretly, default to linear if (skinningType == "dual_quaternion") { skinType = SkinningType.DualQuaternion; } else { skinType = SkinningType.Linear; } } if (hasError) { //TODO //compiler.AddError(...); return(null); } else { //create and update the hardware skinning sub render state SubRenderState subRenderState = CreateOrRetrieveInstance(stranslator); var hardSkinSrs = (HardwareSkinning)subRenderState; hardSkinSrs.SetHardwareSkinningParam(boneCount, weightCount, skinType, correctAntipodalityHandling, scalingShearingSupport); return(subRenderState); } } return(null); }
private void CreateInstancedViewports() { if ( this.instancedViewportsFactory == null ) { this.instancedViewportsFactory = null; // = new ShaderExInStancedViewportsFactory(); ShaderGenerator.Instance.AddSubRenderStateFactory( this.instancedViewportsFactory ); } var monitorCount = new Vector2( 2.0f, 2.0f ); this.instancedViewportsSubRenderState = ShaderGenerator.Instance.CreateSubRenderState( InstancedViewports.SGXType ); var shaderExInstancedViewports = this.instancedViewportsSubRenderState as InstancedViewports; shaderExInstancedViewports.MonitorsCount = monitorCount; RenderState renderState = ShaderGenerator.Instance.GetRenderState( ShaderGenerator.DefaultSchemeName ); renderState.AddTemplateSubRenderState( this.instancedViewportsSubRenderState ); VertexDeclaration vertexDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration(); int offset = 0; offset = vertexDeclaration.GetVertexSize( 0 ); vertexDeclaration.AddElement( 0, offset, VertexElementType.Float4, VertexElementSemantic.TexCoords, 3 ); offset = vertexDeclaration.GetVertexSize( 0 ); vertexDeclaration.AddElement( 0, offset, VertexElementType.Float4, VertexElementSemantic.TexCoords, 4 ); offset = vertexDeclaration.GetVertexSize( 0 ); vertexDeclaration.AddElement( 0, offset, VertexElementType.Float4, VertexElementSemantic.TexCoords, 5 ); offset = vertexDeclaration.GetVertexSize( 0 ); vertexDeclaration.AddElement( 0, offset, VertexElementType.Float4, VertexElementSemantic.TexCoords, 6 ); offset = vertexDeclaration.GetVertexSize( 0 ); vertexDeclaration.AddElement( 0, offset, VertexElementType.Float4, VertexElementSemantic.TexCoords, 7 ); //todo // vbuf.Unlock(); // Root.RenderSystem.GlobalInstanceVertexBuffer = vbuf; Root.RenderSystem.GlobalInstanceVertexBufferVertexDeclaration = vertexDeclaration; Root.RenderSystem.GlobalNumberOfInstances = (int)( monitorCount.x*monitorCount.y ); //Invalidate the scheme ShaderGenerator.Instance.InvalidateScheme( ShaderGenerator.DefaultSchemeName ); ShaderGenerator.Instance.ValidateScheme( ShaderGenerator.DefaultSchemeName ); }