Exemplo n.º 1
0
 private void OnPreRender()
 {
     if (!this.initialized)
     {
         this.Init();
     }
     Shader.SetGlobalTexture("_UniformNoise", this.uniformNoise);
     RenderTexture active = RenderTexture.active;
     if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.Skylight)
     {
         if (this.OcclusionEnabled)
         {
             Shader.SetGlobalInt("_IsRenderingSkylight", 1);
             Shader.DisableKeyword("SKY_OCCLUSION_OFF");
             this.shadowCam.cullingMask = this.skylightCullingMask;
             Vector3 vector = base.transform.position + Vector3.up * 100f;
             float num = this.shadowCam.orthographicSize * 2f;
             float num2 = num / (float)this.skylightShadowMapResolution;
             vector.x -= vector.x % num2;
             vector.y -= vector.x % num2;
             vector.z -= vector.x % num2;
             if (vector != this.snapPositionSkylight)
             {
                 this.shadowCamGameObject.transform.position = vector;
                 this.shadowCamGameObject.transform.LookAt(base.transform.position, Vector3.forward);
             }
             this.snapPositionSkylight = vector;
             this.shadowCam.depthTextureMode = DepthTextureMode.Depth;
             this.shadowCam.targetTexture = this.skylightDepthTexture;
             this.shadowCam.Render();
             Shader.SetGlobalMatrix("_SkyshadowMatrix", this.shadowCam.worldToCameraMatrix);
             Shader.SetGlobalMatrix("_SkyshadowInverseMatrix", this.shadowCam.worldToCameraMatrix.inverse);
             Shader.SetGlobalMatrix("_SkyshadowProjectionMatrix", this.shadowCam.projectionMatrix);
             Shader.SetGlobalMatrix("_SkyshadowProjectionMatrixInverse", this.shadowCam.projectionMatrix.inverse);
             Shader.SetGlobalTexture("_SkyshadowDepthTexture", this.skylightDepthTexture);
             Shader.SetGlobalFloat("_SkylightOcclusionAmount", this.skylightOcclusionAmount);
             Shader.SetGlobalInt("_IsRenderingSkylight", 0);
         }
         else
         {
             Shader.EnableKeyword("SKY_OCCLUSION_OFF");
         }
     }
     else if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.GlobalIllumination)
     {
         if (this.GIEnabled)
         {
             Shader.DisableKeyword("GI_OFF");
             Shader.SetGlobalInt("_IsRenderingGIBuffers", 1);
             this.shadowCam.cullingMask = this.GICullingMask;
             Vector3 position = base.transform.position + Vector3.Normalize(SkylightingAndGICamera.sunlightVector) * 100f;
             this.shadowCamGameObject.transform.position = position;
             this.shadowCamGameObject.transform.LookAt(base.transform.position, Vector3.up);
             this.shadowCam.renderingPath = RenderingPath.Forward;
             this.shadowCam.depthTextureMode = DepthTextureMode.Depth;
             Graphics.SetRenderTarget(this.giFluxBuffer, this.giDepthBuffer);
             this.shadowCam.SetTargetBuffers(this.giFluxBuffer, this.giDepthBuffer);
             this.shadowCam.Render();
             Shader.SetGlobalMatrix("_GIMatrix", this.shadowCam.worldToCameraMatrix);
             Shader.SetGlobalMatrix("_GIInverseMatrix", this.shadowCam.worldToCameraMatrix.inverse);
             Shader.SetGlobalMatrix("_GIProjectionMatrix", this.shadowCam.projectionMatrix);
             Shader.SetGlobalMatrix("_GIProjectionMatrixInverse", this.shadowCam.projectionMatrix.inverse);
             Shader.SetGlobalTexture("_GIFluxTexture", this.giFluxTexture);
             Shader.SetGlobalTexture("_GIDepthTexture", this.giDepthTexture);
             Shader.SetGlobalFloat("_GIGain", this.globalIlluminationGain);
             Shader.SetGlobalInt("_IsRenderingGIBuffers", 0);
         }
         else
         {
             Shader.EnableKeyword("GI_OFF");
         }
     }
     RenderTexture.active = active;
     if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.Skylight)
     {
         if (this.GIEnabled)
         {
             this.currentRenderMode = SkylightingAndGICamera.RenderMode.GlobalIllumination;
         }
     }
     else if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.GlobalIllumination)
     {
         this.currentRenderMode = SkylightingAndGICamera.RenderMode.Skylight;
     }
 }
Exemplo n.º 2
0
    private void OnPreRender()
    {
        if (!this.initialized)
        {
            this.Init();
        }
        Shader.SetGlobalTexture("_UniformNoise", this.uniformNoise);
        RenderTexture active = RenderTexture.active;

        if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.Skylight)
        {
            if (this.OcclusionEnabled)
            {
                Shader.SetGlobalInt("_IsRenderingSkylight", 1);
                Shader.DisableKeyword("SKY_OCCLUSION_OFF");
                this.shadowCam.cullingMask = this.skylightCullingMask;
                Vector3 vector = base.transform.position + Vector3.up * 100f;
                float   num    = this.shadowCam.orthographicSize * 2f;
                float   num2   = num / (float)this.skylightShadowMapResolution;
                vector.x -= vector.x % num2;
                vector.y -= vector.x % num2;
                vector.z -= vector.x % num2;
                if (vector != this.snapPositionSkylight)
                {
                    this.shadowCamGameObject.transform.position = vector;
                    this.shadowCamGameObject.transform.LookAt(base.transform.position, Vector3.forward);
                }
                this.snapPositionSkylight       = vector;
                this.shadowCam.depthTextureMode = DepthTextureMode.Depth;
                this.shadowCam.targetTexture    = this.skylightDepthTexture;
                this.shadowCam.Render();
                Shader.SetGlobalMatrix("_SkyshadowMatrix", this.shadowCam.worldToCameraMatrix);
                Shader.SetGlobalMatrix("_SkyshadowInverseMatrix", this.shadowCam.worldToCameraMatrix.inverse);
                Shader.SetGlobalMatrix("_SkyshadowProjectionMatrix", this.shadowCam.projectionMatrix);
                Shader.SetGlobalMatrix("_SkyshadowProjectionMatrixInverse", this.shadowCam.projectionMatrix.inverse);
                Shader.SetGlobalTexture("_SkyshadowDepthTexture", this.skylightDepthTexture);
                Shader.SetGlobalFloat("_SkylightOcclusionAmount", this.skylightOcclusionAmount);
                Shader.SetGlobalInt("_IsRenderingSkylight", 0);
            }
            else
            {
                Shader.EnableKeyword("SKY_OCCLUSION_OFF");
            }
        }
        else if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.GlobalIllumination)
        {
            if (this.GIEnabled)
            {
                Shader.DisableKeyword("GI_OFF");
                Shader.SetGlobalInt("_IsRenderingGIBuffers", 1);
                this.shadowCam.cullingMask = this.GICullingMask;
                Vector3 position = base.transform.position + Vector3.Normalize(SkylightingAndGICamera.sunlightVector) * 100f;
                this.shadowCamGameObject.transform.position = position;
                this.shadowCamGameObject.transform.LookAt(base.transform.position, Vector3.up);
                this.shadowCam.renderingPath    = RenderingPath.Forward;
                this.shadowCam.depthTextureMode = DepthTextureMode.Depth;
                Graphics.SetRenderTarget(this.giFluxBuffer, this.giDepthBuffer);
                this.shadowCam.SetTargetBuffers(this.giFluxBuffer, this.giDepthBuffer);
                this.shadowCam.Render();
                Shader.SetGlobalMatrix("_GIMatrix", this.shadowCam.worldToCameraMatrix);
                Shader.SetGlobalMatrix("_GIInverseMatrix", this.shadowCam.worldToCameraMatrix.inverse);
                Shader.SetGlobalMatrix("_GIProjectionMatrix", this.shadowCam.projectionMatrix);
                Shader.SetGlobalMatrix("_GIProjectionMatrixInverse", this.shadowCam.projectionMatrix.inverse);
                Shader.SetGlobalTexture("_GIFluxTexture", this.giFluxTexture);
                Shader.SetGlobalTexture("_GIDepthTexture", this.giDepthTexture);
                Shader.SetGlobalFloat("_GIGain", this.globalIlluminationGain);
                Shader.SetGlobalInt("_IsRenderingGIBuffers", 0);
            }
            else
            {
                Shader.EnableKeyword("GI_OFF");
            }
        }
        RenderTexture.active = active;
        if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.Skylight)
        {
            if (this.GIEnabled)
            {
                this.currentRenderMode = SkylightingAndGICamera.RenderMode.GlobalIllumination;
            }
        }
        else if (this.currentRenderMode == SkylightingAndGICamera.RenderMode.GlobalIllumination)
        {
            this.currentRenderMode = SkylightingAndGICamera.RenderMode.Skylight;
        }
    }