private 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);

        // pass textures to shader
        EffectMaterial.SetTexture("_rgbTex", rgb_tex);
        EffectMaterial.SetTexture("_zTex", z_tex);



        // pass eye intrinsics & extrinsics to shader
        EffectMaterial.SetMatrix("_eyeExtrinsics", EyeDataCollection.eyes[0].Extrinsics);
        EffectMaterial.SetMatrix("_eyeIntrinsics", EyeDataCollection.eyes[0].Intrinsics);
        EffectMaterial.SetVector("_eyeUV", EyeDataCollection.eyes[0].UV);

        CustomGraphicsBlit(source, destination, EffectMaterial, 0); // use given effect shader as image effec
    }
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        // Set any custom shader variables here.  For example, you could do:
        // EffectMaterial.SetFloat("_MyVariable", 13.37f);
        // This would set the shader uniform _MyVariable to value 13.37

        EffectMaterial.SetVector("_LightDir", lightTransform ? lightTransform.forward : Vector3.down);

        //// Construct a Model Matrix for the Torus
        //Matrix4x4 MatTorus = Matrix4x4.TRS(
        //    Vector3.right * Mathf.Sin(Time.time) * 5,
        //    Quaternion.identity,
        //    Vector3.one);
        //MatTorus *= Matrix4x4.TRS(
        //    Vector3.zero,
        //    Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)),
        //    Vector3.one);
        //// Send the torus matrix to our shader
        //EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse);

        EffectMaterial.SetColor("_Color", mainColor);
        if (matColorRamp)
        {
            EffectMaterial.SetTexture("_ColorRamp_Material", matColorRamp);
        }
        if (perfColorRamp)
        {
            EffectMaterial.SetTexture("_ColorRamp_PerfMap", perfColorRamp);
        }
        if (densColorRamp)
        {
            EffectMaterial.SetTexture("_ColorRamp_Density", densColorRamp);
        }

        EffectMaterial.SetFloat("_DrawDistance", rayMarchMaxDist);

        if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != debugPerformance)
        {
            if (debugPerformance)
            {
                EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE");
            }
            else
            {
                EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE");
            }
        }

        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
Exemple #3
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.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);
        EffectMaterial.SetTexture("_ColorRamp", _ColorRamp);

        // Construct a Model Matrix for the Torus
        Matrix4x4 MatTorus = Matrix4x4.TRS(
            Vector3.right * Mathf.Sin(Time.time) * 5,
            Quaternion.identity,
            Vector3.one);

        MatTorus *= Matrix4x4.TRS(
            Vector3.zero,
            Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)),
            Vector3.one);
        // Send the torus matrix to our shader
        EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse);


        CustomGraphicsBlit(source, destination, EffectMaterial, 0); // Replace Graphics.Blit with CustomGraphicsBlit
    }
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination);             // do nothing
            return;
        }

        Matrix4x4 MatTorus = Matrix4x4.TRS(
            Vector3.right * Mathf.Sin(Time.time) * 5,
            Quaternion.identity,
            Vector3.one);

        MatTorus *= Matrix4x4.TRS(
            Vector3.zero,
            Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)),
            Vector3.one);

        // pass frustum rays to shader
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);
        EffectMaterial.SetFloat("move", move);
        EffectMaterial.SetFloat("eegData", gameObject.GetComponent <Muse>().eeg_data[0]);
        EffectMaterial.SetFloat("time", Time.time);
        EffectMaterial.SetTexture("_ColorRamp", _ColorRamp);

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
Exemple #5
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        //Construct a Model Matrix for this Torus
        Matrix4x4 MatTorus = Matrix4x4.TRS(Vector3.right * Mathf.Sin(Time.time) * 5, Quaternion.identity, Vector3.one);

        MatTorus *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(0, 0, (Time.time * 200.0f) % 360)), Vector3.one);
        EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse);

        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.transform.forward : Vector3.down);
        EffectMaterial.SetVector("_LightColor", SunLight ? SunLight.color : Color.white);
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);

        //To add my stuff here later
        //If youre seeing this, im gonna alter this code to my benefit. thank you.
    }
Exemple #6
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            //位块传输,简单的赋值
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        // Set any custom shader variables here.  For example, you could do:
        // EffectMaterial.SetFloat("_MyVariable", 13.37f);
        // This would set the shader uniform _MyVariable to value 13.37
        //设置着色器参数
        //光线方向,世界坐标系
        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);

        // Construct a Model Matrix for the Torus
        Matrix4x4 MatTorus = Matrix4x4.TRS(
            Vector3.right * Mathf.Sin(Time.time) * 5,
            Quaternion.identity,
            Vector3.one);

        MatTorus *= Matrix4x4.TRS(
            Vector3.zero,
            Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)),
            Vector3.one);
        // Send the torus matrix to our shader
        //圆环的模型转世界矩阵,定义了圆环的运动
        EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse);

        EffectMaterial.SetTexture("_ColorRamp_Material", _MaterialColorRamp);
        EffectMaterial.SetTexture("_ColorRamp_PerfMap", _PerfColorRamp);
        //rayMarch算法最大前进距离
        EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance);
        //性能调试开关
        if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != _DebugPerformance)
        {
            if (_DebugPerformance)
            {
                EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE");
            }
            else
            {
                EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE");
            }
        }
        //视椎体顶点向量矩阵,摄像机坐标系
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        //摄像机转世界矩阵
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        //摄像机位置,世界坐标系
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }
        //if (!RenderMaterial)
        //{
        //    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.SetTexture("_cloudNoise3D", CloudTex3D);
        EffectMaterial.SetFloat("_cutoff", CutOff);
        EffectMaterial.SetFloat("_cloudScale", CloudScale);
        EffectMaterial.SetTexture("_heightTex", HeightTex);
        EffectMaterial.SetFloat("_cloudBase", CloudBase);
        EffectMaterial.SetFloat("_layerHeight", LayerHeight);
        EffectMaterial.SetTexture("_randomNoiseTex", BlueNoise);
        //EffectMaterial.SetVector("_lightDir", SkyLight.transform.forward);
        EffectMaterial.SetTexture("_detailTex", DetailTex);
        EffectMaterial.SetFloat("_edgeScale", EdgeScale);
        EffectMaterial.SetFloat("_erodeDepth", ErodeDepth);
        EffectMaterial.SetFloat("_coverage", Coverage);
        EffectMaterial.SetFloat("_BeerLaw", BeerLaw);
        EffectMaterial.SetFloat("_SilverIntensity", SilverIntensity);
        EffectMaterial.SetFloat("_SilverSpread", SilverSpread);
        EffectMaterial.SetTexture("_CurlNoise", CurlNoise);
        EffectMaterial.SetFloat("_CurlTile", CurlTile);
        EffectMaterial.SetFloat("_CurlStrength", CurlStrength);
        EffectMaterial.SetFloat("_CloudTopOffset", TopOffset);
        EffectMaterial.SetFloat("_MaxDistance", MaxDistance);

        EffectMaterial.SetTexture("_WeatherTex", WeatherTex);
        EffectMaterial.SetFloat("_WeatherTexSize", WeatherTexSize);
        EffectMaterial.SetFloat("_nearestRenderDistance", nearestRenderDistance);
        Matrix4x4 projectionMatrix = GL.GetGPUProjectionMatrix(_CurrentCamera.projectionMatrix, false);

        projectionMatrix = GL.GetGPUProjectionMatrix(_ShadowCamera.projectionMatrix, false);
        EffectMaterial.SetMatrix("_inverseVP", Matrix4x4.Inverse(projectionMatrix * _CurrentCamera.worldToCameraMatrix));
        EffectMaterial.SetMatrix("_WorldToShadow", projectionMatrix * _ShadowCamera.worldToCameraMatrix);
        EffectMaterial.SetFloat("_WindSpeed", WindSpeed);
        EffectMaterial.SetFloat("_cloudDensity", CloudDensity);


        CustomGraphicsBlit(null, cloud, EffectMaterial, 0);
        RenderMaterial.SetTexture("cloudTexture", cloud);
        Graphics.Blit(source, destination, RenderMaterial);
    }
    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.SetVector("_CameraDir", CurrentCamera.transform.forward);
        EffectMaterial.SetVector("_ScreenResolution", new Vector2(Screen.width, Screen.height));


        CustomGraphicsBlit(source, destination, EffectMaterial, 0); // Replace Graphics.Blit with CustomGraphicsBlit
    }
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);
        EffectMaterial.SetVector("_LightDir", mSunLight ? mSunLight.forward : Vector3.down);
        EffectMaterial.SetInt("_MaxStep", Application.isPlaying ? MaxSteps : 256);
        EffectMaterial.SetFloat("_MaxDist", Application.isPlaying ? MaxDistance : 10);

        Extensions.CustomGraphicsBlit(source, destination, EffectMaterial, 0); // use given effect shader as image effect
    }
Exemple #10
0
 public void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     EffectMaterial.SetFloat("_1", arg1);
     EffectMaterial.SetFloat("_2", arg2);
     EffectMaterial.SetFloat("_3", arg3);
     EffectMaterial.SetFloat("_4", arg4);
     EffectMaterial.SetFloat("_5", arg5);
     EffectMaterial.SetFloat("_6", arg6);
     EffectMaterial.SetFloat("_7", arg7);
     EffectMaterial.SetFloat("_8", arg8);
     EffectMaterial.SetFloat("_9", arg9);
     EffectMaterial.SetFloat("_10", arg10);
     EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);
     EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
     EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
     EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);
     CustomGraphicsBlit(source, destination, EffectMaterial, 0);
 }
Exemple #11
0
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination);
            return;
        }

        EffectMaterial.SetColor("_ringColor", ringColor);
        EffectMaterial.SetFloat("radius", radius);
        EffectMaterial.SetFloat("thickness", thickness);
        EffectMaterial.SetVector("ringCenter", sourceTransform.position);
        EffectMaterial.SetVector("cameraPositionWS", MainCamera.transform.position);
        EffectMaterial.SetMatrix("cameraToWorldMatrix", MainCamera.cameraToWorldMatrix);
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(MainCamera));

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
Exemple #12
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        // Set any custom shader variables here.  For example, you could do:
        // EffectMaterial.SetFloat("_MyVariable", 13.37f);
        // This would set the shader uniform _MyVariable to value 13.37

        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);

        // Construct a Model Matrix for the Torus

        /*Matrix4x4 ObjMatrix = Matrix4x4.TRS(
         *  //Vector3.right * Mathf.Sin(Time.time) * 5,
         *  Vector3.forward * 3,
         *  Quaternion.identity,
         *  Vector3.one);
         * ObjMatrix *= Matrix4x4.TRS(
         *  Vector3.zero,
         *  Quaternion.Euler(new Vector3(0, 0, (Time.time * 20) % 360)),
         *  Vector3.one);*/

        // Testing a custom model matrix
        Matrix4x4 ObjMatrix = Matrix4x4.TRS(
            Vector3.zero,
            Quaternion.Euler(new Vector3(0, 0, (Time.time * 30) % 360)),
            Vector3.one);

        // Send the torus matrix to our shader
        EffectMaterial.SetMatrix("_ObjMatrix_InvModel", ObjMatrix.inverse);

        EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance);

        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
Exemple #13
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
    }
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        // Set any custom shader variables here.  For example, you could do:
        // EffectMaterial.SetFloat("_MyVariable", 13.37f);
        // This would set the shader uniform _MyVariable to value 13.37

        conductor?.PopulateUniforms(EffectMaterial);

        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);


        EffectMaterial.SetTexture("_ColorRamp_Material", _MaterialColorRamp);
        EffectMaterial.SetTexture("_ColorRamp_PerfMap", _PerfColorRamp);

        EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance);

        if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != _DebugPerformance)
        {
            if (_DebugPerformance)
            {
                EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE");
            }
            else
            {
                EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE");
            }
        }

        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        EffectMaterial.SetVector("_Resolution", new Vector2((float)Camera.main.pixelWidth, (float)Camera.main.pixelHeight));

        CustomGraphicsBlit(source, destination, EffectMaterial, 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.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);
        EffectMaterial.SetTexture("_ColorRamp", _ColorRamp);
        EffectMaterial.SetTexture("_ColorSky", _ColorSky);

        // Graphics.Blit(source, destination, EffectMaterial, 0); // use given effect shader as image effect
        CustomGraphicsBlit(source, destination, EffectMaterial, 0); // Replace Graphics.Blit with CustomGraphicsBlit
    }
Exemple #16
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination);
            return;
        }

        var shapesData0Arr = new Vector4[_shapes.Count];
        var shapesData1Arr = new Vector4[_shapes.Count];

        for (int i = 0; i < _shapes.Count; i++)
        {
            var shape    = _shapes[i];
            var shapePos = shape.transform.position;
            shapesData0Arr[i] = new Vector4((float)shape.Type, (float)shape.Operator);
            if (shape.Type == RayMarchingShapeType.Sphere)
            {
                shapesData1Arr[i] = new Vector4(shapePos.x, shapePos.y, shapePos.z, shape.transform.localScale.x);
            }
            else if (shape.Type == RayMarchingShapeType.Box)
            {
                shapesData1Arr[i] = new Vector4(shapePos.x, shapePos.y, shapePos.z, shape.transform.localScale.x);
            }
        }

        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);
        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);
        if (_shapes.Count > 0)
        {
            EffectMaterial.SetInt("_ShapesCount", _shapes.Count);
            EffectMaterial.SetVectorArray("_ShapesData0Arr", shapesData0Arr);
            EffectMaterial.SetVectorArray("_ShapesData1Arr", shapesData1Arr);
        }

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
Exemple #17
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        //Construct a Model Matrix for this Torus
        Matrix4x4 MatTorus = Matrix4x4.TRS(Vector3.right * 5, Quaternion.identity, Vector3.one);

        MatTorus *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(0, 0, 90)), Vector3.one);
        EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse);

        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.transform.forward : Vector3.down);
        EffectMaterial.SetVector("_LightColor", SunLight ? SunLight.color : Color.white);
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        // Set any custom shader variables here.  For example, you could do:
        // EffectMaterial.SetFloat("_MyVariable", 13.37f);
        // This would set the shader uniform _MyVariable to value 13.37

        EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down);

        // Construct a Model Matrix for the Torus
        Matrix4x4 MatTorus = Matrix4x4.TRS(
            Vector3.right * Mathf.Sin(Time.time) * 5,
            Quaternion.identity,
            Vector3.one);

        MatTorus *= Matrix4x4.TRS(
            Vector3.zero,
            Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)),
            Vector3.one);

        // Send the torus matrix to our shader
        EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse);

        EffectMaterial.SetTexture("_ColorRamp_Material", _MaterialColorRamp);
        EffectMaterial.SetTexture("_ColorRamp_PerfMap", _PerfColorRamp);

        EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance);

        if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != _DebugPerformance)
        {
            if (_DebugPerformance)
            {
                EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE");
            }
            else
            {
                EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE");
            }
        }

        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        //Matrix4x4 partPos = new Matrix4x4(
        //    new Vector4(-0.5f + (Mathf.Sin(Time.time)+1.0f)/2.0f, 0.5f - (Mathf.Sin(Time.time) + 1.0f) / 2.0f, 0.0f, 0.2f),
        //    new Vector4(-0.5f, -0.5f, 0.0f, 0.2f),
        //    new Vector4(0.5f, 0.5f, 0.0f, 0.2f),
        //    new Vector4(0.5f, -0.5f, 0.0f, 0.2f)
        //);

        EffectMaterial.SetMatrix("_PartPos", pm.Particules);

        EffectMaterial.SetVector("_Resolution", new Vector2((float)Camera.main.pixelWidth, (float)Camera.main.pixelHeight));

        CustomGraphicsBlit(source, destination, EffectMaterial, 0);
    }
Exemple #19
0
    private void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        // if for some reason there is no material or if there are no Objects, do nothing
        if (!EffectMaterial || _objs == null || _objs.Count == 0)
        {
            Graphics.Blit(src, dest);
            return;
        }

        // sort the Objects by depth
        _objs.Sort((x, y) => (int)Mathf.Clamp(CurrentCamera.transform.InverseTransformPoint(y.transform.position).z - CurrentCamera.transform.InverseTransformPoint(x.transform.position).z, -1, 1));

        // set general shader values for camera
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position);

        // set general shader values for raymarching
        EffectMaterial.SetVector("_RaymarchingParams", new Vector4(StepCount, StepCountInsideVolume, StepSize, DrawDist));

        // create to temporary Render textures as buffers
        RenderTexture temp0 = RenderTexture.GetTemporary(src.width, src.height, 0, src.format);
        RenderTexture temp1 = RenderTexture.GetTemporary(src.width, src.height, 0, src.format);

        // this is a variable for storing which buffer we last used
        int lastUsed = 0;

        // render all objects
        for (int i = 0; i < _objs.Count; ++i)
        {
            VolumetricObject obj = _objs[i];
            // set shader values that are type dependend
            VolumetricObject.Types t = obj.Type;
            switch (t)
            {
            case VolumetricObject.Types.BOX:
                EffectMaterial.SetInt("_Type", 0);
                EffectMaterial.SetVector("_BoxDimensions", obj.Dimensions * 0.5f);
                break;

            case VolumetricObject.Types.SPHERE:
                EffectMaterial.SetInt("_Type", 1);
                EffectMaterial.SetFloat("_SphereRad", obj.Radius);
                break;

            case VolumetricObject.Types.CAPSULE:
                EffectMaterial.SetInt("_Type", 2);
                EffectMaterial.SetMatrix("_CapsuleBounds", obj.CapsuleParams);
                break;
            }

            // set non type dependent per Object values
            EffectMaterial.SetColor("_Color", obj.Color);

            Color dc = obj.DenseColor;
            dc.a = obj.UseDenseColor ? 1 : 0;
            EffectMaterial.SetColor("_DenseColor", dc);

            EffectMaterial.SetVector("_FogOptions", new Vector4(obj.Density, (float)obj.Falloff, (float)obj.BlendMode, 0));
            EffectMaterial.SetMatrix("_Noise_STO", obj.NoiseSTO);
            EffectMaterial.SetMatrix("_InvModel", obj.transform.localToWorldMatrix.inverse);

            // render the Object by alternating between buffers
            if (i == 0)
            {
                CustomGraphicsBlit(src, temp0, EffectMaterial, 0);
                lastUsed = 0;
            }
            else if (i % 2 == 0)
            {
                CustomGraphicsBlit(temp1, temp0, EffectMaterial, 0);
                lastUsed = 0;
            }
            else
            {
                CustomGraphicsBlit(temp0, temp1, EffectMaterial, 0);
                lastUsed = 1;
            }
        }

        // render final render texture
        Graphics.Blit(lastUsed == 1 ? temp1 : temp0, dest);

        // clean up buffers
        RenderTexture.ReleaseTemporary(temp0);
        RenderTexture.ReleaseTemporary(temp1);
    }