/// <summary> /// Helper function to set the texture coordinates. Instead of taking a movie /// object, this takes a specific texture name, video size, texture size, and /// material. Sets a texture matrix to adjust the existing coordinates. /// </summary> /// <param name="textureName"> /// The name of the texture to adjust. /// </param> /// <param name="videoSize"> /// The size of the video in pixels. /// </param> /// <param name="textureSize"> /// The size of the expected texture in pixels. /// </param> /// <param name="material"> /// The name of the material to search for textures. /// </param> /// <returns> /// True if any texture coordinates were adjusted, false if not. /// </returns> public static bool SetTextureCoordinates(string textureName, Size videoSize, Size textureSize, string material) { bool ans = false; Axiom.Graphics.Material m = MaterialManager.Instance.GetByName(material); if (m != null) { for (int i = 0; i < m.NumTechniques; i++) { for (int j = 0; j < m.GetTechnique(i).NumPasses; j++) { Pass p = m.GetTechnique(i).GetPass(j); for (int k = 0; k < p.NumTextureUnitStages; k++) { if (p.GetTextureUnitState(k).TextureName == textureName) { TextureUnitState tu = p.GetTextureUnitState(k); float uRatio = ((float)videoSize.Width) / ((float)textureSize.Width); float vRatio = ((float)videoSize.Height) / ((float)textureSize.Height); tu.SetTextureScale(1.0f / uRatio, 1.0f / vRatio); tu.SetTextureScroll(-0.5f * (1.0f - uRatio), -0.5f * (1.0f - vRatio)); ans = true; } } } } } return(ans); }
public Texture() { isLoaded = false; dataX = 0; dataZ = 0; material = null; }
/// <summary> /// Default constructor. /// </summary> public SimpleRenderable() { materialName = "BaseWhite"; material = MaterialManager.Instance.GetByName("BaseWhite"); name = "SimpleRenderable" + nextAutoGenName++; material.Load(); }
public override void ClearScene() { base.ClearScene(); tiles = null; terrainMaterial = null; terrainRoot = null; }
public BspGeometry() { geometryMat = MaterialManager.Instance.GetByName("Axiom/BspGeometryMaterial"); if (geometryMat == null) { geometryMat = (Material) MaterialManager.Instance.Create("Axiom/BspGeometryMaterial"); geometryMat.ReceiveShadows = true; technique = geometryMat.GetTechnique(0); } }
public BspGeometry() { this.geometryMat = (Material)MaterialManager.Instance.GetByName( "Axiom/BspGeometryMaterial" ); if ( this.geometryMat == null ) { this.geometryMat = (Material) MaterialManager.Instance.Create( "Axiom/BspGeometryMaterial", ResourceGroupManager.Instance.WorldResourceGroupName ); this.geometryMat.ReceiveShadows = true; this.technique = this.geometryMat.GetTechnique( 0 ); } }
/// <summary> /// Helper function to replace an entity in the scene. Adjusts the /// texture coordinates to flip the video. That may be wrong on /// everything except DirectX / DirectShow. /// </summary> /// <param name="en"> /// The entity we're going to replace. /// </param> /// <param name="meshName"> /// The name of the mesh to create. /// </param> /// <param name="materialName"> /// The name of the material to create. /// </param> /// <param name="textureName"> /// The name of the texture to create. /// </param> /// <param name="videoSize"> /// The size of the movie, in width by height pixels. /// </param> /// <param name="textureSize"> /// The size of the texture, in width by height pixels. /// </param> /// <returns></returns> private static bool ReplaceEntity( Entity en, string meshName, string materialName, string textureName, Size videoSize, Size textureSize) { Mesh me = MeshManager.Instance.CreatePlane( meshName, // name new Axiom.MathLib.Plane(new Axiom.MathLib.Vector3(0, 0, -1), new Axiom.MathLib.Vector3(0, 0, 0)), videoSize.Width, videoSize.Height, 1, // xsegments 1, // ysegments true, // normals 1, // numtexcoords 1.0f, // utile 1.0f, // vtile new Axiom.MathLib.Vector3(0, 1, 0) // upvec ); en.Mesh = me; Axiom.Graphics.Material m = MaterialManager.Instance.GetByName(materialName); if (m == null) { m = (Axiom.Graphics.Material) MaterialManager.Instance.Create(materialName, true); ColorEx c = new ColorEx(1.0f, 1.0f, 1.0f); m.Ambient = c; m.Diffuse = c; for (int i = 0; i < m.GetTechnique(0).NumPasses; i++) { Pass p = m.GetTechnique(0).GetPass(i); p.RemoveAllTextureUnitStates(); p.CreateTextureUnitState(textureName); } } en.MaterialName = materialName; return(true); }
public DebugRenderable( Node parent ) { _parent = parent; string materialName = "Axiom/Debug/AxesMat"; _material = (Material)MaterialManager.Instance[ materialName ]; if ( _material == null ) { _material = (Material)MaterialManager.Instance.Create( materialName, ResourceGroupManager.InternalResourceGroupName ); Pass p = _material.GetTechnique( 0 ).GetPass( 0 ); p.LightingEnabled = false; //TODO: p.PolygonModeOverrideable = false; p.VertexColorTracking = TrackVertexColor.Ambient; p.SetSceneBlending( SceneBlendType.TransparentAlpha ); p.CullingMode = CullingMode.None; p.DepthWrite = false; } string meshName = "Axiom/Debug/AxesMesh"; _mesh = MeshManager.Instance[ meshName ]; if ( _mesh == null ) { ManualObject mo = new ManualObject( "tmp" ); mo.Begin( Material.Name, OperationType.TriangleList ); /* 3 axes, each made up of 2 of these (base plane = XY) * .------------|\ * '------------|/ */ mo.EstimateVertexCount( 7 * 2 * 3 ); mo.EstimateIndexCount( 3 * 2 * 3 ); Quaternion[] quat = new Quaternion[ 6 ]; ColorEx[] col = new ColorEx[ 3 ]; // x-axis quat[ 0 ] = Quaternion.Identity; quat[ 1 ] = Quaternion.FromAxes( Vector3.UnitX, Vector3.NegativeUnitZ, Vector3.UnitY ); col[ 0 ] = ColorEx.Red; col[ 0 ].a = 0.8f; // y-axis quat[ 2 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.NegativeUnitX, Vector3.UnitZ ); quat[ 3 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.UnitZ, Vector3.UnitX ); col[ 1 ] = ColorEx.Green; col[ 1 ].a = 0.8f; // z-axis quat[ 4 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitY, Vector3.NegativeUnitX ); quat[ 5 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitX, Vector3.UnitY ); col[ 2 ] = ColorEx.Blue; col[ 2 ].a = 0.8f; Vector3[] basepos = new Vector3[ 7 ] { // stalk new Vector3(0f, 0.05f, 0f), new Vector3(0f, -0.05f, 0f), new Vector3(0.7f, -0.05f, 0f), new Vector3(0.7f, 0.05f, 0f), // head new Vector3(0.7f, -0.15f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0.7f, 0.15f, 0f) }; // vertices // 6 arrows for ( int i = 0; i < 6; ++i ) { // 7 points for ( int p = 0; p < 7; ++p ) { Vector3 pos = quat[ i ] * basepos[ p ]; mo.Position( pos ); mo.Color( col[ i / 2 ] ); } } // indices // 6 arrows for ( int i = 0; i < 6; ++i ) { ushort baseIndex = (ushort)( i * 7 ); mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 1 ), (ushort)( baseIndex + 2 ) ); mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 2 ), (ushort)( baseIndex + 3 ) ); mo.Triangle( (ushort)( baseIndex + 4 ), (ushort)( baseIndex + 5 ), (ushort)( baseIndex + 6 ) ); } mo.End(); _mesh = mo.ConvertToMesh( meshName, ResourceGroupManager.InternalResourceGroupName ); } }
public XnaTechnique( Material parent ) : base( parent ) { }
private void selectMenu_SelectedIndexChanged( SelectMenu sender ) { if ( sender != null ) { this.currentMaterial = sender.SelectionIndex; this.activeMaterial = (Material)MaterialManager.Instance.GetByName( this.materialControlsContainer[ this.currentMaterial ].MaterialName ); this.activeMaterial.Load(); int numShaders = this.materialControlsContainer[ this.currentMaterial ].ShaderControlsCount; this.numPages = ( numShaders/ControlsPerPage ) + ( numShaders%ControlsPerPage == 0 ? 0 : 1 ); ChangePage( 0 ); if ( this.oceanSurfaceEnt != null ) { this.oceanSurfaceEnt.MaterialName = this.materialControlsContainer[ this.currentMaterial ].MaterialName; } } }
public void UpdateMaterial(Material material) { if (useParams) { Pass pass = material.GetTechnique(0).GetPass(0); pass.GetTextureUnitState(0).SetTextureName(sandTextureName); pass.GetTextureUnitState(1).SetTextureName(grassTextureName); pass.GetTextureUnitState(2).SetTextureName(rockTextureName); pass.GetTextureUnitState(3).SetTextureName(snowTextureName); GpuProgramParameters vertexParams = pass.VertexProgramParameters; vertexParams.SetNamedConstant("splatConfig", new Vector3(sandToGrassHeight, grassToRockHeight, rockToSnowHeight)); vertexParams.SetNamedConstant("textureTileSize", new Vector3(textureTileSize, 0, 0)); if (useGeneratedShadeMask) { Page.SetShadeMask(material, 4); } else { pass.GetTextureUnitState(4).SetTextureName(shadeMaskTextureName); } } }
public PreApplyTextureAliasesScriptCompilerEvent( Material material, ref Dictionary<string, string> aliases ) : base( CompilerEventType.PreApplyTextureAliases ) { Material = material; Aliases = aliases; }
protected override void unload() { if ( this._material != null ) { MaterialManager.Instance.Remove( this._material ); this._material.Unload(); this._material = null; } if ( this._texture != null ) { TextureManager.Instance.Remove( this._texture ); this._texture.Unload(); this._texture = null; } }
public TreeBillboardRenderer() { billboardMaterial = MaterialManager.Instance.GetByName("SpeedTree/Billboard"); billboardMaterial.Load(); parentNode = TerrainManager.Instance.RootSceneNode; }
public RSQuadOperation( CompositorInstance instance, uint pass_id, Material mat ) { Material = mat; Instance = instance; PassId = pass_id; QuadLeft = -1; QuadRight = 1; QuadTop = 1; QuadBottom = -1; mat.Load(); instance.OnMaterialSetup( new CompositorInstanceMaterialEventArgs( PassId, Material ) ); Technique = mat.GetTechnique( 0 ); Debug.Assert( Technique != null, "Material has no supported technique." ); }
/// <see cref="Translator.Translate"/> public override void Translate( ScriptCompiler compiler, AbstractNode node ) { var obj = (ObjectAbstractNode)node; if ( obj != null ) { if ( string.IsNullOrEmpty( obj.Name ) ) { compiler.AddError( CompileErrorCode.ObjectNameExpected, obj.File, obj.Line ); } } else { compiler.AddError( CompileErrorCode.ObjectNameExpected, node.File, node.Line ); return; } // Create a material with the given name object mat; ScriptCompilerEvent evt = new CreateMaterialScriptCompilerEvent( node.File, obj.Name, compiler.ResourceGroup ); var processed = compiler._fireEvent( ref evt, out mat ); if ( !processed ) { //TODO // The original translated implementation of this code block was simply the following: // _material = (Material)MaterialManager.Instance.Create( obj.Name, compiler.ResourceGroup ); // but sometimes it generates an exception due to a duplicate resource. // In order to avoid the above mentioned exception, the implementation was changed, but // it need to be checked when ResourceManager._add will be updated to the latest version var checkForExistingMat = (Material)MaterialManager.Instance.GetByName( obj.Name ); if ( checkForExistingMat == null ) { this._material = (Material)MaterialManager.Instance.Create( obj.Name, compiler.ResourceGroup ); } else { this._material = checkForExistingMat; } } else { this._material = (Material)mat; if ( this._material == null ) { compiler.AddError( CompileErrorCode.ObjectAllocationError, obj.File, obj.Line, "failed to find or create material \"" + obj.Name + "\"" ); } } this._material.RemoveAllTechniques(); obj.Context = this._material; this._material.Origin = obj.File; foreach ( var i in obj.Children ) { if ( i is PropertyAbstractNode ) { var prop = (PropertyAbstractNode)i; switch ( (Keywords)prop.Id ) { #region ID_LOD_VALUES case Keywords.ID_LOD_VALUES: { var lods = new LodValueList(); foreach ( var j in prop.Values ) { Real v = 0; if ( getReal( j, out v ) ) { lods.Add( v ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "lod_values expects only numbers as arguments" ); } } this._material.SetLodLevels( lods ); } break; #endregion ID_LOD_VALUES #region ID_LOD_DISTANCES case Keywords.ID_LOD_DISTANCES: { // Set strategy to distance strategy LodStrategy strategy = DistanceLodStrategy.Instance; this._material.LodStrategy = strategy; // Real in lod distances var lods = new LodValueList(); foreach ( var j in prop.Values ) { Real v = 0; if ( getReal( j, out v ) ) { lods.Add( v ); } else { compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line, "lod_values expects only numbers as arguments" ); } } this._material.SetLodLevels( lods ); } break; #endregion ID_LOD_DISTANCES #region ID_LOD_STRATEGY case Keywords.ID_LOD_STRATEGY: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "lod_strategy only supports 1 argument" ); } else { var strategyName = string.Empty; var result = getString( prop.Values[ 0 ], out strategyName ); if ( result ) { var strategy = LodStrategyManager.Instance.GetStrategy( strategyName ); result = strategy != null; if ( result ) { this._material.LodStrategy = strategy; } } if ( !result ) { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "lod_strategy argument must be a valid lod strategy" ); } } break; #endregion ID_LOD_STRATEGY #region ID_RECEIVE_SHADOWS case Keywords.ID_RECEIVE_SHADOWS: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "receive_shadows only supports 1 argument" ); } else { var val = true; if ( getBoolean( prop.Values[ 0 ], out val ) ) { this._material.ReceiveShadows = val; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "receive_shadows argument must be \"true\", \"false\", \"yes\", \"no\", \"on\", or \"off\"" ); } } break; #endregion ID_RECEIVE_SHADOWS #region ID_TRANSPARENCY_CASTS_SHADOWS case Keywords.ID_TRANSPARENCY_CASTS_SHADOWS: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 1 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "transparency_casts_shadows only supports 1 argument" ); } else { var val = true; if ( getBoolean( prop.Values[ 0 ], out val ) ) { this._material.TransparencyCastsShadows = val; } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "transparency_casts_shadows argument must be \"true\", \"false\", \"yes\", \"no\", \"on\", or \"off\"" ); } } break; #endregion ID_TRANSPARENCY_CASTS_SHADOWS #region ID_SET_TEXTURE_ALIAS case Keywords.ID_SET_TEXTURE_ALIAS: if ( prop.Values.Count == 0 ) { compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line ); } else if ( prop.Values.Count > 3 ) { compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line ); } else { AbstractNode i0 = getNodeAt( prop.Values, 0 ), i1 = getNodeAt( prop.Values, 1 ); String name, value; if ( getString( i0, out name ) && getString( i1, out value ) ) { this._textureAliases.Add( name, value ); } else { compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line, "set_texture_alias must have 2 string argument" ); } } break; #endregion ID_SET_TEXTURE_ALIAS default: compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized" ); break; } //end of switch statement } else if ( i is ObjectAbstractNode ) { processNode( compiler, i ); } } // Apply the texture aliases ScriptCompilerEvent locEvt = new PreApplyTextureAliasesScriptCompilerEvent( this._material, ref this._textureAliases ); compiler._fireEvent( ref locEvt ); this._material.ApplyTextureAliases( this._textureAliases ); this._textureAliases.Clear(); }
/// <summary> /// /// </summary> /// <param name="prof"></param> /// <param name="mat"></param> /// <param name="terrain"></param> /// <param name="compositeMap"></param> public virtual void UpdateParams( SM2Profile prof, Material mat, Terrain terrain, bool compositeMap ) { Pass p = mat.GetTechnique( 0 ).GetPass( 0 ); if ( compositeMap ) { UpdateVpParams( prof, terrain, TechniqueType.RenderCompositeMap, p.VertexProgramParameters ); UpdateFpParams( prof, terrain, TechniqueType.RenderCompositeMap, p.FragmentProgramParameters ); } else { //high lod UpdateVpParams( prof, terrain, TechniqueType.HighLod, p.VertexProgramParameters ); UpdateFpParams( prof, terrain, TechniqueType.HighLod, p.FragmentProgramParameters ); //low lod p = mat.GetTechnique( 1 ).GetPass( 0 ); UpdateVpParams( prof, terrain, TechniqueType.LowLod, p.VertexProgramParameters ); UpdateFpParams( prof, terrain, TechniqueType.LowLod, p.FragmentProgramParameters ); } }
public void Initialize(Window window) { m_window = window; InitializeOculus(); InitializeGloves(); // Create the root object m_root = new Root("GlovesLog.log"); // Configure the render system SetRenderingSystem(); // Create render window m_renderWindow = m_root.Initialize(true); // Loads the resources ResourceGroupManager.Instance.AddResourceLocation("media", "Folder", true); ResourceGroupManager.Instance.InitializeAllResourceGroups(); // Create the screen manager m_sceneManager = m_root.CreateSceneManager(SceneType.Generic); InitializeCameras(); InitializeViewports(); InitializeLight(); // Create material to render ClEye camera input m_axiomMaterial = MaterialManager.Instance.Create("dynamicResource", "Materials") as Material; // Create texture to render the CLEye camera input to m_texture = TextureManager.Instance.CreateManual("DynamicTexture", ResourceGroupManager.DefaultResourceGroupName, TextureType.TwoD, 640, 480, 2, PixelFormat.R8G8B8, TextureUsage.RenderTarget); // Set the cameras in the scene SceneNode cameraNode = m_sceneManager.RootSceneNode.CreateChildSceneNode("CameraNode", new Vector3(0, 0, 0)); cameraNode.AttachObject(m_camera[0]); cameraNode.AttachObject(m_camera[1]); InitializeEntities(); // Initialize the material that will draw the camera input m_axiomMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState("DynamicTexture"); m_axiomMaterial.GetTechnique(0).GetPass(0).DepthCheck = false; m_axiomMaterial.GetTechnique(0).GetPass(0).DepthWrite = false; m_axiomMaterial.GetTechnique(0).GetPass(0).LightingEnabled = false; // Initialize the rectangle input onto which the camera input will be rendered m_rect = new Rectangle2D(true); //m_rect.SetCorners(-1.15f, 1.0f, 1.15f, -1.0f); m_rect.SetCorners(-0.85f, 0.7f, 0.85f, -0.7f); m_rect.Material = m_axiomMaterial; m_rect.RenderQueueGroup = RenderQueueGroupID.Background; SceneNode node = m_sceneManager.RootSceneNode.CreateChildSceneNode("Background"); node.AttachObject(m_rect); // Set the function to the FrameStarted event m_root.FrameStarted += FrameStarted; InitializeCLEyeCameras(); // Not recording m_record = false; // Not loading from file m_renderFromFile = false; // Initialize the gloves capture string arrays m_gloveCaptureL = new string[30]; m_gloveCaptureL[0] = "Left Glove Capture"; m_gloveCaptureL[1] = "\r\n"; m_gloveCaptureR = new string[30]; m_gloveCaptureR[0] = "Right Glove Capture"; m_gloveCaptureR[1] = "\r\n"; }
/// <summary> /// /// </summary> /// <param name="mat"></param> /// <param name="terrain"></param> public override void UpdateParamsForCompositeMap( Material mat, Terrain terrain ) { this.mShaderGen.UpdateParams( this, mat, terrain, true ); }
/// <summary> /// /// </summary> /// <param name="mat"></param> /// <param name="terrain"></param> public override void UpdateParams( Material mat, Terrain terrain ) { this.mShaderGen.UpdateParams( this, mat, terrain, false ); }
/// <summary> /// /// </summary> /// <param name="mat"></param> /// <param name="terrain"></param> /// <param name="tt"></param> protected void AddTechnique( Material mat, Terrain terrain, TechniqueType tt ) { string ttStr = string.Empty; switch ( tt ) { case TechniqueType.HighLod: ttStr += "hl"; break; case TechniqueType.LowLod: ttStr += "ll"; break; case TechniqueType.RenderCompositeMap: ttStr += "rc"; break; } LogManager.Instance.Write( "AddTechique:" + ttStr, null ); Technique tech = mat.CreateTechnique(); //only supporting one pass Pass pass = tech.CreatePass(); GpuProgramManager gmgr = GpuProgramManager.Instance; HighLevelGpuProgramManager hmgr = HighLevelGpuProgramManager.Instance; if ( this.mShaderGen == null ) { bool check2x = this.mLayerNormalMappingEnabled || this.mLayerParallaxMappingEnabled; /* if (hmgr.IsLanguageSupported("cg") && (check2x && (gmgr.IsSyntaxSupported("fp40") || gmgr.IsSyntaxSupported("ps_2_x"))) || (gmgr.IsSyntaxSupported("ps_2_0"))) mShaderGen = new ShaderHelperCG(); else*/ if ( hmgr.IsLanguageSupported( "hlsl" ) ) { this.mShaderGen = new ShaderHelperHLSL(); } else if ( hmgr.IsLanguageSupported( "glsl" ) ) { this.mShaderGen = new ShaderHelperGLSL(); } else { //TODO } } HighLevelGpuProgram vprog = this.mShaderGen.GenerateVertexProgram( this, terrain, tt ); HighLevelGpuProgram fprog = this.mShaderGen.GenerateFragmentProgram( this, terrain, tt ); pass.SetVertexProgram( vprog.Name ); pass.SetFragmentProgram( fprog.Name ); if ( tt == TechniqueType.HighLod || tt == TechniqueType.RenderCompositeMap ) { //global normal map TextureUnitState tu = pass.CreateTextureUnitState(); tu.SetTextureName( terrain.TerrainNormalMap.Name ); tu.SetTextureAddressingMode( TextureAddressing.Clamp ); //global color map if ( terrain.IsGlobalColorMapEnabled && IsGlobalColorMapEnabled ) { tu = pass.CreateTextureUnitState( terrain.GlobalColorMap.Name ); tu.SetTextureAddressingMode( TextureAddressing.Clamp ); } //light map if ( IsLightMapEnabled ) { tu = pass.CreateTextureUnitState( terrain.LightMap.Name ); tu.SetTextureAddressingMode( TextureAddressing.Clamp ); } //blend maps uint maxLayers = GetMaxLayers( terrain ); uint numBlendTextures = Utility.Min( terrain.GetBlendTextureCount( (byte)maxLayers ), terrain.GetBlendTextureCount() ); uint numLayers = Utility.Min( maxLayers, (uint)terrain.LayerCount ); for ( uint i = 0; i < numBlendTextures; ++i ) { tu = pass.CreateTextureUnitState( terrain.GetBlendTextureName( (byte)i ) ); tu.SetTextureAddressingMode( TextureAddressing.Clamp ); } //layer textures for ( uint i = 0; i < numLayers; ++i ) { //diffuse / specular string name = terrain.GetLayerTextureName( (byte)i, 0 ); tu = pass.CreateTextureUnitState( terrain.GetLayerTextureName( (byte)i, 0 ) ); //normal / height tu = pass.CreateTextureUnitState( terrain.GetLayerTextureName( (byte)i, 1 ) ); } } //end if else if ( this.mCompositeMapEnabled ) { // LOW_LOD textures // composite map TextureUnitState tu = pass.CreateTextureUnitState(); tu.SetTextureName( terrain.CompositeMap.Name ); tu.SetTextureAddressingMode( TextureAddressing.Clamp ); // That's it! } }
/// <summary> /// Override to do some of our own initialization after the engine is set up. /// </summary> /// <returns></returns> protected override bool Setup() { if(base.Setup()) { material = MaterialManager.Instance.GetByName(MATERIAL_NAME); ToggleNoise(); ToggleMesh(); ToggleBlending(); return true; } return false; }
//----------------------------------------------------------------------- public override void SetMaterial(Material mat) { billboardSet.MaterialName = mat.Name; }
protected override void load() { // clarabie - nov 18, 2008 // modified this to check for an existing material instead of always // creating a new one. Allows more flexibility, but also specifically allows us to // solve the problem of XNA not having fixed function support this._material = (Material)MaterialManager.Instance.GetByName( "Fonts/" + _name ); if ( this._material == null ) { // create a material for this font this._material = (Material)MaterialManager.Instance.Create( "Fonts/" + _name, Group ); TextureUnitState unitState = null; var blendByAlpha = false; if ( this._fontType == FontType.TrueType ) { #if !( XBOX || XBOX360 ) // create the font bitmap on the fly createTexture(); // a texture layer was added in CreateTexture unitState = this._material.GetTechnique( 0 ).GetPass( 0 ).GetTextureUnitState( 0 ); blendByAlpha = true; #endif } else { // load this texture // TODO In general, modify any methods like this that throw their own exception rather than returning null, so the caller can decide how to handle a missing resource. this._texture = TextureManager.Instance.Load( Source, Group, TextureType.TwoD, 0 ); blendByAlpha = texture.HasAlpha; // pre-created font images unitState = Material.GetTechnique( 0 ).GetPass( 0 ).CreateTextureUnitState( Source ); } // Make sure material is aware of colour per vertex. this._material.GetTechnique( 0 ).GetPass( 0 ).VertexColorTracking = TrackVertexColor.Diffuse; if ( unitState != null ) { // Clamp to avoid fuzzy edges unitState.SetTextureAddressingMode( TextureAddressing.Clamp ); // Allow min/mag filter, but no mip unitState.SetTextureFiltering( FilterOptions.Linear, FilterOptions.Linear, FilterOptions.None ); } // set up blending mode if ( blendByAlpha ) { this._material.SetSceneBlending( SceneBlendType.TransparentAlpha ); } else { // assume black background here this._material.SetSceneBlending( SceneBlendType.Add ); } } }
public RSQuadOperation(CompositorInstance instance, uint pass_id, Material mat) { this.mat = mat; this.instance = instance; this.pass_id = pass_id; mat.Load(); instance.FireNotifyMaterialSetup(pass_id, mat); technique = mat.GetTechnique(0); Debug.Assert(technique != null); }
private BspStaticFaceGroup CopyShaderFaceData(Quake3Level q3lvl, int face, Material shadMat, int shadIdx) { BspStaticFaceGroup dest = new BspStaticFaceGroup(); InternalBspFace src = q3lvl.Faces[face]; if((q3lvl.Shaders[src.shader].surfaceFlags & SurfaceFlags.Sky) == SurfaceFlags.Sky) dest.isSky = true; else dest.isSky = false; dest.materialHandle = shadMat.Handle; dest.elementStart = src.elemStart; dest.numElements = src.elemCount; dest.numVertices = src.vertCount; dest.vertexStart = src.vertStart; dest.plane = new Plane(); if (Quake3ShaderManager.Instance.GetByName(q3lvl.Shaders[shadIdx].name) != null) { // it's a quake shader dest.isQuakeShader = true; } if(src.type == BspFaceType.Normal) { dest.type = FaceGroup.FaceList; // Assign plane dest.plane.Normal = new Vector3( src.normal[0], src.normal[1], src.normal[2] ); dest.plane.D = -dest.plane.Normal.Dot( new Vector3( src.org[0], src.org[1], src.org[2] ) ); // Don't rebase indexes here - Quake3 re-uses some indexes for multiple vertex // groups eg repeating small details have the same relative vertex data but // use the same index data. } else if(src.type == BspFaceType.Patch) { // Seems to be some crap in the Q3 level where vertex count = 0 or num control points = 0? if((dest.numVertices == 0) || (src.meshCtrl[0] == 0)) { dest.type = FaceGroup.Unknown; } else { // Set up patch surface dest.type = FaceGroup.Patch; // Locate the patch we already built if(!patches.ContainsKey(face)) throw new AxiomException("Patch not found from previous built state."); dest.patchSurf = (PatchSurface) patches[face]; } } else if(src.type == BspFaceType.Mesh) { dest.type = FaceGroup.FaceList; // Assign plane dest.plane.Normal = new Vector3(src.normal[0], src.normal[1], src.normal[2]); dest.plane.D = -dest.plane.Normal.Dot(new Vector3(src.org[0], src.org[1], src.org[2])); } else { LogManager.Instance.Write("!!! Unknown face type !!!"); } return dest; }
private void Init(int metersPerSample) { // set up the material normalMaterial = WorldManager.Instance.DefaultTerrainMaterial; material = normalMaterial; // create the render operation renderOp = new RenderOperation(); renderOp.operationType = OperationType.TriangleList; renderOp.useIndices = true; location = tile.Location; // ask the world manager what LOD we should use this.metersPerSample = metersPerSample; targetMetersPerSample = metersPerSample; // figure out the number of actual samples we need in the tile based on the size // and level of detail numSamples = tile.Size / metersPerSample; // allocate the storage for the height map heightMap = new float[numSamples * numSamples]; return; }
///<summary> /// Notify listeners of a material compilation. ///</summary> public void FireNotifyMaterialSetup(uint pass_id, Material mat) { foreach (CompositorInstanceListener listener in listeners) listener.NotifyMaterialSetup(pass_id, mat); }
public void SetMaterial( Material mat ) { this.material = mat; }
/// <summary> /// /// </summary> /// <param name="passId"></param> /// <param name="material"></param> public CompositorInstanceMaterialEventArgs( uint passId, Material material ) { this.PassID = passId; this.Material = material; }
///<summary> /// Notification before a render target operation involving a material (like /// rendering a quad), so that material parameters can be varied. ///</summary> ///<param name="pass_id"> /// Pass identifier within Compositor instance, this is speficied /// by the user by CompositionPass::setIdentifier(). ///</param> ///<param name="mat" /// Material, this may be changed at will and will only affect /// the current instance of the Compositor, not the global material /// it was cloned from. ///</param> public virtual void NotifyMaterialRender(uint pass_id, Material mat) { }
protected void InitTextureLighting() { if ( targetRenderSystem.Capabilities.TextureUnitCount < 2 ) { LogManager.Instance.Write( "--WARNING--At least 2 available texture units are required for BSP dynamic lighting!" ); } Texture texLight = TextureLight.CreateTexture(); this.textureLightMaterial = (Material)MaterialManager.Instance.GetByName( "Axiom/BspTextureLightMaterial" ); if ( this.textureLightMaterial == null ) { this.textureLightMaterial = (Material) MaterialManager.Instance.Create( "Axiom/BspTextureLightMaterial", ResourceGroupManager.DefaultResourceGroupName ); this.textureLightPass = this.textureLightMaterial.GetTechnique( 0 ).GetPass( 0 ); // the texture light TextureUnitState tex = this.textureLightPass.CreateTextureUnitState( texLight.Name ); tex.SetColorOperation( LayerBlendOperation.Modulate ); tex.ColorBlendMode.source2 = LayerBlendSource.Diffuse; tex.SetAlphaOperation( LayerBlendOperationEx.Modulate ); tex.AlphaBlendMode.source2 = LayerBlendSource.Diffuse; tex.TextureCoordSet = 2; tex.SetTextureAddressingMode( TextureAddressing.Clamp ); // The geometry texture without lightmap. Use the light texture on this // pass, the appropriate texture will be rendered at RenderTextureLighting tex = this.textureLightPass.CreateTextureUnitState( texLight.Name ); tex.SetColorOperation( LayerBlendOperation.Modulate ); tex.SetAlphaOperation( LayerBlendOperationEx.Modulate ); tex.SetTextureAddressingMode( TextureAddressing.Wrap ); this.textureLightPass.SetSceneBlending( SceneBlendType.TransparentAlpha ); this.textureLightMaterial.CullingMode = CullingMode.None; this.textureLightMaterial.Lighting = false; } else { this.textureLightPass = this.textureLightMaterial.GetTechnique( 0 ).GetPass( 0 ); } }
///<summary> /// Notification of when a render target operation involving a material (like /// rendering a quad) is compiled, so that miscelleneous parameters that are different /// per Compositor instance can be set up. ///</summary> ///<param name="pass_id"> /// Pass identifier within Compositor instance, this is speficied /// by the user by CompositionPass::setIdentifier(). ///</param> ///<param name="mat" /// Material, this may be changed at will and will only affect /// the current instance of the Compositor, not the global material /// it was cloned from. ///</param> public virtual void NotifyMaterialSetup(uint pass_id, Material mat) { }