本文整理汇总了C#中UnityEngine.Material.GetInt方法的典型用法代码示例。如果您正苦于以下问题:C# Material.GetInt方法的具体用法?C# Material.GetInt怎么用?C# Material.GetInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Material
的用法示例。
在下文中一共展示了Material.GetInt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoSpecularMetallicArea
void DoSpecularMetallicArea( Material material )
{
SpecularMode specularMode = ( SpecularMode )material.GetInt( "_SpecularMode" );
if ( specularMode == SpecularMode.BlinnPhong )
{
if (specularMap.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines( Styles.specularMapText, specularMap, specularColor, Styles.smoothnessText, smoothness );
}
else
{
m_MaterialEditor.TexturePropertySingleLine( Styles.specularMapText, specularMap );
}
m_MaterialEditor.ShaderProperty( reflectanceMin, Styles.reflectanceMinText.text, 2 );
m_MaterialEditor.ShaderProperty( reflectanceMax, Styles.reflectanceMaxText.text, 2 );
}
else if ( specularMode == SpecularMode.Metallic )
{
if (metallicMap.textureValue == null)
m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapText, metallicMap, metallic, Styles.smoothnessText, smoothness);
else
m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapText, metallicMap);
}
}
示例2: SetBlendMode
static void SetBlendMode (Material material, eBlendMode blendMode) {
SetKeyword(material, PremultipledAlpha, blendMode == eBlendMode.PreMultipliedAlpha);
SetKeyword(material, Multiply, blendMode == eBlendMode.Multiply);
SetKeyword(material, Multiply2x, blendMode == eBlendMode.Multiplyx2);
SetKeyword(material, Additive, blendMode == eBlendMode.Additive);
SetKeyword(material, SoftAdditive, blendMode == eBlendMode.SoftAdditive);
int renderQueue;
switch (blendMode) {
case eBlendMode.Solid:
{
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
SetRenderQueue(material, "Opaque");
renderQueue = SolidQueue;
}
break;
case eBlendMode.Additive:
{
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
SetRenderQueue(material, "Transparent");
renderQueue = TransparentQueue;
}
break;
case eBlendMode.SoftAdditive:
{
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcColor);
SetRenderQueue(material, "Transparent");
renderQueue = TransparentQueue;
}
break;
case eBlendMode.Multiply:
{
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
SetRenderQueue(material, "Transparent");
renderQueue = TransparentQueue;
}
break;
case eBlendMode.Multiplyx2:
{
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
SetRenderQueue(material, "Transparent");
renderQueue = TransparentQueue;
}
break;
case eBlendMode.PreMultipliedAlpha:
case eBlendMode.StandardAlpha:
default:
{
bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
SetRenderQueue(material, zWrite ? "TransparentCutout" : "Transparent");
renderQueue = zWrite ? AlphaTestQueue : TransparentQueue;
}
break;
}
material.renderQueue = renderQueue + material.GetInt("_RenderQueue");
}
示例3: SetMaterialKeywords
static void SetMaterialKeywords(Material material)
{
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
// (MaterialProperty value might come from renderer material property block)
SetKeyword (material, "_NORMALMAP", material.GetTexture ("_BumpMap") || material.GetTexture ("_DetailNormalMap"));
SpecularMode specularMode = ( SpecularMode )material.GetInt( "_SpecularMode" );
if ( specularMode == SpecularMode.BlinnPhong )
{
SetKeyword( material, "_SPECGLOSSMAP", material.GetTexture( "_SpecGlossMap" ) );
}
else if ( specularMode == SpecularMode.Metallic )
{
SetKeyword( material, "_METALLICGLOSSMAP", material.GetTexture( "_MetallicGlossMap" ) );
}
SetKeyword( material, "S_SPECULAR_NONE", specularMode == SpecularMode.None );
SetKeyword( material, "S_SPECULAR_BLINNPHONG", specularMode == SpecularMode.BlinnPhong );
SetKeyword( material, "S_SPECULAR_METALLIC", specularMode == SpecularMode.Metallic );
SetKeyword( material, "S_OCCLUSION", material.GetTexture("_OcclusionMap") );
SetKeyword( material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
SetKeyword( material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"));
SetKeyword( material, "S_OVERRIDE_LIGHTMAP", material.GetTexture( "g_tOverrideLightmap" ) );
SetKeyword( material, "S_UNLIT", material.GetInt( "g_bUnlit" ) == 1 );
SetKeyword( material, "S_RECEIVE_SHADOWS", material.GetInt( "g_bReceiveShadows" ) == 1 );
SetKeyword( material, "S_WORLD_ALIGNED_TEXTURE", material.GetInt( "g_bWorldAlignedTexture" ) == 1 );
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled (material.GetColor("_EmissionColor"));
SetKeyword (material, "_EMISSION", shouldEmissionBeEnabled);
if ( material.IsKeywordEnabled( "S_RENDER_BACKFACES" ) )
{
material.SetInt( "_Cull", ( int )UnityEngine.Rendering.CullMode.Off );
}
else
{
material.SetInt( "_Cull", ( int )UnityEngine.Rendering.CullMode.Back );
}
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
{
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
if (!shouldEmissionBeEnabled)
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
material.globalIlluminationFlags = flags;
}
// Reflectance constants
float flReflectanceMin = material.GetFloat( "g_flReflectanceMin" );
float flReflectanceMax = material.GetFloat( "g_flReflectanceMax" );
material.SetFloat( "g_flReflectanceScale", Mathf.Max( flReflectanceMin, flReflectanceMax ) - flReflectanceMin );
material.SetFloat( "g_flReflectanceBias", flReflectanceMin );
// World aligned texture constants
Vector4 worldAlignedTextureNormal = material.GetVector( "g_vWorldAlignedTextureNormal" );
Vector3 normal = new Vector3( worldAlignedTextureNormal.x, worldAlignedTextureNormal.y, worldAlignedTextureNormal.z );
normal = ( normal.sqrMagnitude > 0.0f ) ? normal : Vector3.up;
Vector3 tangentU = Vector3.zero, tangentV = Vector3.zero;
Vector3.OrthoNormalize( ref normal, ref tangentU, ref tangentV );
material.SetVector( "g_vWorldAlignedNormalTangentU", new Vector4( tangentU.x, tangentU.y, tangentU.z, 0.0f ) );
material.SetVector( "g_vWorldAlignedNormalTangentV", new Vector4( tangentV.x, tangentV.y, tangentV.z, 0.0f ) );
// Static combo skips
if ( material.GetInt( "g_bUnlit" ) == 1 )
{
material.DisableKeyword( "_NORMALMAP" );
material.EnableKeyword( "S_SPECULAR_NONE" );
material.DisableKeyword( "S_SPECULAR_BLINNPHONG" );
material.DisableKeyword( "S_SPECULAR_METALLIC" );
material.DisableKeyword( "_METALLICGLOSSMAP" );
material.DisableKeyword( "_SPECGLOSSMAP" );
material.DisableKeyword( "S_OVERRIDE_LIGHTMAP" );
material.DisableKeyword( "S_RECEIVE_SHADOWS" );
}
}
示例4: DumpShaderMaterial
//.........这里部分代码省略.........
}
}
else if (babylonLine.IndexOf("samplers", StringComparison.OrdinalIgnoreCase) >= 0)
{
string[] samplers = babylonLine.Split(':');
if (samplers != null && samplers.Length > 1)
{
string sbuffer = samplers[1].Replace("[", "").Replace("]", "").Replace("\"", "");
if (!String.IsNullOrEmpty(sbuffer))
{
sbuffer = sbuffer.Trim();
string[] sdata = sbuffer.Split(',');
if (sdata != null && sdata.Length > 0)
{
foreach (string soption in sdata)
{
string soption_buffer = soption.Trim();
if (!String.IsNullOrEmpty(soption_buffer))
{
samplerList.Add(soption_buffer);
}
}
}
}
}
}
else if (babylonLine.IndexOf("defines", StringComparison.OrdinalIgnoreCase) >= 0)
{
string[] defines = babylonLine.Split(':');
if (defines != null && defines.Length > 1)
{
string dbuffer = defines[1].Replace("[", "").Replace("]", "").Replace("\"", "");
if (!String.IsNullOrEmpty(dbuffer))
{
dbuffer = dbuffer.Trim();
string[] ddata = dbuffer.Split(',');
if (ddata != null && ddata.Length > 0)
{
foreach (string doption in ddata)
{
string doption_buffer = doption.Trim();
if (!String.IsNullOrEmpty(doption_buffer))
{
defineList.Add(doption_buffer);
}
}
}
}
}
}
}
if (material.HasProperty("_AlphaMode")) {
babylonShaderMaterial.alphaMode = material.GetInt("_AlphaMode");
}
bool needsAlphaBlending = false;
if (material.HasProperty("_NeedsAlphaBlending")) {
needsAlphaBlending = (material.GetInt("_NeedsAlphaBlending") != 0);
}
bool needsAlphaTesting = false;
if (material.HasProperty("_NeedsAlphaTesting")) {
needsAlphaTesting = (material.GetInt("_NeedsAlphaTesting") != 0);
}
if (material.HasProperty("_BackFaceCulling")) {
babylonShaderMaterial.backFaceCulling = (material.GetInt("_BackFaceCulling") != 0);
}
babylonShaderMaterial.options = new BabylonShaderOptions();
babylonShaderMaterial.options.needAlphaBlending = needsAlphaBlending;
babylonShaderMaterial.options.needAlphaTesting = needsAlphaTesting;
babylonShaderMaterial.options.attributes = attributeList.ToArray();
babylonShaderMaterial.options.uniforms = uniformList.ToArray();
babylonShaderMaterial.options.samplers = samplerList.ToArray();
babylonShaderMaterial.options.defines = defineList.ToArray();
string vertexProgram = GetShaderProgramSection(basename, program, BabylonProgramSection.Vertex);
var vertextFile = Path.Combine(outpath, basename + ".vertex.fx");
if (exportationOptions.EmbeddedShaders)
{
shaderpath.Add("vertexElement", ("base64:" + Tools.FormatBase64(vertexProgram)));
}
else
{
File.WriteAllText(vertextFile, vertexProgram);
}
string fragmentProgram = GetShaderProgramSection(basename, program, BabylonProgramSection.Fragment);
var fragmentFile = Path.Combine(outpath, basename + ".fragment.fx");
if (exportationOptions.EmbeddedShaders)
{
shaderpath.Add("fragmentElement", ("base64:" + Tools.FormatBase64(fragmentProgram)));
}
else
{
File.WriteAllText(fragmentFile, fragmentProgram);
}
babylonShaderMaterial.shaderPath = (exportationOptions.EmbeddedShaders) ? (object)shaderpath : (object)basename;
materialsDictionary.Add(babylonShaderMaterial.name, babylonShaderMaterial);
return babylonShaderMaterial;
}
示例5: DumpPBRMaterial
private BabylonMaterial DumpPBRMaterial(Material material, int lightmapIndex = -1, Vector4 lightmapScaleOffset = default(Vector4), bool metallic = true, int lightmapCoordIndex = -1)
{
var materialNotSupported = false;
if (materialsDictionary.ContainsKey(material.name))
{
return materialsDictionary[material.name];
}
var babylonPbrMaterial = new BabylonPBRMaterial
{
name = material.name,
id = Guid.NewGuid().ToString(),
albedo = new float[4],
useEmissiveAsIllumination = true,
useSpecularOverAlpha = true,
useRadianceOverAlpha = true,
};
ExporterWindow.ReportProgress(1, "Exporting physical material: " + material.name);
babylonPbrMaterial.environmentIntensity = RenderSettings.ambientIntensity;
if (material.mainTexture && material.mainTexture.GetType().FullName == "UnityEngine.ProceduralTexture")
{
materialNotSupported = true;
Debug.LogWarning("ProceduralTexture: " + material.mainTexture.name + " not supported by Babylon.js");
}
if (material.HasProperty("_Roughness"))
{
babylonPbrMaterial.roughness = material.GetInt("_Roughness");
}
if (material.HasProperty("_UseRoughnessFromMetallicTextureAlpha"))
{
babylonPbrMaterial.useRoughnessFromMetallicTextureAlpha = (material.GetInt("_UseRoughnessFromMetallicTextureAlpha") != 0);
}
if (material.HasProperty("_UseRoughnessFromMetallicTextureGreen"))
{
babylonPbrMaterial.useRoughnessFromMetallicTextureGreen = (material.GetInt("_UseRoughnessFromMetallicTextureGreen") != 0);
}
if (material.HasProperty("_AlphaMode"))
{
babylonPbrMaterial.alphaMode = material.GetInt("_AlphaMode");
}
if (material.HasProperty("_DisableLighting"))
{
babylonPbrMaterial.disableLighting = (material.GetInt("_DisableLighting") != 0);
}
if (material.HasProperty("_UseEmissiveAsIllumination"))
{
babylonPbrMaterial.useEmissiveAsIllumination = (material.GetInt("_UseEmissiveAsIllumination") != 0);
}
if (material.HasProperty("_BackFaceCulling"))
{
babylonPbrMaterial.backFaceCulling = (material.GetInt("_BackFaceCulling") != 0);
}
// Albedo
if (material.HasProperty("_Color"))
{
babylonPbrMaterial.albedo = material.color.ToFloat();
}
babylonPbrMaterial.albedoTexture = DumpTextureFromMaterial(material, "_MainTex");
if (material.mainTexture != null && !materialNotSupported)
{
var textureScale = material.mainTextureScale;
babylonPbrMaterial.albedoTexture.uScale = textureScale.x;
babylonPbrMaterial.albedoTexture.vScale = textureScale.y;
var textureOffset = material.mainTextureOffset;
babylonPbrMaterial.albedoTexture.uOffset = textureOffset.x;
babylonPbrMaterial.albedoTexture.vOffset = textureOffset.y;
}
// Emissive
if (material.HasProperty("_EmissionColor"))
{
babylonPbrMaterial.emissive = material.GetColor("_EmissionColor").ToFloat();
}
babylonPbrMaterial.emissiveTexture = DumpTextureFromMaterial(material, "_EmissionMap");
// Transparency
DumpTransparency(material, babylonPbrMaterial);
// Glossiess/Reflectivity
DumpGlossinessReflectivity(material, metallic, babylonPbrMaterial);
// Occlusion
babylonPbrMaterial.ambientTexture = DumpTextureFromMaterial(material, "_OcclusionMap");
if (babylonPbrMaterial.ambientTexture != null && material.HasProperty("_OcclusionStrength"))
{
babylonPbrMaterial.ambientTexture.level = material.GetFloat("_OcclusionStrength");
}
// Normal
babylonPbrMaterial.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
if (babylonPbrMaterial.bumpTexture != null && material.HasProperty("_BumpScale"))
//.........这里部分代码省略.........
示例6: DumpStandardMaterial
private BabylonMaterial DumpStandardMaterial(Material material, int lightmapIndex = -1, Vector4 lightmapScaleOffset = default(Vector4), int lightmapCoordIndex = -1)
{
var materialNotSupported = false;
if (!materialsDictionary.ContainsKey(material.name))
{
var bMat = new BabylonStandardMaterial
{
name = material.name,
id = Guid.NewGuid().ToString(),
diffuse = new float[4],
specular = new float[4]
};
ExporterWindow.ReportProgress(1, "Exporting standard material: " + material.name);
// Default diffuse
bMat.diffuse[0] = 1.0f;
bMat.diffuse[1] = 1.0f;
bMat.diffuse[2] = 1.0f;
bMat.diffuse[3] = 1.0f;
// Default specular
bMat.specular[0] = 0.0f;
bMat.specular[1] = 0.0f;
bMat.specular[2] = 0.0f;
bMat.specular[3] = 1.0f;
if (material.mainTexture && material.mainTexture.GetType().FullName == "UnityEngine.ProceduralTexture")
{
materialNotSupported = true;
Debug.LogWarning("ProceduralTexture: " + material.mainTexture.name + " not supported by Babylon.js");
}
if (material.HasProperty("_Shininess"))
{
var specShininess = material.GetFloat("_Shininess");
bMat.specularPower = specShininess * 128;
}
if (material.HasProperty("_Color"))
{
bMat.diffuse = material.color.ToFloat();
}
if (material.HasProperty("_SpecColor"))
{
var specColor = material.GetColor("_SpecColor");
bMat.specular = specColor.ToFloat();
}
if (material.HasProperty("_Emission"))
{
if (material.GetColorNames().IndexOf("_Emission") >= 0)
{
var emissiveColor = material.GetColor("_Emission");
bMat.emissive = emissiveColor.ToFloat();
}
else if (material.GetFloatNames().IndexOf("_Emission") >= 0)
{
// TODO: Convert Lightmapper Emission Color
UnityEngine.Debug.LogWarning("Material Emission Is Float Not Color: " + material.name);
}
}
if (material.HasProperty("_AlphaMode"))
{
bMat.alphaMode = material.GetInt("_AlphaMode");
}
if (material.HasProperty("_DisableLighting"))
{
bMat.disableLighting = (material.GetInt("_DisableLighting") != 0);
}
if (material.HasProperty("_UseEmissiveAsIllumination"))
{
bMat.useEmissiveAsIllumination = (material.GetInt("_UseEmissiveAsIllumination") != 0);
}
if (material.HasProperty("_BackFaceCulling"))
{
bMat.backFaceCulling = (material.GetInt("_BackFaceCulling") != 0);
}
if (material.mainTexture && !materialNotSupported)
{
var mainTexture2D = material.mainTexture as Texture2D;
var mainTexturePath = AssetDatabase.GetAssetPath(mainTexture2D);
var alphaCuttOff = 0f;
if (material.HasProperty("_Cutoff"))
{
alphaCuttOff = material.GetFloat("_Cutoff");
}
bMat.diffuseTexture = new BabylonTexture
{
uScale = material.mainTextureScale.x,
vScale = material.mainTextureScale.y,
uOffset = material.mainTextureOffset.x,
vOffset = material.mainTextureOffset.y
};
CopyTexture(mainTexturePath, mainTexture2D, bMat.diffuseTexture);
if ((mainTexture2D && mainTexture2D.alphaIsTransparency) || alphaCuttOff > 0)
{
//.........这里部分代码省略.........
示例7: ValveToStandardSingleMaterial
//---------------------------------------------------------------------------------------------------------------------------------------------------
private static bool ValveToStandardSingleMaterial( Material m, Shader destShaderStandard, Shader destShaderStandardSpecular )
{
if ( m.shader.name.Equals( "Valve/vr_standard" ) )
{
if ( ( m.GetTag( "OriginalShader", true ) != null ) && ( m.GetTag( "OriginalShader", true ).Length > 0 ) )
{
Debug.Log( " Converting from \"" + m.shader.name + "\"-->\"" + m.GetTag( "OriginalShader", true ) + "\": " + m.name + "\n" );
m.shader = Shader.Find( m.GetTag( "OriginalShader", true ) );
return true;
}
else if ( m.GetInt( "_SpecularMode" ) == 2 )
{
// Metallic specular
Debug.Log( " Converting from \"" + m.shader.name + "\"-->\"" + destShaderStandard.name + "\": " + m.name + "\n" );
m.shader = destShaderStandard;
return true;
}
else
{
// Regular specular
Debug.Log( " Converting from \"" + m.shader.name + "\"-->\"" + destShaderStandardSpecular.name + "\": " + m.name + "\n" );
m.shader = destShaderStandardSpecular;
return true;
}
}
return false;
}