Esempio n. 1
0
        void LateUpdate()
        {
            FetchPropertyBlocks();
            {
                if (headDefinition != null)
                {
                    headDefinition.PrepareInstance(ref headInstance, smr, headControllers, warnings);
                    headDefinition.ResolveControllers(ref headInstance);
                    headDefinition.ResolveBlendShapes(ref headInstance, smr);

                    if (injectFittedWeights)
                    {
                        var skinDeform = GetComponent <SkinDeformationRenderer>();
                        if (skinDeform != null && skinDeform.fittedWeightsAvailable)
                        {
                            var fittedWeights = skinDeform.fittedWeights;
                            var inputIndices  = headInstance.blendShapeIndices;
                            var inputWeights  = headInstance.blendShapeWeights;
                            for (int i = 0; i != headInstance.blendShapeIndices.Length; i++)
                            {
                                inputWeights[i] = Mathf.Clamp01(Mathf.Max(injectFittedWeightsScale * fittedWeights[inputIndices[i]], inputWeights[i]));
                            }
                        }

                        headDefinition.ResolveShaderParam(ref headInstance);
                        headDefinition.ResolveBlendShapes(ref headInstance, smr);                        // done again to avoid factoring in fitted weights
                    }
                    else
                    {
                        headDefinition.ResolveShaderParam(ref headInstance);
                    }

                    SnappersHeadDefinition.ApplyControllers(ref headInstance);
                    SnappersHeadDefinition.ApplyBlendShapes(ref headInstance, smr);
                }
                else
                {
                    SnappersHeadDefinition.ResetShaderParam(ref headInstance);
                }

                for (int i = 0; i != materials.Length; i++)
                {
                    SnappersHeadDefinition.ApplyShaderParam(ref headInstance, materials[i].materialProps);
                    materials[i].ApplyTextureSet();
                }
            }
            ApplyPropertyBlocks();
        }
Esempio n. 2
0
        void OnDisable()
        {
            FetchPropertyBlocks();
            {
                if (headInstance.shaderParamFloats != null)                //TODO introduce IsCreated() or similar?
                {
                    SnappersHeadDefinition.ResetShaderParam(ref headInstance);

                    for (int i = 0; i != materials.Length; i++)
                    {
                        SnappersHeadDefinition.ApplyShaderParam(ref headInstance, materials[i].materialProps);
                    }
                }
            }
            ApplyPropertyBlocks();
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        void LateUpdate()
        {
            if (smrProps == null)
            {
                smrProps = new MaterialPropertyBlock();
            }

            smr.GetPropertyBlock(smrProps);
            {
                if (headDefinition != null)
                {
                    headDefinition.PrepareInstance(ref headInstance, smr, headControllers, warnings);
                    headDefinition.ResolveControllers(ref headInstance);
                    headDefinition.ResolveBlendShapes(ref headInstance, smr);

                    if (injectFittedWeights)
                    {
                        var skinDeform = GetComponent <SkinDeformationRenderer>();
                        if (skinDeform != null && skinDeform.fittedWeightsAvailable)
                        {
                            var fittedWeights = skinDeform.fittedWeights;
                            var inputIndices  = headInstance.blendShapeIndices;
                            var inputWeights  = headInstance.blendShapeWeights;
                            for (int i = 0; i != headInstance.blendShapeIndices.Length; i++)
                            {
                                inputWeights[i] = Mathf.Clamp01(Mathf.Max(injectFittedWeightsScale * fittedWeights[inputIndices[i]], inputWeights[i]));
                            }
                        }

                        headDefinition.ResolveShaderParam(ref headInstance);
                        headDefinition.ResolveBlendShapes(ref headInstance, smr);                        // done again to avoid factoring in fitted weights
                    }
                    else
                    {
                        headDefinition.ResolveShaderParam(ref headInstance);
                    }

                    SnappersHeadDefinition.ApplyControllers(ref headInstance);
                    SnappersHeadDefinition.ApplyBlendShapes(ref headInstance, smr);
                    SnappersHeadDefinition.ApplyShaderParam(ref headInstance, smrProps);
                }
                else
                {
                    SnappersHeadDefinition.ResetShaderParam(ref headInstance);
                    SnappersHeadDefinition.ApplyShaderParam(ref headInstance, smrProps);
                }

#if _SNAPPERS_TEXTURE_ARRAYS
                SetTextureChecked(smrProps, "_SnappersMask", arrayMask);
                SetTextureChecked(smrProps, "_SnappersAlbedo", arrayAlbedo);
                SetTextureChecked(smrProps, "_SnappersNormal", arrayNormal);
                SetTextureChecked(smrProps, "_SnappersCavity", arrayCavity);
#else
                SetTextureChecked(smrProps, "_SnappersMask1", mask1);
                SetTextureChecked(smrProps, "_SnappersMask2", mask2);
                SetTextureChecked(smrProps, "_SnappersMask3", mask3);
                SetTextureChecked(smrProps, "_SnappersMask4", mask4);
                SetTextureChecked(smrProps, "_SnappersMask5", mask5);
                SetTextureChecked(smrProps, "_SnappersMask6", mask6);
                SetTextureChecked(smrProps, "_SnappersMask7", mask7);
                SetTextureChecked(smrProps, "_SnappersMask8", mask8);
                SetTextureChecked(smrProps, "_SnappersMask9", mask9);
                SetTextureChecked(smrProps, "_SnappersMask10", mask10);
                SetTextureChecked(smrProps, "_SnappersMask11", mask11);
                SetTextureChecked(smrProps, "_SnappersMask12", mask12);

                SetTextureChecked(smrProps, "_SnappersAlbedo1", albedo1);
                SetTextureChecked(smrProps, "_SnappersAlbedo2", albedo2);
                SetTextureChecked(smrProps, "_SnappersAlbedo3", albedo3);
                SetTextureChecked(smrProps, "_SnappersAlbedo4", albedo4);

                SetTextureChecked(smrProps, "_SnappersNormal1", normal1);
                SetTextureChecked(smrProps, "_SnappersNormal2", normal2);
                SetTextureChecked(smrProps, "_SnappersNormal3", normal3);
                SetTextureChecked(smrProps, "_SnappersNormal4", normal4);

                SetTextureChecked(smrProps, "_SnappersCavity1", cavity1);
                SetTextureChecked(smrProps, "_SnappersCavity2", cavity2);
                SetTextureChecked(smrProps, "_SnappersCavity3", cavity3);
                SetTextureChecked(smrProps, "_SnappersCavity4", cavity4);
#endif
            }
            smr.SetPropertyBlock(smrProps);
        }