public void CreateBlueprint() { state = BuildingState.Blueprint; MeshRenderer[] mrs = transform.Find("Model").GetComponentsInChildren <MeshRenderer> (); foreach (MeshRenderer rend in mrs) { rend.material.color = new Color(1f, 1f, 1f, blueprintAlpha); StandardShaderHelper.ChangeRenderMode(rend.material, StandardShaderHelper.BlendMode.Fade); } }
public Shader GetShader(SyncMaterial syncMaterial) { var transparent = StandardShaderHelper.IsTransparent(syncMaterial); if (syncMaterial.IsDoubleSided) { return(transparent ? m_URPDoubleTransparentShader : m_URPDoubleOpaqueShader); } return(transparent ? m_URPTransparentShader : m_URPOpaqueShader); }
protected void ExtractBasicMaterialInfo(SyncMaterial syncMaterial, out bool transparent, out bool emission, out Color color) { transparent = StandardShaderHelper.IsTransparent(syncMaterial); emission = syncMaterial.Emission != SyncColor.Black || syncMaterial.EmissionMap.TextureId != SyncId.None; var tint = ImportersUtils.GetUnityColor(syncMaterial.Tint, false); color = tint * ImportersUtils.GetUnityColor(syncMaterial.AlbedoColor, false); if (transparent) { color.a = syncMaterial.Alpha; } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { var material = materialEditor.target as Material; if (m_FirstTimeApply) { FindProperties(props); m_MaterialEditor = materialEditor; StandardShaderHelper.ComputeFlagsAndKeywords(material); m_FirstTimeApply = false; } ShaderPropertiesGUI(material); }
protected void Deactivate() { state = BuildingState.Inactive; if (anim != null) { anim.enabled = false; } MeshRenderer[] mrs = transform.Find("Model").GetComponentsInChildren <MeshRenderer> (); foreach (MeshRenderer rend in mrs) { if (rend.gameObject.name.Contains("(P)")) { rend.material.color = new Color(info.mainColor.r / 2f, info.mainColor.g / 2f, info.mainColor.b / 2f); } else if (rend.gameObject.name.Contains("(S)")) { rend.material.color = new Color(info.secondaryColor.r / 2f, info.secondaryColor.g / 2f, info.secondaryColor.b / 2f); } else if (rend.gameObject.name.Contains("(A)")) { rend.material.color = new Color(info.alternateColor.r / 2f, info.alternateColor.g / 2f, info.alternateColor.b / 2f); } else if (rend.gameObject.name == "Pad") { rend.material.color = new Color(padColor.r / 2f, padColor.g / 2f, padColor.b / 2f); } StandardShaderHelper.ChangeRenderMode(rend.material, StandardShaderHelper.BlendMode.Opaque); } //TODO: this can lead to issues if the building is on multiple islands //we can't use the tile's original color though because it won't match with the layer that it's on until after it has been destroyed Color anchorColor = TerrainManager.instance.tiles [coveredTiles [0]].originalColor; foreach (Vector2 pos in coveredTiles) { TerrainManager.instance.ClearTileAtPosition(pos); TerrainManager.instance.GetTileAtPosition(pos).GetComponent <Renderer> ().material.color = anchorColor; } }
void ShaderPropertiesGUI(Material material) { EditorGUIUtility.labelWidth = 0f; DoAlbedoArea(); EditorGUILayout.Space(); DoNormalArea(); EditorGUILayout.Space(); if (DoCutoutArea()) { EditorGUILayout.Space(); } if (DoAlphaArea()) { EditorGUILayout.Space(); } DoSmoothnessArea(); EditorGUILayout.Space(); DoMetallicArea(); EditorGUILayout.Space(); DoEmissionArea(); EditorGUILayout.Space(); DoTintArea(); StandardShaderHelper.ComputeFlagsAndKeywords(material); EditorGUILayout.Space(); GUILayout.Label("Advanced", EditorStyles.boldLabel); m_MaterialEditor.EnableInstancingField(); m_MaterialEditor.DoubleSidedGIField(); }
void SetBuildingColors() { MeshRenderer[] mrs = transform.Find("Model").GetComponentsInChildren <MeshRenderer> (); foreach (MeshRenderer rend in mrs) { if (rend.gameObject.name.Contains("(P)")) { rend.material.color = info.mainColor; } else if (rend.gameObject.name.Contains("(S)")) { rend.material.color = info.secondaryColor; } else if (rend.gameObject.name.Contains("(A)")) { rend.material.color = info.alternateColor; } else if (rend.gameObject.name == "Pad") { rend.material.color = padColor; } StandardShaderHelper.ChangeRenderMode(rend.material, StandardShaderHelper.BlendMode.Opaque); } }
public UnityEngine.Material GenerateMaterial( Schema.Material gltfMaterial, ref Schema.Texture[] textures, ref Schema.Image[] schemaImages, ref Dictionary <int, Texture2D>[] imageVariants ) { UnityEngine.Material material; if (gltfMaterial.extensions != null && gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness != null) { material = GetPbrSpecularGlossinessMaterial(gltfMaterial.doubleSided); } else if (gltfMaterial.extensions.KHR_materials_unlit != null) { material = GetUnlitMaterial(gltfMaterial.doubleSided); } else { material = GetPbrMetallicRoughnessMaterial(gltfMaterial.doubleSided); } material.name = gltfMaterial.name; //added support for KHR_materials_pbrSpecularGlossiness if (gltfMaterial.extensions != null) { Schema.PbrSpecularGlossiness specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness; if (specGloss != null) { material.color = specGloss.diffuseColor.gamma; material.SetVector(StandardShaderHelper.specColorPropId, specGloss.specularColor); material.SetFloat(StandardShaderHelper.glossinessPropId, specGloss.glossinessFactor); TrySetTexture(specGloss.diffuseTexture, material, StandardShaderHelper.mainTexPropId, ref textures, ref schemaImages, ref imageVariants); if (TrySetTexture(specGloss.specularGlossinessTexture, material, StandardShaderHelper.specGlossMapPropId, ref textures, ref schemaImages, ref imageVariants)) { material.EnableKeyword(StandardShaderHelper.KW_SPEC_GLOSS_MAP); } } } if (gltfMaterial.pbrMetallicRoughness != null) { material.color = gltfMaterial.pbrMetallicRoughness.baseColor.gamma; material.SetFloat(StandardShaderHelper.metallicPropId, gltfMaterial.pbrMetallicRoughness.metallicFactor); material.SetFloat(StandardShaderHelper.roughnessPropId, gltfMaterial.pbrMetallicRoughness.roughnessFactor); TrySetTexture( gltfMaterial.pbrMetallicRoughness.baseColorTexture, material, StandardShaderHelper.mainTexPropId, ref textures, ref schemaImages, ref imageVariants ); if (TrySetTexture(gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture, material, StandardShaderHelper.metallicGlossMapPropId, ref textures, ref schemaImages, ref imageVariants)) { material.EnableKeyword(StandardShaderHelper.KW_METALLIC_ROUGNESS_MAP); } } if (TrySetTexture(gltfMaterial.normalTexture, material, StandardShaderHelper.bumpMapPropId, ref textures, ref schemaImages, ref imageVariants)) { material.EnableKeyword("_NORMALMAP"); } if (TrySetTexture(gltfMaterial.occlusionTexture, material, StandardShaderHelper.occlusionMapPropId, ref textures, ref schemaImages, ref imageVariants)) { material.EnableKeyword(StandardShaderHelper.KW_OCCLUSION); } if (TrySetTexture(gltfMaterial.emissiveTexture, material, StandardShaderHelper.emissionMapPropId, ref textures, ref schemaImages, ref imageVariants)) { material.EnableKeyword(StandardShaderHelper.KW_EMISSION); } if (gltfMaterial.alphaModeEnum == AlphaMode.MASK) { material.SetFloat(StandardShaderHelper.cutoffPropId, gltfMaterial.alphaCutoff); StandardShaderHelper.SetAlphaModeMask(material, gltfMaterial); } else if (gltfMaterial.alphaModeEnum == AlphaMode.BLEND) { StandardShaderHelper.SetAlphaModeBlend(material); } else { StandardShaderHelper.SetOpaqueMode(material); } if (gltfMaterial.emissive != Color.black) { material.SetColor("_EmissionColor", gltfMaterial.emissive.gamma); material.EnableKeyword(StandardShaderHelper.KW_EMISSION); } return(material); }
public UnityEngine.Material GenerateMaterial(Schema.Material gltfMaterial, Schema.Texture[] textures, Texture2D[] images, List <UnityEngine.Object> additionalResources) { var material = Material.Instantiate <Material>(GetDefaultMaterial()); material.name = gltfMaterial.name; material.mainTextureScale = TEXTURE_SCALE; material.mainTextureOffset = TEXTURE_OFFSET; //added support for KHR_materials_pbrSpecularGlossiness if (gltfMaterial.extensions != null) { Schema.PbrSpecularGlossiness specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness; if (specGloss != null) { if (!specularSetupShader) { specularSetupShader = Shader.Find("Standard (Specular setup)"); } material.shader = specularSetupShader; var diffuseTexture = GetTexture(specGloss.diffuseTexture, textures, images); if (diffuseTexture != null) { material.mainTexture = diffuseTexture; } else { material.color = specGloss.diffuseColor; } var specGlossTexture = GetTexture(specGloss.specularGlossinessTexture, textures, images); if (specGlossTexture != null) { material.SetTexture(StandardShaderHelper.specGlossMapPropId, specGlossTexture); material.EnableKeyword("_SPECGLOSSMAP"); } else { material.SetVector(StandardShaderHelper.specColorPropId, specGloss.specularColor); material.SetFloat(StandardShaderHelper.glossinessPropId, (float)specGloss.glossinessFactor); } } Schema.MaterialUnlit unlitMaterial = gltfMaterial.extensions.KHR_materials_unlit; if (unlitMaterial != null) { if (gltfMaterial.pbrMetallicRoughness != null) { if (!unlitShader) { unlitShader = Shader.Find("Unlit/Color"); } material.shader = unlitShader; } } } if (gltfMaterial.pbrMetallicRoughness != null) { material.color = gltfMaterial.pbrMetallicRoughness.baseColor; material.SetFloat(StandardShaderHelper.metallicPropId, gltfMaterial.pbrMetallicRoughness.metallicFactor); material.SetFloat(StandardShaderHelper.glossinessPropId, 1 - gltfMaterial.pbrMetallicRoughness.roughnessFactor); var mainTxt = GetTexture(gltfMaterial.pbrMetallicRoughness.baseColorTexture, textures, images); if (mainTxt != null) { mainTxt.wrapMode = TextureWrapMode.Clamp; material.mainTexture = mainTxt; } var metallicRoughnessTxt = GetTexture(gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture, textures, images); if (metallicRoughnessTxt != null) { Profiler.BeginSample("ConvertMetallicRoughnessTexture"); // todo: Avoid this conversion by switching to a shader that accepts the given layout. Debug.LogWarning("Convert MetallicRoughnessTexture structure to fit Unity Standard Shader (slow operation)."); var newmrt = new UnityEngine.Texture2D(metallicRoughnessTxt.width, metallicRoughnessTxt.height); #if DEBUG newmrt.name = string.Format("{0}_metal_smooth", metallicRoughnessTxt.name); #endif var buf = metallicRoughnessTxt.GetPixels32(); for (int i = 0; i < buf.Length; i++) { // TODO: Reassure given space (linear) is correct (no gamma conversion needed). var color = buf[i]; color.a = (byte)(255 - color.g); color.r = color.g = color.b; buf[i] = color; } newmrt.SetPixels32(buf); newmrt.Apply(); Profiler.EndSample(); material.SetTexture(StandardShaderHelper.metallicGlossMapPropId, newmrt); material.EnableKeyword("_METALLICGLOSSMAP"); additionalResources.Add(newmrt); } } var normalTxt = GetTexture(gltfMaterial.normalTexture, textures, images); if (normalTxt != null) { material.SetTexture(StandardShaderHelper.bumpMapPropId, normalTxt); material.EnableKeyword("_NORMALMAP"); } var occlusionTxt = GetTexture(gltfMaterial.occlusionTexture, textures, images); if (occlusionTxt != null) { Profiler.BeginSample("ConvertOcclusionTexture"); // todo: Avoid this conversion by switching to a shader that accepts the given layout. Debug.LogWarning("Convert OcclusionTexture structure to fit Unity Standard Shader (slow operation)."); var newOcclusionTxt = new UnityEngine.Texture2D(occlusionTxt.width, occlusionTxt.height); #if DEBUG newOcclusionTxt.name = string.Format("{0}_occlusion", occlusionTxt.name); #endif var buf = occlusionTxt.GetPixels32(); for (int i = 0; i < buf.Length; i++) { var color = buf[i]; color.g = color.b = color.r; color.a = 1; buf[i] = color; } newOcclusionTxt.SetPixels32(buf); newOcclusionTxt.Apply(); Profiler.EndSample(); material.SetTexture(StandardShaderHelper.occlusionMapPropId, newOcclusionTxt); additionalResources.Add(newOcclusionTxt); } var emmissiveTxt = GetTexture(gltfMaterial.emissiveTexture, textures, images); if (emmissiveTxt != null) { material.SetTexture(StandardShaderHelper.emissionMapPropId, emmissiveTxt); material.EnableKeyword("_EMISSION"); } if (gltfMaterial.alphaModeEnum == AlphaMode.MASK) { material.SetFloat(StandardShaderHelper.cutoffPropId, gltfMaterial.alphaCutoff); StandardShaderHelper.SetAlphaModeMask(material, gltfMaterial); } else if (gltfMaterial.alphaModeEnum == AlphaMode.BLEND) { StandardShaderHelper.SetAlphaModeBlend(material); } else { StandardShaderHelper.SetOpaqueMode(material); } if (gltfMaterial.emissive != Color.black) { material.SetColor("_EmissionColor", gltfMaterial.emissive); material.EnableKeyword("_EMISSION"); } if (gltfMaterial.doubleSided) { Debug.LogWarning("Double sided shading is not supported!"); } return(material); }
public void SetMaterialProperties(SyncMaterial syncMaterial, Material material, ITextureCache textureCache) { StandardShaderHelper.ComputeMaterial(syncMaterial, material, textureCache); }
public Shader GetShader(SyncMaterial syncMaterial) { var transparent = StandardShaderHelper.IsTransparent(syncMaterial); return(transparent ? m_URPTransparentShader : m_URPOpaqueShader); }
public UnityEngine.Material GenerateMaterial(Schema.Material gltfMaterial, Schema.Texture[] textures, Texture2D[] images, string shader) { UnityEngine.Material material; // Check for user defined shader if (shader != null) { if (shader.Contains("glTF/PbrSpecularGlossiness")) { material = GetPbrSpecularGlossinessMaterial(gltfMaterial.doubleSided); } else if (shader.Contains("glTF/PbrMetallicRoughness")) { material = GetPbrMetallicRoughnessMaterial(gltfMaterial.doubleSided); } else if (shader.Contains("glTF/Unlit")) { material = GetUnlitMaterial(gltfMaterial.doubleSided); } else { material = new Material(Shader.Find(shader)); } } else { // Original setting if (gltfMaterial.extensions != null && gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness != null) { material = GetPbrSpecularGlossinessMaterial(gltfMaterial.doubleSided); } else if (gltfMaterial.extensions.KHR_materials_unlit != null) { material = GetUnlitMaterial(gltfMaterial.doubleSided); } else { // Enable Pbr Metallic Roughness Material by default (original setting) material = GetPbrMetallicRoughnessMaterial(gltfMaterial.doubleSided); // Disable unlit Shader by default // material = GetUnlitMaterial(gltfMaterial.doubleSided); } } material.name = gltfMaterial.name; if (material.HasProperty(StandardShaderHelper.KW_MAIN_MAP)) { // Initialize texture transform material.mainTextureScale = TEXTURE_SCALE; material.mainTextureOffset = TEXTURE_OFFSET; } //added support for KHR_materials_pbrSpecularGlossiness if (gltfMaterial.extensions != null) { Schema.PbrSpecularGlossiness specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness; if (specGloss != null) { material.color = specGloss.diffuseColor; material.SetVector(StandardShaderHelper.specColorPropId, specGloss.specularColor); material.SetFloat(StandardShaderHelper.glossinessPropId, specGloss.glossinessFactor); TrySetTexture(specGloss.diffuseTexture, material, StandardShaderHelper.mainTexPropId, textures, images); if (TrySetTexture(specGloss.specularGlossinessTexture, material, StandardShaderHelper.specGlossMapPropId, textures, images)) { material.EnableKeyword(StandardShaderHelper.KW_SPEC_GLOSS_MAP); } } } if (gltfMaterial.pbrMetallicRoughness != null) { material.color = gltfMaterial.pbrMetallicRoughness.baseColor; material.SetFloat(StandardShaderHelper.metallicPropId, gltfMaterial.pbrMetallicRoughness.metallicFactor); material.SetFloat(StandardShaderHelper.roughnessPropId, gltfMaterial.pbrMetallicRoughness.roughnessFactor); TrySetTexture( gltfMaterial.pbrMetallicRoughness.baseColorTexture, material, StandardShaderHelper.mainTexPropId, textures, images ); if (TrySetTexture(gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture, material, StandardShaderHelper.metallicGlossMapPropId, textures, images)) { material.EnableKeyword(StandardShaderHelper.KW_METALLIC_ROUGNESS_MAP); } } if (TrySetTexture(gltfMaterial.normalTexture, material, StandardShaderHelper.bumpMapPropId, textures, images)) { material.EnableKeyword("_NORMALMAP"); } if (TrySetTexture(gltfMaterial.occlusionTexture, material, StandardShaderHelper.occlusionMapPropId, textures, images)) { material.EnableKeyword(StandardShaderHelper.KW_OCCLUSION); } if (TrySetTexture(gltfMaterial.emissiveTexture, material, StandardShaderHelper.emissionMapPropId, textures, images)) { material.EnableKeyword(StandardShaderHelper.KW_EMISSION); } if (gltfMaterial.alphaModeEnum == AlphaMode.MASK) { material.SetFloat(StandardShaderHelper.cutoffPropId, gltfMaterial.alphaCutoff); StandardShaderHelper.SetAlphaModeMask(material, gltfMaterial); } else if (gltfMaterial.alphaModeEnum == AlphaMode.BLEND) { StandardShaderHelper.SetAlphaModeBlend(material); } else { StandardShaderHelper.SetOpaqueMode(material); } if (gltfMaterial.emissive != Color.black) { material.SetColor("_EmissionColor", gltfMaterial.emissive); material.EnableKeyword(StandardShaderHelper.KW_EMISSION); } return(material); }
public Shader GetShader(SyncMaterial syncMaterial) { return(StandardShaderHelper.GetShader(syncMaterial)); }