void Update()
    {
        if (!EffectMaterial || Application.isPlaying && !UpdateField)
        {
            return;
        }

        if (Tree == null)
        {
            return;
        }
        mFigures      = Tree.GetComponentsInChildren <Figure>();
        mFiguresCount = mFigures.Length;

        EffectMaterial.SetInt("_Size", mFiguresCount);

        var numbers    = new float[64];
        var parameters = new Matrix4x4[64];
        var transforms = new Matrix4x4[64];

        for (int i = 0; i < mFiguresCount; i++)
        {
            numbers[i]    = (float)mFigures[i].Type;
            parameters[i] = mFigures[i].Params;
            transforms[i] = mFigures[i].transform.worldToLocalMatrix;
        }

        EffectMaterial.SetFloatArray("_Numbers", numbers);
        EffectMaterial.SetMatrixArray("_Transforms", transforms);
        EffectMaterial.SetMatrixArray("_Params", parameters);
    }
Beispiel #2
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        // pass frustum rays to shader
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);
        EffectMaterial.SetFloat("_Interpolator", t);
        EffectMaterial.SetMatrixArray("_Points", points.Select(x => Matrix4x4.TRS(x.position, x.rotation, x.localScale).inverse).ToArray());
        EffectMaterial.SetInt("_Points_size", points.Count);
        EffectMaterial.SetColor("_LightColor", lightColor);
        EffectMaterial.SetColor("_ShadowColor", shadowColor);
        CustomGraphicsBlit(source, destination, EffectMaterial, 0); // use given effect shader as image effect
    }