コード例 #1
0
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (RaymarchMaterial == null)
        {
            Graphics.Blit(source, destination);
            return;
        }

        RaymarchMaterial.SetVector("_lightDir", directionalLight ? directionalLight.forward : Vector3.down);
        RaymarchMaterial.SetMatrix("_CamFrustum", CamFrustum(Camera));
        RaymarchMaterial.SetMatrix("_CamToWorld", Camera.cameraToWorldMatrix);
        RaymarchMaterial.SetFloat("_maxDistance", maxDistance);
        RaymarchMaterial.SetVector("_sphere1", new Vector4(spherePos.x, spherePos.y, spherePos.z, sphereRadius));

        RenderTexture.active = destination;
        RaymarchMaterial.SetTexture("_MainTex", source);
        GL.PushMatrix();
        GL.LoadOrtho();
        RaymarchMaterial.SetPass(0);
        GL.Begin(GL.QUADS);

        //BL
        GL.MultiTexCoord2(0, 0f, 0f);
        GL.Vertex3(0f, 0f, 3f); // third arg corresponds to the row index of BL set in CamFrustum method, and is retrieved by the shader's vert function
        //BR
        GL.MultiTexCoord2(0, 1f, 0f);
        GL.Vertex3(1f, 0f, 2f);
        //TR
        GL.MultiTexCoord2(0, 1f, 1f);
        GL.Vertex3(1f, 1f, 1f);
        //TL
        GL.MultiTexCoord2(0, 0f, 1f);
        GL.Vertex3(0f, 1f, 0f);

        GL.End();
        GL.PopMatrix();
    }
コード例 #2
0
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!RaymarchMaterial)
        {
            Graphics.Blit(source, destination);
            return;
        }

        //Then we are testing out the new raymarching data input Texture3D so need to set up the shader details differently:
        //Camera Setup
        RaymarchMaterial.SetMatrix("_CamFrustum", CamFrustum(RaymarchingCamera));
        RaymarchMaterial.SetMatrix("_CamToWorld", RaymarchingCamera.cameraToWorldMatrix);

        //Raymarching setup
        RaymarchMaterial.SetInt("_MaxIterations", _MaxIterations);
        RaymarchMaterial.SetFloat("_MaxDistance", _MaxDistance);
        RaymarchMaterial.SetFloat("_Accuracy", _Accuracy);

        //Light
        RaymarchMaterial.SetVector("_LightDirection", _DirectionalLight ? _DirectionalLight.forward : Vector3.down);
        RaymarchMaterial.SetColor("_LightColour", _LightColour);
        RaymarchMaterial.SetFloat("_LightIntensity", _LightIntensity);

        //Shadow
        RaymarchMaterial.SetFloat("_ShadowIntensity", _ShadowIntensity);
        RaymarchMaterial.SetVector("_ShadowDistance", _ShadowDistance);
        RaymarchMaterial.SetFloat("_ShadowPenumbra", _ShadowPenumbra);

        //AO
        RaymarchMaterial.SetFloat("_AmbientOcclusionIntensity", _AmbientOcclusionIntensity);
        RaymarchMaterial.SetFloat("_AmbientOcclusionStepSize", _AmbientOcclusionStepSize);
        RaymarchMaterial.SetInt("_AmbientOcclusionIterations", _AmbientOcclusionIterations);

        //Reflections
        RaymarchMaterial.SetFloat("_ReflectionIntensity", _ReflectionIntensity);
        RaymarchMaterial.SetFloat("_EnvironmentReflectionIntensity", _EnvironmentReflectionIntensity);
        RaymarchMaterial.SetInt("_ReflectionCount", _ReflectionCount);
        RaymarchMaterial.SetTexture("_ReflectionCube", _ReflectionCube);

        //Refactoring Scene Colour
        RaymarchMaterial.SetColor("_GroundColour", _GroundColour);
        RaymarchMaterial.SetFloat("_ColourIntensity", _ColourIntensity);
        RaymarchMaterial.SetColor("_TestColour", _SphereColour);

        //SDF
        RaymarchMaterial.SetFloat("_SphereSmooth", _SphereSmooth);

        RaymarchMaterial.SetBuffer("_SphereBuffer", SphereBuffer);
        RaymarchMaterial.SetInt("_SphereBufferLength", SphereBuffer.count);

        RenderTexture.active = destination;
        RaymarchMaterial.SetTexture("_MainTex", source);
        GL.PushMatrix();
        GL.LoadOrtho();
        RaymarchMaterial.SetPass(0);
        GL.Begin(GL.QUADS);

        //bottomLeft
        GL.MultiTexCoord2(0, 0.0f, 0.0f);
        GL.Vertex3(0.0f, 0.0f, 3.0f);
        //bottomRight
        GL.MultiTexCoord2(0, 1.0f, 0.0f);
        GL.Vertex3(1.0f, 0.0f, 2.0f);
        //topRight
        GL.MultiTexCoord2(0, 1.0f, 1.0f);
        GL.Vertex3(1.0f, 1.0f, 1.0f);
        //topLeft
        GL.MultiTexCoord2(0, 0.0f, 1.0f);
        GL.Vertex3(0.0f, 1.0f, 0.0f);

        GL.End();
        GL.PopMatrix();
    }
コード例 #3
0
        private void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
            if (!_shader)
            {
                _shader = Shader.Find("CloudRendering/RaymarchShader");
            }

            if (!RaymarchMaterial)
            {
                Graphics.Blit(src, dest);
                return;
            }

            RaymarchMaterial.SetMatrix("_CamFrustum", CalculateCameraFrustum(Cam));
            RaymarchMaterial.SetMatrix("_CamToWorldMatrix", Cam.cameraToWorldMatrix);

            RaymarchMaterial.SetVector("_CloudLayerHeight", new Vector4(cloudLayer.bottomHeight, cloudLayer.topHeight, 0, 0));


            RaymarchMaterial.SetFloat("_g_c", globalCloudCoverage);
            RaymarchMaterial.SetFloat("_g_d", globalCloudDensity);

            RaymarchMaterial.SetTexture("_WeatherMap", WeatherMap);
            RaymarchMaterial.SetVector("_WeatherMap_offset", weatherMapST.offset);
            RaymarchMaterial.SetFloat("_WeatherMap_scale", weatherMapST.scale);

            RaymarchMaterial.SetTexture("_BlueNoise", BlueNoise);

            RaymarchMaterial.SetTexture("_ShapeNoise", ShapeNoise);
            RaymarchMaterial.SetFloat("_ShapeNoiseScale", shapeNoiseScale);

            RaymarchMaterial.SetTexture("_DetailNoise", DetailNoise);
            RaymarchMaterial.SetFloat("_DetailNoiseScale", detailNoiseScale);

            // Lighting parameters
            RaymarchMaterial.SetFloat("_cloud_inscatter", lightingParameters.cloudInScatter);
            RaymarchMaterial.SetFloat("_cloud_outscatter", lightingParameters.cloudOutScatter);
            RaymarchMaterial.SetFloat("_cloud_beer", lightingParameters.beer);
            RaymarchMaterial.SetFloat("_cloud_in_vs_outscatter", lightingParameters.inVsOutScatter);
            RaymarchMaterial.SetFloat("_cloud_silver_intensity", lightingParameters.silverLiningIntensity);
            RaymarchMaterial.SetFloat("_cloud_silver_exponent", lightingParameters.silverLiningExponent);
            RaymarchMaterial.SetFloat("_cloud_outscatter_ambient", lightingParameters.ambientOutScatter);
            RaymarchMaterial.SetFloat("_cloud_attuention_clampval", lightingParameters.attuentionClampVal);
            RaymarchMaterial.SetFloat("_cloud_ambient_minimum", lightingParameters.minimumAttenuationAmbient);


            RaymarchMaterial.SetFloat("_step_increase_rate", stepIncreaseRate);
            RaymarchMaterial.SetFloat("_step_size_inside_cloud", stepSizeInsideCloud);
            RaymarchMaterial.SetFloat("_step_size_outside_cloud", stepSizeOutsideCloud);

            RaymarchMaterial.SetInt("_groundTruthMode", groundTruthMode ? 1 : 0);
            RaymarchMaterial.SetFloat("_groundTruthThreshold", groundTruthThreshold);

            RenderTexture.active = dest;
            RaymarchMaterial.SetTexture("_MainTex", src);

            GL.PushMatrix();
            GL.LoadOrtho();
            RaymarchMaterial.SetPass(0);

            GL.Begin(GL.QUADS);

            GL.MultiTexCoord2(0, 0.0f, 0.0f);
            GL.Vertex3(0.0f, 0.0f, 3.0f);

            GL.MultiTexCoord2(0, 1.0f, 0.0f);
            GL.Vertex3(1.0f, 0.0f, 2.0f);

            GL.MultiTexCoord2(0, 1.0f, 1.0f);
            GL.Vertex3(1.0f, 1.0f, 1.0f);

            GL.MultiTexCoord2(0, 0.0f, 1.0f);
            GL.Vertex3(0.0f, 1.0f, 0.0f);

            GL.End();
            GL.PopMatrix();
        }
コード例 #4
0
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!RaymarchMaterial)
        {
            Graphics.Blit(source, destination);
            return;
        }

        _raymatchMat.SetMatrix("_CamFrustum", CamFrustum(Camera));
        _raymatchMat.SetMatrix("_CamToWorld", Camera.cameraToWorldMatrix);

        _raymatchMat.SetFloat("_MaxIterations", maxIterations);
        _raymatchMat.SetFloat("_Accuracy", accuracy);
        _raymatchMat.SetFloat("_Repetation", repetation);

        _raymatchMat.SetFloat("_LightIntensity", directionalLight ? directionalLight.intensity : 0.5f);
        _raymatchMat.SetFloat("_ShadowIntensity", directionalLight ? directionalLight.shadowStrength : 0.5f);
        _raymatchMat.SetFloat("_ShadowPenumbra", shadowPenumbra);
        _raymatchMat.SetFloat("_MaxDistance", maxDistance);
        _raymatchMat.SetFloat("_Box1Round", box1Round);
        _raymatchMat.SetFloat("_BoxSphereSmooth", boxSphereSmooth);
        _raymatchMat.SetFloat("_SphereIntersectionSmooth", sphereIntersectSmooth);

        _raymatchMat.SetVector("_LightDir", directionalLight ? directionalLight.transform.forward : Vector3.one);
        _raymatchMat.SetVector("_Sphere1", sphere1);
        _raymatchMat.SetVector("_Sphere2", sphere2);
        _raymatchMat.SetVector("_Box1", box1);
        _raymatchMat.SetVector("_ShadowDistance", shadowDistance);

        _raymatchMat.SetColor("_MainColor", mainColor);
        _raymatchMat.SetColor("_LightCol", directionalLight ? directionalLight.color : Color.white);

        //AO
        _raymatchMat.SetFloat("_AoStepSize", aoStepSize);
        _raymatchMat.SetFloat("_AoIntensity", aoIntensity);
        _raymatchMat.SetInt("_AoIterations", aoIterations);

        RenderTexture.active = destination;
        _raymatchMat.SetTexture("_MainTex", source);

        _raymatchMat.SetTexture("_NoiseTex", noiseText);

        GL.PushMatrix();
        GL.LoadOrtho();
        RaymarchMaterial.SetPass(0);
        GL.Begin(GL.QUADS);

        //BL
        GL.MultiTexCoord2(0, 0.0f, 0.0f);
        GL.Vertex3(0.0f, 0.0f, 3.0f);
        //BR
        GL.MultiTexCoord2(0, 1.0f, 0.0f);
        GL.Vertex3(1.0f, 0.0f, 2.0f);
        //TR
        GL.MultiTexCoord2(0, 1.0f, 1.0f);
        GL.Vertex3(1.0f, 1.0f, 1.0f);
        //TL
        GL.MultiTexCoord2(0, 0.0f, 1.0f);
        GL.Vertex3(0.0f, 1.0f, 0.0f);

        GL.End();
        GL.PopMatrix();
    }