public static void AddLight(DeferredLight light)
 {
     if (DeferredShadingCamera.sceneLights == null)
     {
         DeferredShadingCamera.sceneLights = new List <DeferredLight>();
     }
     DeferredShadingCamera.sceneLights.Add(light);
     Debug.Log("Added a light. Total lights: " + DeferredShadingCamera.sceneLights.Count);
 }
Example #2
0
        public void update()
        {
            // check for debug toggle
            if (Input.isKeyPressed(Keys.F))
            {
                var renderer = entity.scene.getRenderer <DeferredLightingRenderer>();
                renderer.enableDebugBufferRender = !renderer.enableDebugBufferRender;
            }

            // check for light changes
            var lightIndex = -1;

            if (Input.isKeyPressed(Keys.D1))
            {
                lightIndex = 0;
            }
            if (Input.isKeyPressed(Keys.D2))
            {
                lightIndex = 1;
            }
            if (Input.isKeyPressed(Keys.D3))
            {
                lightIndex = 2;
            }
            if (Input.isKeyPressed(Keys.D4))
            {
                lightIndex = 3;
            }
            if (Input.isKeyPressed(Keys.D5))
            {
                lightIndex = 4;
            }
            if (Input.isKeyPressed(Keys.D6))
            {
                lightIndex = 5;
            }

            if (lightIndex > -1)
            {
                var lights = entity.scene.findComponentsOfType <DeferredLight>();
                if (lights.Count > lightIndex)
                {
                    _currentLight = lights[lightIndex];
                    updateInstructions();
                }
                else
                {
                    Debug.log("no light at index: {0}", lightIndex);
                }
            }

            checkInput();
        }
        /// <summary>
        /// Adiciona uma luz ao interpolador
        /// As cores das luzes adicionadas serao gerenciadas por este component
        /// </summary>
        /// <param name="dl">luz</param>
        /// <param name="c1">Cor original</param>
        /// <param name="c2">Cor destino</param>
        /// <param name="duration">Duracao da interpolacao em SEGUNDOS</param>
        public void AddLight(DeferredLight dl, Color c1, Color c2, double duration)
        {
            lightInterpolation l = new lightInterpolation();

            l.dl       = dl;
            l.duration = duration;
            l.v1       = c1.ToVector3();
            l.v2       = c2.ToVector3();
            lights.Add(l);
            l.vi = new Vec3Interpolator();
            l.vi.Start(l.v1, l.v2, duration, true);
        }
Example #4
0
 public override void onAddedToEntity()
 {
     _dirLight     = entity.scene.findComponentOfType <DirLight>();
     _currentLight = _dirLight;
 }
 public static void RemoveLight(DeferredLight light)
 {
     DeferredShadingCamera.sceneLights.Remove(light);
     Debug.Log("Removed a light. Total lights: " + DeferredShadingCamera.sceneLights.Count);
 }
 private void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     RenderTexture.active = this.lastActive;
     if (this.displayMode == DeferredShadingCamera.DebugDisplay.gbuffer0)
     {
         Graphics.Blit(this.gbufferTextures[0], destination);
     }
     else if (this.displayMode == DeferredShadingCamera.DebugDisplay.gbuffer1)
     {
         Graphics.Blit(this.gbufferTextures[1], destination);
     }
     else if (this.displayMode == DeferredShadingCamera.DebugDisplay.gbuffer2)
     {
         Graphics.Blit(this.gbufferTextures[2], destination);
     }
     else if (this.displayMode == DeferredShadingCamera.DebugDisplay.composite)
     {
         RenderTexture renderTexture = null;
         if (this.renderSSAO)
         {
             RenderTexture temporary = RenderTexture.GetTemporary(this.depthTexture.width / 2, this.depthTexture.height / 2, 0, RenderTextureFormat.RFloat);
             temporary.filterMode = FilterMode.Point;
             Graphics.Blit(this.depthTexture, temporary, this.compositeMaterial, 3);
             Shader.SetGlobalTexture("gdepthhalf", temporary);
             renderTexture = RenderTexture.GetTemporary(this.gbufferTextures[0].width, this.gbufferTextures[0].height, 0, RenderTextureFormat.R8);
             RenderTexture temporary2 = RenderTexture.GetTemporary(this.gbufferTextures[0].width, this.gbufferTextures[0].height, 0, RenderTextureFormat.R8);
             Graphics.Blit(source, renderTexture, this.ssaoMaterial, 0);
             this.postBlurMaterial.SetFloat("BlurDepthTollerance", 0.1f);
             this.postBlurMaterial.SetVector("BlurXY", new Vector2(1f, 0f));
             Graphics.Blit(renderTexture, temporary2, this.postBlurMaterial, 0);
             this.postBlurMaterial.SetVector("BlurXY", new Vector2(0f, 1f));
             Graphics.Blit(temporary2, renderTexture, this.postBlurMaterial, 0);
             RenderTexture.ReleaseTemporary(temporary2);
             this.compositeMaterial.SetTexture("ssaotex", renderTexture);
             RenderTexture.ReleaseTemporary(temporary);
         }
         RenderTexture renderTexture2 = null;
         if (this.renderSSSSS)
         {
             renderTexture2 = RenderTexture.GetTemporary(this.gbufferTextures[0].width, this.gbufferTextures[0].height, 0, RenderTextureFormat.ARGBHalf);
             this.MultiBlit(this.gbufferTextures[0], new RenderTexture[]
             {
                 destination,
                 renderTexture2
             }, this.compositeMaterial, 0);
         }
         else
         {
             Graphics.Blit(this.gbufferTextures[0], destination, this.compositeMaterial, 0);
         }
         if (renderTexture != null)
         {
             RenderTexture.ReleaseTemporary(renderTexture);
         }
         if (this.renderPointLights)
         {
             int num  = 0;
             int num2 = DeferredShadingCamera.sceneLights.Count / 20;
             for (int i = 0; i <= num2; i++)
             {
                 for (int j = 1; j <= 20; j++)
                 {
                     this.compositeMaterial.SetColor("_LightColor" + j.ToString(), Color.black);
                     this.compositeMaterial.SetVector("_LightPosition" + j.ToString(), new Vector4(0f, 0f, 0f, 0f));
                     this.compositeMaterial.SetInt("_LightType" + j.ToString(), 2);
                     this.compositeMaterial.SetFloat("_LightFakeReflection" + j.ToString(), 0f);
                     this.compositeMaterial.SetVector("_LightSpotDirection" + j.ToString(), Vector4.zero);
                 }
                 for (int k = 1; k <= Mathf.Min(DeferredShadingCamera.sceneLights.Count, 20) - i * 20; k++)
                 {
                     DeferredLight deferredLight = DeferredShadingCamera.sceneLights[k - 1 + i * 20];
                     if (deferredLight == null)
                     {
                         DeferredShadingCamera.sceneLights.Clear();
                         break;
                     }
                     this.compositeMaterial.SetColor("_LightColor" + k.ToString(), new Color(deferredLight.color.r * deferredLight.color.r, deferredLight.color.g * deferredLight.color.g, deferredLight.color.b * deferredLight.color.b, deferredLight.intensity));
                     this.compositeMaterial.SetVector("_LightPosition" + k.ToString(), new Vector4(deferredLight.position.x, deferredLight.position.y, deferredLight.position.z, deferredLight.range));
                     this.compositeMaterial.SetInt("_LightType" + k.ToString(), (deferredLight.type != LightType.Point) ? ((deferredLight.type != LightType.Spot) ? 2 : 1) : 0);
                     this.compositeMaterial.SetFloat("_LightFakeReflection" + k.ToString(), deferredLight.fakerefl);
                     this.compositeMaterial.SetVector("_LightSpotDirection" + k.ToString(), new Vector4(deferredLight.spotDirection.x, deferredLight.spotDirection.y, deferredLight.spotDirection.z, deferredLight.spotAngle));
                     this.compositeMaterial.SetTexture("_LightProjectTexture" + k.ToString(), deferredLight.spotlightProjectTexture);
                     num++;
                 }
                 if (this.renderSSSSS)
                 {
                     this.MultiBlit(this.gbufferTextures[0], new RenderTexture[]
                     {
                         destination,
                         renderTexture2
                     }, this.compositeMaterial, 1);
                 }
                 else
                 {
                     Graphics.Blit(this.gbufferTextures[0], destination, this.compositeMaterial, 1);
                 }
             }
         }
         if (this.renderSSSSS)
         {
             RenderTexture temporary3 = RenderTexture.GetTemporary(this.gbufferTextures[0].width, this.gbufferTextures[0].height, 0, RenderTextureFormat.ARGBHalf);
             this.compositeMaterial.SetVector("sssssKernel", new Vector3(1f, 0f, 1f));
             Graphics.Blit(renderTexture2, temporary3, this.compositeMaterial, 4);
             this.compositeMaterial.SetVector("sssssKernel", new Vector3(0f, 1f, 1f));
             Graphics.Blit(temporary3, renderTexture2, this.compositeMaterial, 4);
             this.compositeMaterial.SetVector("sssssKernel", new Vector3(3f, 0f, 0.5f));
             Graphics.Blit(renderTexture2, temporary3, this.compositeMaterial, 4);
             this.compositeMaterial.SetVector("sssssKernel", new Vector3(0f, 3f, 0.5f));
             Graphics.Blit(temporary3, renderTexture2, this.compositeMaterial, 4);
             RenderTexture.ReleaseTemporary(temporary3);
             Graphics.Blit(renderTexture2, destination, this.compositeMaterial, 5);
             RenderTexture.ReleaseTemporary(renderTexture2);
         }
         RenderTexture temporary4 = RenderTexture.GetTemporary(this.gbufferTextures[0].width, this.gbufferTextures[0].height, 0, this.gbufferTextures[0].format);
         Graphics.Blit(destination, temporary4);
         Shader.SetGlobalTexture("composite", temporary4);
         this.transparentCamera.CopyFrom(this.c);
         this.transparentCamera.enabled     = false;
         this.transparentCamera.cullingMask = this.waterRenderingMask;
         this.transparentCamera.clearFlags  = CameraClearFlags.Nothing;
         this.transparentCamera.SetTargetBuffers(destination.colorBuffer, destination.depthBuffer);
         this.transparentCamera.Render();
         this.transparentCamera.cullingMask = this.particleRenderingMask;
         this.transparentCamera.SetTargetBuffers(destination.colorBuffer, destination.depthBuffer);
         this.transparentCamera.Render();
         RenderTexture.ReleaseTemporary(temporary4);
     }
 }
Example #7
0
 public override void OnAddedToEntity()
 {
     _dirLight     = Entity.Scene.FindComponentOfType <DirLight>();
     _currentLight = _dirLight;
 }