Пример #1
0
    private void Update()
    {
        if (!rgb_Tex || !z_Tex)
        {
            RefreshTextures();
        }

        if (frustum.IsPointInsideFrustum(Camera.main.transform.position, 0.1f))
        {
            EffectMaterial.EnableKeyword("CAMERA_INSIDE");
            EffectMaterial.DisableKeyword("CAMERA_OUTSIDE");

            EffectMaterial.SetFloat("_Cull", 1);
        }
        else
        {
            EffectMaterial.EnableKeyword("CAMERA_OUTSIDE");
            EffectMaterial.DisableKeyword("CAMERA_INSIDE");

            EffectMaterial.SetFloat("_Cull", 2);
        }

        EffectMaterial.SetFloat("_farClip", frustum.farClip);
        EffectMaterial.SetFloat("_nearClip", frustum.nearClip);
        EffectMaterial.SetTexture("_MainTex", rgb_Tex);
        EffectMaterial.SetTexture("_zTex", z_Tex);
        EffectMaterial.SetVector("_eyeFwd", transform.forward);
    }
Пример #2
0
    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;
        }

        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);
    }
Пример #4
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.
    }
Пример #5
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination);
            return;
        }

        EffectMaterial.SetColor("_Color1", color1);
        EffectMaterial.SetColor("_Color2", color2);
        EffectMaterial.SetColor("_Color3", color3);
        EffectMaterial.SetColor("_Color4", color4);
        EffectMaterial.SetColor("_Color5", color5);
        EffectMaterial.SetVector("_LightPos", SunLight.position);
        EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance);
        EffectMaterial.SetVector("_CameraWP", CurrentCamera.transform.position);
        EffectMaterial.SetFloat("_FovX", CurrentCamera.fieldOfView * Mathf.Deg2Rad);
        EffectMaterial.SetVector("_CamForward", CurrentCamera.transform.forward.normalized);
        EffectMaterial.SetVector("_CamUp", CurrentCamera.transform.up.normalized);
        EffectMaterial.SetVector("_CamRight", CurrentCamera.transform.right.normalized);
        EffectMaterial.SetFloat("_AspectRatio", CurrentCamera.aspect);
        EffectMaterial.SetFloat("_LightStrength", lightStrength);


        Graphics.Blit(source, destination, EffectMaterial);
    }
Пример #6
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
    }
Пример #7
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", 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);
    }
Пример #8
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);
    }
Пример #9
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);
    }
Пример #10
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.SetVector("_CameraDir", CurrentCamera.transform.forward);
        EffectMaterial.SetVector("_ScreenResolution", new Vector2(Screen.width, Screen.height));


        CustomGraphicsBlit(source, destination, EffectMaterial, 0); // Replace Graphics.Blit with CustomGraphicsBlit
    }
Пример #11
0
    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
    }
Пример #12
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);
 }
Пример #13
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);
    }
Пример #14
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);
    }
Пример #15
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);
    }
Пример #17
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
    }
Пример #18
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);
    }
Пример #19
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);
    }
Пример #20
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);
    }
Пример #21
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }

        var cameraParams = new Vector4(currentCamera.sensorSize.x, currentCamera.sensorSize.y, currentCamera.focalLength, m_Aperture);

        if (currentCamera.transform.position != m_CameraPrevPos ||
            currentCamera.transform.rotation != m_CameraPrevRot ||
            m_Render == null ||
            m_Render.width != destination.width ||
            m_Render.height != destination.height ||
            m_ShouldReset ||
            m_Sun.intensity != m_SunPrevIntensity ||
            m_Sun.color != m_SunPrevColor ||
            m_Sun.transform.forward != m_SunPrevDir ||
            cameraParams != m_PrevCameraParams ||
            m_SunSize != m_SunPrevSize)
        {
            // Reset renderer
            //Debug.Log("Resetting renderer...");

            if (m_Render == null ||
                m_Render.width != destination.width ||
                m_Render.height != destination.height)
            {
                m_Render = new RenderTexture(destination.width, destination.height, 0, RenderTextureFormat.ARGBFloat);
            }

            m_CameraPrevPos = currentCamera.transform.position;
            m_CameraPrevRot = currentCamera.transform.rotation;

            m_SunPrevIntensity = m_Sun.intensity;
            m_SunPrevColor     = m_Sun.color;
            m_SunPrevDir       = m_Sun.transform.forward;
            m_SunPrevSize      = m_SunSize;

            m_PrevCameraParams = cameraParams;

            m_IntegrationCount = 0;

            m_ShouldReset = false;
        }

        if (m_Sun)
        {
            Vector3 sunColor = new Vector3(m_Sun.color.r, m_Sun.color.g, m_Sun.color.b) * m_Sun.intensity;
            EffectMaterial.SetVector("_SunColor", sunColor);
            EffectMaterial.SetVector("_SunDir", m_Sun.transform.forward);
            EffectMaterial.SetFloat("_SunSize", m_SunSize);
        }

        if (m_ReflectionProbe)
        {
            m_ReflectionProbe.RenderProbe();
            EffectMaterial.SetTexture("_IBLTex", m_ReflectionProbe.texture);
        }

        EffectMaterial.SetVector("_CameraRight", currentCamera.transform.right);
        EffectMaterial.SetVector("_CameraUp", currentCamera.transform.up);
        EffectMaterial.SetVector("_CameraForward", currentCamera.transform.forward);
        EffectMaterial.SetVector("_CameraParams", cameraParams);
        EffectMaterial.SetFloat("_IntegrationCount", m_IntegrationCount);

        EffectMaterial.SetVector("_Random", new Vector4(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)));

        Graphics.Blit(source, m_Render, EffectMaterial, 0);

        m_IntegrationCount++;

        Graphics.Blit(m_Render, destination);
    }
    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);
    }