private void DoTheBlits() { // get temp RTs RenderTexture posRT = RenderTexture.GetTemporary(processor.positionTexture.width, processor.positionTexture.height, processor.positionTexture.depth, processor.positionTexture.format); posRT.filterMode = FilterMode.Point; RenderTexture normRT = RenderTexture.GetTemporary(processor.normalTexture.width, processor.normalTexture.height, processor.normalTexture.depth, processor.normalTexture.format); normRT.filterMode = FilterMode.Point; RenderTexture tanRT = RenderTexture.GetTemporary(processor.tangentTexture.width, processor.tangentTexture.height, processor.tangentTexture.depth, processor.tangentTexture.format); tanRT.filterMode = FilterMode.Point; // blit using bone material targetBufferCache[0] = posRT.colorBuffer; targetBufferCache[1] = normRT.colorBuffer; targetBufferCache[2] = tanRT.colorBuffer; Graphics.SetRenderTarget(targetBufferCache, posRT.depthBuffer); // process morphs if (bakedFurMorphResources != null) { for (int i = 0; i < bakedFurMorphResources.Length; ++i) { BakedMorph bakedFurMorph = bakedFurMorphResources[i].value; //use this weight for morph targets float blendWeight = processor.neoFurAsset.skinnedMeshRenderer.GetBlendShapeWeight(i) / 100; if (blendWeight == 0) { continue; } // set material properties boneMaterial.SetFloat("_BlendWeight", blendWeight); boneMaterial.SetTexture("_BlendPosOffsetTexture", bakedFurMorph.positionOffsetTexture); boneMaterial.SetTexture("_BlendNormOffsetTexture", bakedFurMorph.normalOffsetTexture); boneMaterial.SetTexture("_BlendTanOffsetTexture", bakedFurMorph.tangentOffsetTexture); // blit using bone material targetBufferCache[0] = posRT.colorBuffer; targetBufferCache[1] = normRT.colorBuffer; targetBufferCache[2] = tanRT.colorBuffer; Graphics.SetRenderTarget(targetBufferCache, posRT.depthBuffer); // blit to target buffer cache Graphics.Blit(null, boneMaterial, 0); // blit/copy target buffers to processor RTs VertexProcessorUtility.CopyTexture(posRT, processor.positionTexture); VertexProcessorUtility.CopyTexture(normRT, processor.normalTexture); VertexProcessorUtility.CopyTexture(tanRT, processor.tangentTexture); } } ProcessBoneWeights(); // blit using bone material targetBufferCache[0] = posRT.colorBuffer; targetBufferCache[1] = normRT.colorBuffer; targetBufferCache[2] = tanRT.colorBuffer; Graphics.SetRenderTarget(targetBufferCache, posRT.depthBuffer); // blit to target buffer cache Graphics.Blit(null, boneMaterial, 1); // blit/copy target buffers to processor RTs VertexProcessorUtility.CopyTexture(posRT, processor.positionTexture); VertexProcessorUtility.CopyTexture(normRT, processor.normalTexture); VertexProcessorUtility.CopyTexture(tanRT, processor.tangentTexture); // release temp RTs RenderTexture.ReleaseTemporary(posRT); RenderTexture.ReleaseTemporary(normRT); RenderTexture.ReleaseTemporary(tanRT); }
protected override void OnDebugDraw() { base.OnDebugDraw(); Rect rect; if (boneMatrixTexture) { GUILayout.Label("Bone Matrix Texture"); rect = GUILayoutUtility.GetRect(boneMatrixTexture.width * 4, boneMatrixTexture.height * 4, GUILayout.ExpandWidth(false)); GUI.DrawTexture(rect, boneMatrixTexture, ScaleMode.StretchToFill, false); GUILayout.Space(5); } if (boneIndexTextureResource != null) { GUILayout.Label("Bone Index Map Texture"); rect = GUILayoutUtility.GetRect(boneIndexTextureResource.value.width * 4, boneIndexTextureResource.value.height * 4, GUILayout.ExpandWidth(false)); GUI.DrawTexture(rect, boneIndexTextureResource.value, ScaleMode.StretchToFill, false); GUILayout.Space(5); } if (boneWeightTextureResource != null) { GUILayout.Label("Bone Weight Texture"); rect = GUILayoutUtility.GetRect(boneWeightTextureResource.value.width * 4, boneWeightTextureResource.value.height * 4, GUILayout.ExpandWidth(false)); GUI.DrawTexture(rect, boneWeightTextureResource.value, ScaleMode.StretchToFill, false); GUILayout.Space(5); } if (bakedFurMorphResources != null && bakedFurMorphResources.Length > 0) { GUILayout.Label("Morph Target Offsets"); for (int i = 0; i < bakedFurMorphResources.Length; ++i) { BakedMorph morph = bakedFurMorphResources[i].value; GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); GUILayout.BeginVertical(GUILayout.ExpandWidth(false)); GUILayout.Label("Morph " + i + " Position"); rect = GUILayoutUtility.GetRect(morph.positionOffsetTexture.width * 4, morph.positionOffsetTexture.height * 4, GUILayout.ExpandWidth(false)); GUI.DrawTexture(rect, morph.positionOffsetTexture, ScaleMode.StretchToFill, false); GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.ExpandWidth(false)); GUILayout.Label("Morph " + i + " Normal"); rect = GUILayoutUtility.GetRect(morph.normalOffsetTexture.width * 4, morph.normalOffsetTexture.height * 4, GUILayout.ExpandWidth(false)); GUI.DrawTexture(rect, morph.normalOffsetTexture, ScaleMode.StretchToFill, false); GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.ExpandWidth(false)); GUILayout.Label("Morph " + i + " Tangnet"); rect = GUILayoutUtility.GetRect(morph.tangentOffsetTexture.width * 4, morph.tangentOffsetTexture.height * 4, GUILayout.ExpandWidth(false)); GUI.DrawTexture(rect, morph.tangentOffsetTexture, ScaleMode.StretchToFill, false); GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(5); } } }