private static void SetupCutout(OutlineParameters parameters, OutlineTarget target) { if (target.Renderer == null) { return; } if (target.Renderer is SpriteRenderer) { var spriteRenderer = target.Renderer as SpriteRenderer; var sprite = spriteRenderer.sprite; if (sprite == null) { parameters.Buffer.DisableShaderKeyword(KeywordsUtility.GetCutoutKeyword()); return; } parameters.Buffer.EnableShaderKeyword(KeywordsUtility.GetCutoutKeyword()); parameters.Buffer.SetGlobalFloat(CutoutThresholdHash, target.CutoutThreshold); parameters.Buffer.SetGlobalTexture(CutoutTextureHash, spriteRenderer.sprite.texture); return; } var materialToGetTextureFrom = target.Renderer.sharedMaterial; if (target.CutoutDescriptionType != CutoutDescriptionType.None && materialToGetTextureFrom != null && materialToGetTextureFrom.HasProperty(target.CutoutTextureId)) { parameters.Buffer.EnableShaderKeyword(KeywordsUtility.GetCutoutKeyword()); parameters.Buffer.SetGlobalFloat(CutoutThresholdHash, target.CutoutThreshold); var offset = materialToGetTextureFrom.GetTextureOffset(target.CutoutTextureId); var scale = materialToGetTextureFrom.GetTextureScale(target.CutoutTextureId); parameters.Buffer.SetGlobalVector(CutoutTextureSTHash, new Vector4(scale.x, scale.y, offset.x, offset.y)); var texture = materialToGetTextureFrom.GetTexture(target.CutoutTextureId); if (texture == null || texture.dimension != TextureDimension.Tex2DArray) { parameters.Buffer.DisableShaderKeyword(KeywordsUtility.GetTextureArrayCutoutKeyword()); } else { parameters.Buffer.SetGlobalFloat(TextureIndexHash, target.CutoutTextureIndex); parameters.Buffer.EnableShaderKeyword(KeywordsUtility.GetTextureArrayCutoutKeyword()); } parameters.Buffer.SetGlobalTexture(CutoutTextureHash, texture); } else { parameters.Buffer.DisableShaderKeyword(KeywordsUtility.GetCutoutKeyword()); } }
private static void UpdateBounds(Renderer renderer, OutlineTarget target) { if (target.RendererType == RendererType.MeshRenderer) { var meshFilter = renderer.GetComponent <MeshFilter>(); if (meshFilter.sharedMesh != null) { meshFilter.sharedMesh.RecalculateBounds(); } } else if (target.RendererType == RendererType.SkinnedMeshRenderer) { var skinedMeshRenderer = renderer as SkinnedMeshRenderer; if (skinedMeshRenderer.sharedMesh != null) { skinedMeshRenderer.sharedMesh.RecalculateBounds(); } } }
private static void SetupCull(OutlineParameters parameters, OutlineTarget target) { parameters.Buffer.SetGlobalInt(CullHash, (int)target.CullMode); }
public OutlineTargetGroup(Outlinable outlinable, OutlineTarget target) { Outlinable = outlinable; Target = target; }