internal void _PreUpdateMask(UpdateContext context) { //_maskFlag: 0-new mask, 1-active mask, 2-mask complete if (_maskFlag == 0) { if (_stencilEraser == null) { _stencilEraser = new StencilEraser(gameObject.transform); _stencilEraser.meshFilter.mesh = mesh; } else { _stencilEraser.enabled = true; } } _maskFlag = 1; if (_manager != null) { NMaterial nm = _manager.GetMaterial(6, blendMode, context.clipInfo.clipId); Material mat = nm.material; if ((object)mat != (object)_stencilEraser.meshRenderer.sharedMaterial) { _stencilEraser.meshRenderer.sharedMaterial = mat; } int refValue = context.stencilReferenceValue - 1; mat.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Equal); mat.SetInt(ShaderConfig._properyIDs._Stencil, refValue); mat.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Replace); mat.SetInt(ShaderConfig._properyIDs._StencilReadMask, refValue); mat.SetInt(ShaderConfig._properyIDs._ColorMask, 0); } }
public void RefreshMaterials() { int cnt = _materials.Length; bool hasAlphaTexture = _texture.alphaTexture != null; for (int i = 0; i < cnt; i++) { List <NMaterial> items = _materials[i]; if (items != null) { int cnt2 = items.Count; for (int j = 0; j < cnt2; j++) { NMaterial nm = items[j]; nm.material.mainTexture = _texture.nativeTexture; if (hasAlphaTexture) { if (!nm.combined) { nm.combined = true; nm.material.EnableKeyword("COMBINED"); } nm.material.SetTexture(ShaderConfig._properyIDs._AlphaTex, _texture.alphaTexture); } } } } }
static public int get_stencilSet(IntPtr l) { try { FairyGUI.NMaterial self = (FairyGUI.NMaterial)checkSelf(l); pushValue(l, true); pushValue(l, self.stencilSet); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int get_blendMode(IntPtr l) { try { FairyGUI.NMaterial self = (FairyGUI.NMaterial)checkSelf(l); pushValue(l, true); pushEnum(l, (int)self.blendMode); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int set_blendMode(IntPtr l) { try { FairyGUI.NMaterial self = (FairyGUI.NMaterial)checkSelf(l); FairyGUI.BlendMode v; checkEnum(l, 2, out v); self.blendMode = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_material(IntPtr l) { try { FairyGUI.NMaterial self = (FairyGUI.NMaterial)checkSelf(l); UnityEngine.Material v; checkType(l, 2, out v); self.material = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_stencilSet(IntPtr l) { try { FairyGUI.NMaterial self = (FairyGUI.NMaterial)checkSelf(l); System.Boolean v; checkType(l, 2, out v); self.stencilSet = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_clipId(IntPtr l) { try { FairyGUI.NMaterial self = (FairyGUI.NMaterial)checkSelf(l); System.UInt32 v; checkType(l, 2, out v); self.clipId = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
public NMaterial GetMaterial(uint frameId, uint context) { if (_items == null) { _items = new List <NMaterial>(); } int cnt = _items.Count; NMaterial spare = null; for (int i = 0; i < cnt; i++) { NMaterial mat = _items[i]; if (mat.frameId == frameId) { if (mat.context == context) { return(mat); } } else if (spare == null) { spare = mat; } } if (spare != null) { spare.frameId = frameId; spare.context = context; return(spare); } else { NMaterial mat = _manager.CreateMaterial(); if (_variants != null) { foreach (string v in _variants) { mat.EnableKeyword(v); } } mat.frameId = frameId; mat.context = context; _items.Add(mat); return(mat); } }
static public int constructor(IntPtr l) { try { FairyGUI.NMaterial o; UnityEngine.Shader a1; checkType(l, 2, out a1); o = new FairyGUI.NMaterial(a1); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
public NMaterial CreateMaterial() { NMaterial mat = new NMaterial(ShaderConfig.GetShader(shaderName)); mat.mainTexture = texture.nativeTexture; if (texture.alphaTexture != null) { mat.EnableKeyword("COMBINED"); mat.SetTexture("_AlphaTex", texture.alphaTexture); } if (_keywords != null) { foreach (string v in _keywords) { mat.EnableKeyword(v); } } mat.hideFlags = DisplayOptions.hideFlags; return(mat); }
/// <summary> /// /// </summary> /// <returns></returns> public NMaterial CreateMaterial() { NMaterial nm = new NMaterial(ShaderConfig.GetShader(shaderName)); nm.material.mainTexture = texture.nativeTexture; if (texture.alphaTexture != null) { nm.combined = true; nm.material.EnableKeyword("COMBINED"); nm.material.SetTexture("_AlphaTex", texture.alphaTexture.nativeTexture); } if (_keywords != null) { foreach (string v in _keywords) { nm.material.EnableKeyword(v); } } nm.material.hideFlags = DisplayOptions.hideFlags; return(nm); }
public NMaterial CreateMaterial() { Shader shader = ShaderConfig.Get(shaderName); if (shader == null) { Debug.LogWarning("FairyGUI: shader not found: " + shaderName); shader = Shader.Find("UI/Default"); } NMaterial mat = new NMaterial(shader); mat.mainTexture = texture.nativeTexture; if (texture.alphaTexture != null) { mat.EnableKeyword("COMBINED"); mat.SetTexture("_AlphaTex", texture.alphaTexture); } shader.hideFlags = DisplayOptions.hideFlags; mat.hideFlags = DisplayOptions.hideFlags; return(mat); }
/// <summary> /// /// </summary> /// <returns></returns> NMaterial CreateMaterial() { NMaterial nm = new NMaterial(_shader); nm.material.mainTexture = _texture.nativeTexture; if (_texture.alphaTexture != null) { nm.combined = true; nm.material.EnableKeyword("COMBINED"); nm.material.SetTexture(ShaderConfig._properyIDs._AlphaTex, _texture.alphaTexture); } if (_keywords != null) { int cnt = _keywords.Length; for (int i = 0; i < cnt; i++) { nm.material.EnableKeyword(_keywords[i]); } } nm.material.hideFlags = DisplayOptions.hideFlags; return(nm); }
public void UpdateMaterial(UpdateContext context) { NMaterial nm = null; if (_manager != null && !_customMatarial) { nm = _manager.GetMaterial(this, context); _material = nm.material; if ((object)_material != (object)meshRenderer.sharedMaterial && (object)_material.mainTexture != null) { meshRenderer.sharedMaterial = _material; } if (nm.combined) { _material.SetTexture("_AlphaTex", _manager.texture.alphaTexture.nativeTexture); } } if (maskFrameId != 0 && maskFrameId != UpdateContext.frameId) { //曾经是遮罩对象,现在不是了 if (_stencilEraser != null) { _stencilEraser.enabled = false; } } if (_material != null) { if (blendMode != BlendMode.Normal) //GetMateria已经保证了不同的blendMode会返回不同的共享材质,所以这里可以放心设置 { BlendModeUtils.Apply(_material, blendMode); } if (context.clipped) { if (maskFrameId != UpdateContext.frameId && context.rectMaskDepth > 0) //在矩形剪裁下,且不是遮罩对象 { _material.SetVector("_ClipBox", context.clipInfo.clipBox); if (context.clipInfo.soft) { _material.SetVector("_ClipSoftness", context.clipInfo.softness); } } if (context.stencilReferenceValue > 0) { if (maskFrameId == UpdateContext.frameId) //是遮罩 { if (context.stencilReferenceValue == 1) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 1); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 0); } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", context.stencilReferenceValue - 1); _material.SetInt("_ColorMask", 0); } //设置擦除stencil的drawcall if (_stencilEraser == null) { _stencilEraser = new StencilEraser(gameObject.transform); _stencilEraser.meshFilter.mesh = mesh; } else { _stencilEraser.enabled = true; } if (nm != null) { NMaterial eraserNm = _manager.GetMaterial(this, context); eraserNm.stencilSet = true; Material eraserMat = eraserNm.material; if ((object)eraserMat != (object)_stencilEraser.meshRenderer.sharedMaterial) { _stencilEraser.meshRenderer.sharedMaterial = eraserMat; } int refValue = context.stencilReferenceValue - 1; eraserMat.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); eraserMat.SetInt("_Stencil", refValue); eraserMat.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); eraserMat.SetInt("_StencilReadMask", refValue); eraserMat.SetInt("_ColorMask", 0); } } else { int refValue = context.stencilReferenceValue | (context.stencilReferenceValue - 1); _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", refValue); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", refValue); _material.SetInt("_ColorMask", 15); } if (nm != null) { nm.stencilSet = true; } } else if (nm != null && nm.stencilSet) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 0); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 15); nm.stencilSet = false; } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 0); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 15); } } } }
/// <summary> /// /// </summary> /// <param name="context"></param> public void UpdateMaterial(UpdateContext context) { Stats.GraphicsCount++; NMaterial nm = null; bool firstInstance = true; if (!_customMatarial) { if (_manager != null) { nm = _manager.GetMaterial(this, context, out firstInstance); _material = nm.material; if ((object)_material != (object)meshRenderer.sharedMaterial) { meshRenderer.sharedMaterial = _material; } } else { _material = null; if ((object)meshRenderer.sharedMaterial != null) { meshRenderer.sharedMaterial = null; } } } if (maskFrameId != 0 && maskFrameId != UpdateContext.frameId) { //曾经是遮罩对象,现在不是了 if (_stencilEraser != null) { _stencilEraser.enabled = false; } } if (firstInstance && (object)_material != null) { if (blendMode != BlendMode.Normal) //GetMateria已经保证了不同的blendMode会返回不同的共享材质,所以这里可以放心设置 { BlendModeUtils.Apply(_material, blendMode); } bool clearStencil = false; if (context.clipped) { if (maskFrameId != UpdateContext.frameId && context.rectMaskDepth > 0) //在矩形剪裁下,且不是遮罩对象 { _material.SetVector(ShaderConfig._properyIDs._ClipBox, context.clipInfo.clipBox); if (context.clipInfo.soft) { _material.SetVector(ShaderConfig._properyIDs._ClipSoftness, context.clipInfo.softness); } } if (context.stencilReferenceValue > 0) { if (maskFrameId == UpdateContext.frameId) //是遮罩 { if (context.stencilReferenceValue == 1) { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt(ShaderConfig._properyIDs._Stencil, 1); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, 255); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 0); } else { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt(ShaderConfig._properyIDs._Stencil, context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, context.stencilReferenceValue - 1); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 0); } //设置擦除stencil的drawcall if (_stencilEraser == null) { _stencilEraser = new StencilEraser(gameObject.transform); _stencilEraser.meshFilter.mesh = mesh; } else { _stencilEraser.enabled = true; } if (nm != null) { NMaterial eraserNm = _manager.GetMaterial(this, context, out firstInstance); eraserNm.stencilSet = true; Material eraserMat = eraserNm.material; if ((object)eraserMat != (object)_stencilEraser.meshRenderer.sharedMaterial) { _stencilEraser.meshRenderer.sharedMaterial = eraserMat; } int refValue = context.stencilReferenceValue - 1; eraserMat.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Equal); eraserMat.SetInt(ShaderConfig._properyIDs._Stencil, refValue); eraserMat.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Replace); eraserMat.SetInt(ShaderConfig._properyIDs._StencilReadMask, refValue); eraserMat.SetInt(ShaderConfig._properyIDs._ColorMask, 0); } } else { int refValue = context.stencilReferenceValue | (context.stencilReferenceValue - 1); if (context.clipInfo.reversedMask) { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.NotEqual); } else { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Equal); } _material.SetInt(ShaderConfig._properyIDs._Stencil, refValue); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, refValue); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 15); } if (nm != null) { nm.stencilSet = true; } } else { clearStencil = nm == null || nm.stencilSet; } } else { clearStencil = nm == null || nm.stencilSet; } if (clearStencil) { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt(ShaderConfig._properyIDs._Stencil, 0); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, 255); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 15); } } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="alpha"></param> /// <param name="grayed"></param> public void Update(UpdateContext context, float alpha, bool grayed) { Stats.GraphicsCount++; if (_meshDirty) { _alpha = alpha; UpdateMeshNow(); } else if (_alpha != alpha) { ChangeAlpha(alpha); } uint clipId = context.clipInfo.clipId; int matType = 0; NMaterial nm = null; if (!_customMatarial) { if (_manager != null) { if (context.clipped && !dontClip) { if (_maskFlag == 1) { matType = 6; } else if (context.rectMaskDepth == 0) { matType = grayed ? 1 : 0; } else if (context.clipInfo.soft) { matType = grayed ? 5 : 4; } else { matType = grayed ? 3 : 2; } } else { clipId = 0; matType = grayed ? 1 : 0; } nm = _manager.GetMaterial(matType, blendMode, clipId); _material = nm.material; if ((object)_material != (object)meshRenderer.sharedMaterial) { meshRenderer.sharedMaterial = _material; } } else { _material = null; if ((object)meshRenderer.sharedMaterial != null) { meshRenderer.sharedMaterial = null; } } } if ((nm == null || nm._firstInstance) && (object)_material != null) { if (blendMode != BlendMode.Normal) //GetMateria已经保证了不同的blendMode会返回不同的共享材质,所以这里可以放心设置 { BlendModeUtils.Apply(_material, blendMode); } bool clearStencil = nm == null || nm.stencilSet; if (context.clipped) { if (_maskFlag != 1 && context.rectMaskDepth > 0) //在矩形剪裁下,且不是遮罩对象 { _material.SetVector(ShaderConfig._properyIDs._ClipBox, context.clipInfo.clipBox); if (context.clipInfo.soft) { _material.SetVector(ShaderConfig._properyIDs._ClipSoftness, context.clipInfo.softness); } } if (context.stencilReferenceValue > 0) { if (_maskFlag == 1) //是遮罩 { if (context.stencilReferenceValue == 1) { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt(ShaderConfig._properyIDs._Stencil, 1); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, 255); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 0); } else { if (context.isStencilReversing) { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.NotEqual); } else { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Equal); } _material.SetInt(ShaderConfig._properyIDs._Stencil, context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, context.stencilReferenceValue - 1); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 0); } } else { _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt(ShaderConfig._properyIDs._Stencil, context.stencilCompareValue); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 15); } if (nm != null) { nm.stencilSet = true; } clearStencil = false; } } if (clearStencil) { if (nm != null) { nm.stencilSet = false; } _material.SetInt(ShaderConfig._properyIDs._StencilComp, (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt(ShaderConfig._properyIDs._Stencil, 0); _material.SetInt(ShaderConfig._properyIDs._StencilOp, (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt(ShaderConfig._properyIDs._StencilReadMask, 255); _material.SetInt(ShaderConfig._properyIDs._ColorMask, 15); } } if (_maskFlag != 0) { if (_maskFlag == 1) { _maskFlag = 2; } else { if (_stencilEraser != null) { _stencilEraser.enabled = false; } _maskFlag = 0; } } }
public NMaterial CreateMaterial() { NMaterial nm = new NMaterial(ShaderConfig.GetShader(shaderName)); nm.material.mainTexture = texture.nativeTexture; if (texture.alphaTexture != null) { nm.combined = true; nm.material.EnableKeyword("COMBINED"); nm.material.SetTexture("_AlphaTex", texture.alphaTexture.nativeTexture); } if (_keywords != null) { foreach (string v in _keywords) nm.material.EnableKeyword(v); } nm.material.hideFlags = DisplayOptions.hideFlags; return nm; }
/// <summary> /// /// </summary> /// <param name="materialType"></param> /// <param name="blendMode"></param> /// <param name="clipId"></param> /// <param name="firstInstance"></param> /// <returns></returns> public NMaterial GetMaterial(int materialType, BlendMode blendMode, uint clipId, out bool firstInstance) { uint frameId = UpdateContext.frameId; List <NMaterial> items; if (blendMode == BlendMode.Normal) { items = _materials[materialType]; if (items == null) { items = new List <NMaterial>(); _materials[materialType] = items; } } else { items = _materials[internalKeywordCount + materialType]; if (items == null) { items = new List <NMaterial>(); _materials[internalKeywordCount + materialType] = items; } } int cnt = items.Count; NMaterial result = null; for (int i = 0; i < cnt; i++) { NMaterial mat = items[i]; if (mat.frameId == frameId) { if (materialType != 6 && mat.clipId == clipId && mat.blendMode == blendMode) { firstInstance = false; return(mat); } } else { result = mat; break; } } if (result != null) { result.frameId = frameId; result.clipId = clipId; result.blendMode = blendMode; if (result.combined) { result.material.SetTexture(ShaderConfig._properyIDs._AlphaTex, _texture.alphaTexture); } } else { result = CreateMaterial(); string[] keywords = internalKeywords[materialType]; if (keywords != null) { cnt = keywords.Length; for (int i = 0; i < cnt; i++) { result.material.EnableKeyword(keywords[i]); } } result.frameId = frameId; result.clipId = clipId; result.blendMode = blendMode; if (BlendModeUtils.Factors[(int)result.blendMode].pma) { result.material.EnableKeyword("COLOR_FILTER"); } items.Add(result); } firstInstance = true; return(result); }
public NMaterial CreateMaterial() { NMaterial mat = new NMaterial(ShaderConfig.GetShader(shaderName)); mat.mainTexture = texture.nativeTexture; if (texture.alphaTexture != null) { mat.EnableKeyword("COMBINED"); mat.SetTexture("_AlphaTex", texture.alphaTexture); } if (_keywords != null) { foreach (string v in _keywords) mat.EnableKeyword(v); } mat.hideFlags = DisplayOptions.hideFlags; return mat; }
public void UpdateMaterial(UpdateContext context) { NMaterial nm = null; if (_manager != null && !_customMatarial) { nm = _manager.GetMaterial(this, context); _material = nm.material; if ((object)_material != (object)meshRenderer.sharedMaterial && (object)_material.mainTexture != null) { meshRenderer.sharedMaterial = _material; } if (nm.combined) { _material.SetTexture("_AlphaTex", _manager.texture.alphaTexture); } } if (_material != null) { if (blendMode != BlendMode.Normal) //GetMateria已经保证了不同的blendMode会返回不同的共享材质,所以这里可以放心设置 { BlendModeUtils.Apply(_material, blendMode); } if (context.clipped) { if (maskFrameId != UpdateContext.frameId && context.rectMaskDepth > 0) { _material.SetVector("_ClipBox", context.clipInfo.clipBox); if (context.clipInfo.soft) { _material.SetVector("_ClipSoftness", context.clipInfo.softness); } } if (context.stencilReferenceValue > 0) { if (maskFrameId == UpdateContext.frameId) { if (context.stencilReferenceValue == 1) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 1); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 0); } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", context.stencilReferenceValue - 1); _material.SetInt("_ColorMask", 0); } } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_ColorMask", 15); } if (nm != null) { nm.stencilSet = true; } } else if (nm != null && nm.stencilSet) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 0); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 15); nm.stencilSet = false; } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 0); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 15); } } } }
/// <summary> /// /// </summary> /// <param name="grahpics"></param> /// <param name="context"></param> /// <returns></returns> public NMaterial GetMaterial(NGraphics grahpics, UpdateContext context) { uint frameId = UpdateContext.frameId; BlendMode blendMode = grahpics.blendMode; int collectionIndex; uint clipId; if (context.clipped && !grahpics.dontClip) { clipId = context.clipInfo.clipId; if (grahpics.maskFrameId == UpdateContext.frameId) { collectionIndex = 6; } else if (context.rectMaskDepth == 0) { if (grahpics.grayed) { collectionIndex = 1; } else { collectionIndex = 0; } } else { if (context.clipInfo.soft) { if (grahpics.grayed) { collectionIndex = 5; } else { collectionIndex = 4; } } else { if (grahpics.grayed) { collectionIndex = 3; } else { collectionIndex = 2; } } } } else { clipId = 0; if (grahpics.grayed) { collectionIndex = 1; } else { collectionIndex = 0; } } List <NMaterial> items; if (blendMode == BlendMode.Normal) { items = _materials[collectionIndex]; if (items == null) { items = new List <NMaterial>(); } _materials[collectionIndex] = items; } else { items = _materials[internalKeywordCount + collectionIndex]; if (items == null) { items = new List <NMaterial>(); } _materials[internalKeywordCount + collectionIndex] = items; } int cnt = items.Count; NMaterial result = null; for (int i = 0; i < cnt; i++) { NMaterial mat = items[i]; if (mat.frameId == frameId) { if (collectionIndex != 6 && mat.clipId == clipId && mat.blendMode == blendMode) { return(mat); } } else if (result == null) { result = mat; } } if (result != null) { result.frameId = frameId; result.clipId = clipId; result.blendMode = blendMode; if (result.combined) { result.material.SetTexture("_AlphaTex", _texture.alphaTexture); } } else { result = CreateMaterial(); string[] keywords = internalKeywords[collectionIndex]; if (keywords != null) { cnt = keywords.Length; for (int i = 0; i < cnt; i++) { result.material.EnableKeyword(keywords[i]); } } result.frameId = frameId; result.clipId = clipId; result.blendMode = blendMode; if (BlendModeUtils.Factors[(int)result.blendMode].pma) { result.material.EnableKeyword("COLOR_FILTER"); } items.Add(result); } return(result); }
public NMaterial Get() { List <NMaterial> items; if (_manager.blendMode == BlendMode.Normal) { if (_items == null) { _items = new List <NMaterial>(); } items = _items; } else { if (_blendItems == null) { _blendItems = new List <NMaterial>(); } items = _blendItems; } int cnt = items.Count; NMaterial result = null; for (int i = 0; i < cnt; i++) { NMaterial mat = items[i]; if (mat.frameId == _manager.frameId) { if (mat.clipId == _manager.clipId && mat.blendMode == _manager.blendMode) { return(mat); } } else if (result == null) { result = mat; } } if (result != null) { result.frameId = _manager.frameId; result.clipId = _manager.clipId; result.blendMode = _manager.blendMode; } else { result = _manager.CreateMaterial(); if (_variants != null) { foreach (string v in _variants) { result.material.EnableKeyword(v); } } result.frameId = _manager.frameId; result.clipId = _manager.clipId; result.blendMode = _manager.blendMode; items.Add(result); } return(result); }