public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { // _Emission property is lost after assigning Standard shader to the material // thus transfer it before assigning the new shader if (material.HasProperty("_Emission")) { material.SetColor("_EmissionColor", material.GetColor("_Emission")); } base.AssignNewShaderToMaterial(material, oldShader, newShader); if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/")) { HairShaderUtility.SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode")); return; } BlendMode blendMode = BlendMode.Opaque; if (oldShader.name.Contains("/Transparent/Cutout/")) { blendMode = BlendMode.Cutout; } else if (oldShader.name.Contains("/Transparent/")) { // NOTE: legacy shaders did not provide physically based transparency // therefore Fade mode blendMode = BlendMode.Fade; } material.SetFloat("_Mode", (float)blendMode); DetermineWorkflow(MaterialEditor.GetMaterialProperties(new Material[] { material })); MaterialChanged(material, m_WorkflowMode); }
void OnEnable() { if (_commandBuffer != null) { return; } if (_targetHair == null) { return; } _alphaPassMaterials = _targetHair.sharedMaterials.Select(Instantiate).ToArray(); foreach (var each in _alphaPassMaterials) { HairShaderUtility.SetupMaterialWithBlendMode(each, HairShaderUtility.BlendMode.Fade); each.EnableKeyword("_ALPHA_PASS"); } _commandBuffer = new CommandBuffer(); for (var i = 0; i < _subMeshIndices.Length; ++i) { _commandBuffer.DrawRenderer(_targetHair, _alphaPassMaterials[_subMeshIndices[i]], _subMeshIndices[i], 0); } }
static void MaterialChanged(Material material, WorkflowMode workflowMode) { HairShaderUtility.SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode")); SetMaterialKeywords(material, workflowMode); }