public Texture( string _textureLine ) { m_rawTextureLine = _textureLine; // Parse texture name Parser P = new Parser( _textureLine ); m_name = P.ReadString( true, false ); try { // Check if it's a constant color m_name = m_name.ToLower(); if ( m_name.StartsWith( "_" ) ) { // Procedural texture switch ( m_name ) { case "_default": m_constantColorType = CONSTANT_COLOR_TYPE.DEFAULT; break; case "_black": m_constantColorType = CONSTANT_COLOR_TYPE.BLACK; break; case "_blackalphawhite": m_constantColorType = CONSTANT_COLOR_TYPE.BLACK_ALPHA_WHITE; break; case "_white": m_constantColorType = CONSTANT_COLOR_TYPE.WHITE; break; case "_invalid": m_constantColorType = CONSTANT_COLOR_TYPE.INVALID; break; default: throw new Exception( "Unsupported procedural texture type \"" + m_name + "\"!" ); } } else if ( m_name.StartsWith( "ipr_constantcolor" ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.CUSTOM; P = new Parser( _textureLine ); P.ConsumeString( "ipr_constantColor", false ); string strColor = P.ReadBlock( '(', ')' ); m_customConstantColor = P.ReadFloat4( strColor ); // Compare known colors to revert to basic types if ( CompareFloat4( m_customConstantColor, float4.Zero ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.BLACK; } else if ( CompareFloat4( m_customConstantColor, float4.UnitW ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.BLACK_ALPHA_WHITE; } else if ( CompareFloat4( m_customConstantColor, float4.One ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.WHITE; } } if ( m_constantColorType == CONSTANT_COLOR_TYPE.TEXTURE ) { // Build file name string fullPath = Path.Combine( ms_TexturesBasePath.FullName, m_name ); if ( Path.GetExtension( fullPath.ToLower() ) == "" ) fullPath += ".tga"; // Assume tga files if unspecified m_fileName = new FileInfo( fullPath ); } } catch ( Exception _e ) { m_error = _e; } }
private void Parse( string _block ) { m_states.m_unknownStates.Clear(); m_parms.m_unknownParms.Clear(); m_options.m_unknownOptions.Clear(); m_unknownVariables.Clear(); m_forbiddenParms.Clear(); m_isUsingVegetationParms = false; m_isUsingCloudParms = false; m_isUsingWaterParms = false; Parser P = new Parser( _block ); while ( P.OK ) { string token = P.ReadString(); if ( token == null ) break; // Done! if ( token.StartsWith( "//" ) ) { RecordSingleLineCommentVariable( token, P ); continue; } if ( token.StartsWith( "/*" ) ) { RecordCommentVariable( token, P ); continue; } if ( token.EndsWith( "{" ) ) { // Handle problematic parms without space before their values token = token.Substring( 0, token.Length-1 ); P.m_Index--; } P.SkipSpaces(); switch ( token.ToLower() ) { case "version": P.SkipSpaces(); m_version = P.ReadInteger(); break; case "state": m_states.Parse( P.ReadBlock() ); break; case "parms": m_parms.Parse( P.ReadBlock() ); break; case "options": ParseOptions( P.ReadBlock() ); break; // Programs case "mainprogram": m_programs.SetMainProgram( P.ReadString() ); break; case "zprepassprogram": m_programs.m_ZPrepass = P.ReadString(); break; case "shadowprogram": m_programs.m_shadow = P.ReadString(); break; // Textures // Layer 0 case "diffusemap": Layer0.m_diffuse = new Layer.Texture( P.ReadToEOL() ); break; case "bumpmap": Layer0.m_normal = new Layer.Texture( P.ReadToEOL() ); break; case "glossmap": Layer0.m_gloss = new Layer.Texture( P.ReadToEOL() ); break; case "metallicmap": Layer0.m_metal = new Layer.Texture( P.ReadToEOL() ); break; case "specularmap": Layer0.m_specular = new Layer.Texture( P.ReadToEOL() ); break; case "heightmap": m_height = new Layer.Texture( P.ReadToEOL() ); break; case "lightmap": m_lightMap = new Layer.Texture( P.ReadToEOL() ); break; case "occlusionmap": Layer0.m_AO = new Layer.Texture( P.ReadToEOL() ); break; case "translucencymap": Layer0.m_translucency = new Layer.Texture( P.ReadToEOL() ); break; case "emissivemap": Layer0.m_emissive = new Layer.Texture( P.ReadToEOL() ); break; case "layer0_maskmap": Layer0.m_mask = new Layer.Texture( P.ReadToEOL() ); break; case "layer0_scalebias": Layer0.ParseScaleBias( P ); break; case "layer0_maskscalebias":Layer0.ParseMaskScaleBias( P ); break; case "layer0_colorconstant":Layer0.m_colorConstant = P.ReadFloat4(); break; // Layer 1 case "layer1_diffusemap": Layer1.m_diffuse = new Layer.Texture( P.ReadToEOL() ); break; case "layer1_bumpmap": Layer1.m_normal = new Layer.Texture( P.ReadToEOL() ); break; case "layer1_glossmap": Layer1.m_gloss = new Layer.Texture( P.ReadToEOL() ); break; case "layer1_specularmap": Layer1.m_specular = new Layer.Texture( P.ReadToEOL() ); break; case "layer1_metallicmap": Layer1.m_metal = new Layer.Texture( P.ReadToEOL() ); break; case "layer1_maskmap": Layer1.m_mask = new Layer.Texture( P.ReadToEOL() ); break; case "layer1_emissivemap": throw new Exception( "Shouldn't be allowed!" );//P.SkipSpaces(); Layer1.m_emissive = new Layer.Texture( P.ReadToEOL() ); break; case "layer1_scalebias": Layer1.ParseScaleBias( P ); break; case "layer1_maskscalebias":Layer1.ParseMaskScaleBias( P ); break; case "layer1_colorconstant":Layer1.m_colorConstant = P.ReadFloat4(); break; // Layer 2 case "layer2_diffusemap": Layer2.m_diffuse = new Layer.Texture( P.ReadToEOL() ); break; case "layer2_bumpmap": Layer2.m_normal = new Layer.Texture( P.ReadToEOL() ); break; case "layer2_glossmap": Layer2.m_gloss = new Layer.Texture( P.ReadToEOL() ); break; case "layer2_specularmap": Layer2.m_specular = new Layer.Texture( P.ReadToEOL() ); break; case "layer2_metallicmap": Layer2.m_metal = new Layer.Texture( P.ReadToEOL() ); break; case "layer2_emissivemap": throw new Exception( "Shouldn't be allowed!" );//P.SkipSpaces(); Layer2.m_emissive = new Layer.Texture( P.ReadToEOL() ); break; case "layer2_maskmap": Layer2.m_mask = new Layer.Texture( P.ReadToEOL() ); break; case "layer2_scalebias": Layer2.ParseScaleBias( P ); break; case "layer2_maskscalebias":Layer2.ParseMaskScaleBias( P ); break; case "layer2_colorconstant":Layer2.m_colorConstant = P.ReadFloat4(); break; // Main variables case "m_physicsmaterial": m_physicsMaterial = P.ReadToEOL(); break; case "wardroughness": float4 roughness = P.ReadFloat4(); m_glossMinMax.x = roughness.x; m_glossMinMax.y = roughness.y; break; case "metallicminmax": float4 metal = P.ReadFloat4(); m_metallicMinMax.x = metal.x; m_metallicMinMax.y = metal.y; break; default: if ( CheckSafeTokens( token ) ) RecordUnknownVariable( token, P ); else RecordForbiddenVariable( token, P ); break; } } }
public void ParseScaleBias( Parser _P ) { float4 SB = _P.ReadFloat4(); m_UVScale.Set( SB.x, SB.y ); m_UVOffset.Set( SB.z, SB.w ); }