private void UpdateOutline() { if (meshRenderer == null) { return; } if (mpb == null) { mpb = new MaterialPropertyBlock(); } //머리 색상 meshRenderer.GetPropertyBlock(mpb, 8); mpb.SetColor("_Color", hair_Color); mpb.SetColor("_ColorDim", hair_Color * 1.5f); mpb.SetColor("_ColorDimExtra", hair_Color); mpb.SetColor("_ColorDimExtra", hair_Color); meshRenderer.SetPropertyBlock(mpb, 8); //피부 색상 meshRenderer.GetPropertyBlock(mpb, 0); mpb.SetColor("_Color", skin_Color); mpb.SetColor("_ColorDim", skin_Color * skin_Color); mpb.SetColor("_ColorDimExtra", skin_Color * skin_Color * skin_Color); meshRenderer.SetPropertyBlock(mpb, 0); meshRenderer.GetPropertyBlock(mpb, 1); mpb.SetColor("_Color", skin_Color * 1.3f); mpb.SetColor("_ColorDim", skin_Color * skin_Color * 1.3f); mpb.SetColor("_ColorDimExtra", skin_Color * skin_Color * skin_Color * 1.3f); meshRenderer.SetPropertyBlock(mpb, 1); meshRenderer.GetPropertyBlock(mpb, 2); mpb.SetColor("_Color", skin_Color * 1.3f); mpb.SetColor("_ColorDim", skin_Color * skin_Color * 1.3f); mpb.SetColor("_ColorDimExtra", skin_Color * skin_Color * skin_Color * 1.3f); meshRenderer.SetPropertyBlock(mpb, 2); //옷 색상 meshRenderer.GetPropertyBlock(mpb, 3); mpb.SetColor("_Color", cloth_Color); mpb.SetColor("_ColorDim", cloth_Color * cloth_Color); mpb.SetColor("_ColorDimExtra", cloth_Color * cloth_Color * cloth_Color); meshRenderer.SetPropertyBlock(mpb, 3); meshRenderer.GetPropertyBlock(mpb, 6); mpb.SetColor("_Color", cloth_Color * 1.5f); mpb.SetColor("_ColorDim", cloth_Color * cloth_Color * 1.5f); mpb.SetColor("_ColorDimExtra", cloth_Color * cloth_Color * cloth_Color * 1.5f); meshRenderer.SetPropertyBlock(mpb, 6); //눈 meshRenderer.GetPropertyBlock(mpb, 2); mpb.SetTexture("_MainTex", eye_Tex[eye_Num]); meshRenderer.SetPropertyBlock(mpb, 2); //입 meshRenderer.GetPropertyBlock(mpb, 1); mpb.SetTexture("_MainTex", mouth_Tex[mouth_Num]); meshRenderer.SetPropertyBlock(mpb, 1); }
void Awake() { block = new MaterialPropertyBlock(); render = GetComponent <SkinnedMeshRenderer>(); render.GetPropertyBlock(block); texture = block.GetTexture("_MainTex") as Texture2D; }
void OnDisable() { if (smrProps == null) { smrProps = new MaterialPropertyBlock(); } smr.GetPropertyBlock(smrProps); { if (headInstance.shaderParamFloats != null) //TODO introduce IsCreated() or similar? { SnappersHeadDefinition.ResetShaderParam(ref headInstance); SnappersHeadDefinition.ApplyShaderParam(ref headInstance, smrProps); } } smr.SetPropertyBlock(smrProps); }
void UpdateOutline(bool outline) { mpb = new MaterialPropertyBlock(); spriteRenderer.GetPropertyBlock(mpb); mpb.SetFloat("_Outline", outline ? 1f : 0); mpb.SetColor("_OutlineColor", color); mpb.SetFloat("_OutlineSize", outlineSize); spriteRenderer.SetPropertyBlock(mpb); }
private void OnEnable() { this._photoBlock = new MaterialPropertyBlock(); SkinnedMeshRenderer componentInChildren = this.burnTarget.GetComponentInChildren <SkinnedMeshRenderer>(); componentInChildren.GetPropertyBlock(this._photoBlock); this._photoBlock.SetFloat("_BurnAmount", 0f); componentInChildren.SetPropertyBlock(this._photoBlock); }
private void ChangeTexture(int i) { // Get the property block. _renderer.GetPropertyBlock(_propBlock); // Assign our new values _propBlock.SetTexture("_Diffuse", butteryflySets[i].diffuse); _propBlock.SetTexture("_Normal", butteryflySets[i].normal); // Apply the edited values to the renderer. _renderer.SetPropertyBlock(_propBlock); }
void FetchPropertyBlocks() { for (int i = 0; i != materials.Length; i++) { if (materials[i].materialProps == null) { materials[i].materialProps = new MaterialPropertyBlock(); } smr.GetPropertyBlock(materials[i].materialProps, materials[i].materialIndex); } }
public void Render() { if (skinnedMeshRenderer.HasPropertyBlock()) { skinnedMeshRenderer.GetPropertyBlock(materialPropertyBlock); } materialPropertyBlock.SetFloat("_Age", Time.time - snapshotTime); for (int subIndex = 0; subIndex < mesh.subMeshCount; subIndex++) { Graphics.DrawMesh(mesh, transform, sharedMaterials[subIndex], skinnedMeshRenderer.gameObject.layer, null, subIndex, materialPropertyBlock); } }
public void Update() { AnimatedGO.GetPropertyBlock(materialPropertyBlock); materialPropertyBlock.SetFloat("_Visible", Visibility); AnimatedGO.SetPropertyBlock(materialPropertyBlock); if ((bluePlayer.transform.position - transform.position).sqrMagnitude < 2 && Visibility < 1) { FadeInMaterial(); } else if ((bluePlayer.transform.position - transform.position).sqrMagnitude > 2 && Visibility > 0) { FadeOutMaterial(); } }
void Start() { emotivePropertyBlock = new MaterialPropertyBlock(); if (GetComponent <MeshRenderer>() != null) { emotiveRenderer = GetComponent <MeshRenderer>(); emotiveRenderer.GetPropertyBlock(emotivePropertyBlock); } else if (GetComponent <SkinnedMeshRenderer>() != null) { emotiveRendererSkinned = GetComponent <SkinnedMeshRenderer>(); emotiveRendererSkinned.GetPropertyBlock(emotivePropertyBlock); } textureHeight = defaultShaderVariables.colorTexture.height; textureWidth = defaultShaderVariables.colorTexture.width; UpdateShader(defaultShaderVariables); }
private void UpdateShader(ShaderVariables variables) { if (emotiveRenderer != null) { emotiveRenderer.GetPropertyBlock(emotivePropertyBlock); } else if (emotiveRendererSkinned != null) { emotiveRendererSkinned.GetPropertyBlock(emotivePropertyBlock); } emotivePropertyBlock.SetFloat("_Smoothness", variables.smoothness); if (variables.emotionTexure != null) { emotivePropertyBlock.SetTexture("_EmoteTex", variables.emotionTexure); } if (variables.colorTexture != null) { emotivePropertyBlock.SetTexture("_ColorTex", variables.colorTexture); } emotivePropertyBlock.SetColor("_ColorTint", variables.tint); emotivePropertyBlock.SetFloat("_ColorXSpeed", variables.colorXSpeed); emotivePropertyBlock.SetFloat("_ColorYSpeed", variables.colorZSpeed); if (variables.displTexture != null) { emotivePropertyBlock.SetTexture("_DispTex", variables.displTexture); } emotivePropertyBlock.SetFloat("_Displacement", variables.displacement); emotivePropertyBlock.SetFloat("_DispSpeed", variables.displYSpeed); emotivePropertyBlock.SetFloat("_DispXSpeed", variables.displXSpeed); emotivePropertyBlock.SetFloat("_DispYSpeed", variables.displZSpeed); if (emotiveRenderer != null) { emotiveRenderer.SetPropertyBlock(emotivePropertyBlock); } else if (emotiveRendererSkinned != null) { emotiveRendererSkinned.SetPropertyBlock(emotivePropertyBlock); } }
// void Update() // { // } void LateUpdate() { if (null == PropertyMaterial) { PropertyMaterial = new MaterialPropertyBlock(); IDMaterialMainTexture = Shader.PropertyToID("_MainTex"); IDMaterialRectangleCell = Shader.PropertyToID("_CellRectangle"); IDMaterialPivotCell = Shader.PropertyToID("_CellPivot_LocalScale"); } /* MEMO: "SpriteRenderer", "SpriteMask" and "SkinnedMeshRenderer" do not coexist. */ int sortingOrder = 0; int sortingOffsetParts = 1; if (null != PartsRoot) { sortingOrder = PartsRoot.SortingOrder; sortingOffsetParts = PartsRoot.SortingOffsetPartsDraw; if (0 >= sortingOffsetParts) { sortingOffsetParts = 1; } } #if UNITY_2017_1_OR_NEWER int sortingOrderBase = sortingOrder; #else #endif sortingOrder += ((int)OrderInLayer) * sortingOffsetParts; /* Sprite (SpriteRenderer) */ if (null != InstanceSpriteRenderer) { /* Priority Set */ if (OrderInLayerPrevious != sortingOrder) { InstanceSpriteRenderer.sortingOrder = sortingOrder; OrderInLayerPrevious = sortingOrder; } if (null != PropertyMaterial) { InstanceSpriteRenderer.GetPropertyBlock(PropertyMaterial); /* Cell Set */ if (CellPrevious != Cell) { /* MEMO: Not enough to just set cell to "SpriteRenderer". (Need to set texture to shader) */ InstanceSpriteRenderer.sprite = Cell; PropertyMaterial.SetTexture(IDMaterialMainTexture, Cell.texture); Vector4 temp; Rect rectangleCell = Cell.rect; temp.x = rectangleCell.xMin; temp.y = rectangleCell.yMin; temp.z = rectangleCell.width; temp.w = rectangleCell.height; PropertyMaterial.SetVector(IDMaterialRectangleCell, temp); /* MEMO: Since "LocalScale" is stored together in "_CellPivot_LocalScale", overwrite value set by animation. */ temp = PropertyMaterial.GetVector(IDMaterialPivotCell); Vector2 pivot = Cell.pivot; temp.x = pivot.x; temp.y = rectangleCell.height - pivot.y; PropertyMaterial.SetVector(IDMaterialPivotCell, temp); CellPrevious = Cell; } InstanceSpriteRenderer.SetPropertyBlock(PropertyMaterial); } return; } /* Mask (SpriteMask) */ #if UNITY_2017_1_OR_NEWER if (null != InstanceSpriteMask) { if (OrderInLayerPrevious != sortingOrder) { InstanceSpriteMask.frontSortingOrder = sortingOrder; InstanceSpriteMask.backSortingOrder = sortingOrderBase - PartsRoot.SortingOffsetPartsDraw; OrderInLayerPrevious = sortingOrder; } if (null != Cell) { InstanceSpriteMask.sprite = Cell; Cell = null; } return; } #else /* MEMO: Can not use "SpriteMask" in Unity5.6 or earlier. */ /* (For "Nintendo Switch" for the time being, corresponds to Unity5.6 or earlier) */ #endif /* Mesh (SkinnedMeshRenderer) */ if (null != InstanceSkinnedMeshRenderer) { if (OrderInLayerPrevious != sortingOrder) { InstanceSkinnedMeshRenderer.sortingOrder = sortingOrder; OrderInLayerPrevious = sortingOrder; } if (CellMeshPrevious != CellMesh) { if (null == InstanceCellMesh) { InstanceCellMesh = new Mesh(); if (null == InstanceCellMesh) { /* Error */ return; } } /* Re-Set Mesh */ InstanceCellMesh.Clear(); InstanceCellMesh.name = CellMesh.name; InstanceCellMesh.vertices = CellMesh.vertices; InstanceCellMesh.uv = CellMesh.uv; InstanceCellMesh.triangles = CellMesh.triangles; InstanceCellMesh.boneWeights = CellMesh.boneWeights; InstanceCellMesh.bindposes = TableMatrixBindPose; InstanceSkinnedMeshRenderer.sharedMesh = InstanceCellMesh; CellMeshPrevious = CellMesh; } if (TextureMeshPrevious != TextureMesh) { InstanceSkinnedMeshRenderer.GetPropertyBlock(PropertyMaterial); PropertyMaterial.SetTexture(IDMaterialMainTexture, TextureMesh); InstanceSkinnedMeshRenderer.SetPropertyBlock(PropertyMaterial); TextureMeshPrevious = TextureMesh; } return; } /* Mesh (SkinnedMeshRenderer) */ if (null != InstanceMeshRenderer) { if (OrderInLayerPrevious != sortingOrder) { InstanceMeshRenderer.sortingOrder = sortingOrder; OrderInLayerPrevious = sortingOrder; } if (CellMeshPrevious != CellMesh) { if (null == InstanceCellMesh) { InstanceCellMesh = new Mesh(); if (null == InstanceCellMesh) { /* Error */ return; } } /* Re-Set Mesh */ InstanceCellMesh.Clear(); InstanceCellMesh.name = CellMesh.name; InstanceCellMesh.vertices = CellMesh.vertices; InstanceCellMesh.uv = CellMesh.uv; InstanceCellMesh.triangles = CellMesh.triangles; // InstanceCellMesh.boneWeights = // InstanceCellMesh.bindposes = InstanceMeshFilter.sharedMesh = InstanceCellMesh; CellMeshPrevious = CellMesh; } if (TextureMeshPrevious != TextureMesh) { InstanceMeshRenderer.GetPropertyBlock(PropertyMaterial); PropertyMaterial.SetTexture(IDMaterialMainTexture, TextureMesh); InstanceMeshRenderer.SetPropertyBlock(PropertyMaterial); TextureMeshPrevious = TextureMesh; } return; } }
private void UpdateOutline() { if (meshRenderer == null) { return; } if (mpb == null) { mpb = new MaterialPropertyBlock(); } //머리 색상 meshRenderer.GetPropertyBlock(mpb, 0); mpb.SetColor("_Color", hair_Color); mpb.SetColor("_ColorDim", hair_Color * 1.5f); mpb.SetColor("_ColorDimExtra", hair_Color); meshRenderer.SetPropertyBlock(mpb, 0); //피부 색상 meshRenderer.GetPropertyBlock(mpb, 1); mpb.SetColor("_Color", skin_Color); mpb.SetColor("_ColorDim", skin_Color * skin_Color); mpb.SetColor("_ColorDimExtra", skin_Color * skin_Color * skin_Color); meshRenderer.SetPropertyBlock(mpb, 1); meshRenderer.GetPropertyBlock(mpb, 2); mpb.SetColor("_Color", skin_Color * 1.2f); mpb.SetColor("_ColorDim", skin_Color * skin_Color * 1.2f); mpb.SetColor("_ColorDimExtra", skin_Color * skin_Color * skin_Color * 1.2f); meshRenderer.SetPropertyBlock(mpb, 2); meshRenderer.GetPropertyBlock(mpb, 3); mpb.SetColor("_Color", skin_Color * 1.2f); mpb.SetColor("_ColorDim", skin_Color * skin_Color * 1.2f); mpb.SetColor("_ColorDimExtra", skin_Color * skin_Color * skin_Color * 1.2f); meshRenderer.SetPropertyBlock(mpb, 3); //옷 색상 meshRenderer.GetPropertyBlock(mpb, 4); mpb.SetColor("_Color", cloth_Color); mpb.SetColor("_ColorDim", cloth_Color * cloth_Color); mpb.SetColor("_ColorDimExtra", cloth_Color * cloth_Color * cloth_Color); meshRenderer.SetPropertyBlock(mpb, 4); meshRenderer.GetPropertyBlock(mpb, 7); mpb.SetColor("_Color", cloth_Color * 1.5f); mpb.SetColor("_ColorDim", cloth_Color * cloth_Color * 1.5f); mpb.SetColor("_ColorDimExtra", cloth_Color * cloth_Color * cloth_Color * 1.5f); meshRenderer.SetPropertyBlock(mpb, 7); //눈 meshRenderer.GetPropertyBlock(mpb, 3); mpb.SetTexture("_MainTex", eye_Tex[eye_Num]); meshRenderer.SetPropertyBlock(mpb, 3); //입 meshRenderer.GetPropertyBlock(mpb, 2); mpb.SetTexture("_MainTex", mouth_Tex[mouth_Num]); meshRenderer.SetPropertyBlock(mpb, 2); for (int i = 0; i < 10; i++) { Color temp; //기타 meshRenderer.GetPropertyBlock(mpb, i); temp = mpb.GetColor("_Color"); temp = new Color(temp.r, temp.g, temp.b, alpha ? 0 : 1); mpb.SetColor("_Color", temp); temp = mpb.GetColor("_ColorDim"); temp = new Color(temp.r, temp.g, temp.b, alpha ? 0 : 1); mpb.SetColor("_ColorDim", temp); temp = mpb.GetColor("_ColorDimExtra"); temp = new Color(temp.r, temp.g, temp.b, alpha ? 0 : 1); mpb.SetColor("_ColorDimExtra", temp); meshRenderer.SetPropertyBlock(mpb, i); } }
private void UpdateOutline() { if (meshRenderer == null) { return; } if (mpb == null) { mpb = new MaterialPropertyBlock(); } //옷색깔 meshRenderer.GetPropertyBlock(mpb, 0); mpb.SetColor("_BaseColor", cloth_Color); mpb.SetColor("_1st_ShadeColor", cloth_Color); mpb.SetColor("_2st_ShadeColor", cloth_Color); mpb.SetColor("_Outline_Color", cloth_Color); meshRenderer.SetPropertyBlock(mpb, 0); //1번색깔 meshRenderer.GetPropertyBlock(mpb, 1); mpb.SetColor("_BaseColor", base_Color1); mpb.SetColor("_1st_ShadeColor", base_Color1); mpb.SetColor("_2st_ShadeColor", base_Color1); mpb.SetColor("_Outline_Color", base_Color1); meshRenderer.SetPropertyBlock(mpb, 1); meshRenderer.GetPropertyBlock(mpb, 5); mpb.SetColor("_BaseColor", base_Color1); mpb.SetColor("_1st_ShadeColor", base_Color1); mpb.SetColor("_2st_ShadeColor", base_Color1); mpb.SetColor("_Outline_Color", base_Color1); meshRenderer.SetPropertyBlock(mpb, 5); //2번색깔 meshRenderer.GetPropertyBlock(mpb, 2); mpb.SetColor("_BaseColor", base_Color2); mpb.SetColor("_1st_ShadeColor", base_Color2); mpb.SetColor("_2st_ShadeColor", base_Color2); mpb.SetColor("_Outline_Color", base_Color2); meshRenderer.SetPropertyBlock(mpb, 2); meshRenderer.GetPropertyBlock(mpb, 6); mpb.SetColor("_BaseColor", base_Color2); mpb.SetColor("_1st_ShadeColor", base_Color2); mpb.SetColor("_2st_ShadeColor", base_Color2); mpb.SetColor("_Outline_Color", base_Color2); meshRenderer.SetPropertyBlock(mpb, 6); //얼굴 face_Num = Mathf.Min(face_Num, face_Tex.Count - 1); face_Num = Mathf.Max(face_Num, 0); if (face_Num >= 0) { meshRenderer.GetPropertyBlock(mpb, 1); mpb.SetTexture("_MainTex", face_Tex[face_Num]); mpb.SetTexture("_1st_ShadeMap", face_Tex[face_Num]); mpb.SetTexture("_2st_ShadeMap", face_Tex[face_Num]); meshRenderer.SetPropertyBlock(mpb, 1); meshRenderer.GetPropertyBlock(mpb, 2); mpb.SetTexture("_MainTex", face_Tex[face_Num]); mpb.SetTexture("_1st_ShadeMap", face_Tex[face_Num]); mpb.SetTexture("_2st_ShadeMap", face_Tex[face_Num]); meshRenderer.SetPropertyBlock(mpb, 2); } //입 mouth_Num = Mathf.Min(mouth_Num, mouth_Tex.Count - 1); mouth_Num = Mathf.Max(mouth_Num, 0); if (mouth_Num >= 0) { meshRenderer.GetPropertyBlock(mpb, 8); mpb.SetTexture("_MainTex", mouth_Tex[mouth_Num]); mpb.SetTexture("_1st_ShadeMap", mouth_Tex[mouth_Num]); mpb.SetTexture("_2st_ShadeMap", mouth_Tex[mouth_Num]); meshRenderer.SetPropertyBlock(mpb, 8); } //옷 cloth_Num = Mathf.Min(cloth_Num, cloth_Tex.Count - 1); cloth_Num = Mathf.Max(cloth_Num, 0); if (cloth_Num >= 0) { meshRenderer.GetPropertyBlock(mpb, 0); mpb.SetTexture("_MainTex", cloth_Tex[cloth_Num]); mpb.SetTexture("_1st_ShadeMap", cloth_Tex[cloth_Num]); mpb.SetTexture("_2st_ShadeMap", cloth_Tex[cloth_Num]); meshRenderer.SetPropertyBlock(mpb, 0); } }