/// <summary> /// /// </summary> /// <param name="renderer"></param> /// <param name="viewProj"></param> private void SetupPointLight(VolumetricLightRenderer renderer, Matrix4x4 viewProj) { _commandBuffer.Clear(); int pass = 0; if (!IsCameraInPointLightBounds()) { pass = 2; } Mesh mesh = VolumetricLightRenderer.GetPointLightMesh(); float scale = _light.range * 2.0f; Matrix4x4 world = Matrix4x4.TRS(transform.position, _light.transform.rotation, new Vector3(scale, scale, scale)); _material.SetMatrix(_WorldViewProj, viewProj * world); _material.SetMatrix(_WorldView, Camera.current.worldToCameraMatrix * world); _material.SetVector(_LightPos, new Vector4(_light.transform.position.x, _light.transform.position.y, _light.transform.position.z, 1.0f / (_light.range * _light.range))); _material.SetColor(_LightColor, _light.color * _light.intensity * intensity * (1f / SampleCount)); if (_light.cookie != null) { Matrix4x4 view = Matrix4x4.TRS(_light.transform.position, _light.transform.rotation, Vector3.one).inverse; _material.SetMatrix(_MyLightMatrix0, view); } bool forceShadowsOff = false; if ((_light.transform.position - Camera.current.transform.position).magnitude >= QualitySettings.shadowDistance) { forceShadowsOff = true; } if (_light.shadows != LightShadows.None && forceShadowsOff == false) { _material.EnableKeyword("SHADOWS_CUBE"); _commandBuffer.SetGlobalTexture(_ShadowMapTexture, BuiltinRenderTextureType.CurrentActive); _commandBuffer.SetRenderTarget(renderer.volumeLightTexture); _commandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, _commandBuffer, viewProj); } } else { _material.DisableKeyword("SHADOWS_CUBE"); renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } }
private void SetupPointLight(VolumetricLightRenderer renderer, Matrix4x4 viewProj) { this._commandBuffer.Clear(); int num1 = 0; if (!this.IsCameraInPointLightBounds()) { num1 = 2; } this._material.SetPass(num1); Mesh pointLightMesh = VolumetricLightRenderer.GetPointLightMesh(); float num2 = this._light.get_range() * 2f; Matrix4x4 matrix4x4_1 = Matrix4x4.TRS(((Component)this).get_transform().get_position(), ((Component)this._light).get_transform().get_rotation(), new Vector3(num2, num2, num2)); this._material.SetMatrix("_WorldViewProj", Matrix4x4.op_Multiply(viewProj, matrix4x4_1)); this._material.SetMatrix("_WorldView", Matrix4x4.op_Multiply(Camera.get_current().get_worldToCameraMatrix(), matrix4x4_1)); if (this.Noise) { this._material.EnableKeyword("NOISE"); } else { this._material.DisableKeyword("NOISE"); } this._material.SetVector("_LightPos", new Vector4((float)((Component)this._light).get_transform().get_position().x, (float)((Component)this._light).get_transform().get_position().y, (float)((Component)this._light).get_transform().get_position().z, (float)(1.0 / ((double)this._light.get_range() * (double)this._light.get_range())))); this._material.SetColor("_LightColor", Color.op_Multiply(this._light.get_color(), this._light.get_intensity())); if (Object.op_Equality((Object)this._light.get_cookie(), (Object)null)) { this._material.EnableKeyword("POINT"); this._material.DisableKeyword("POINT_COOKIE"); } else { Matrix4x4 matrix4x4_2 = Matrix4x4.TRS(((Component)this._light).get_transform().get_position(), ((Component)this._light).get_transform().get_rotation(), Vector3.get_one()); this._material.SetMatrix("_MyLightMatrix0", ((Matrix4x4) ref matrix4x4_2).get_inverse()); this._material.EnableKeyword("POINT_COOKIE"); this._material.DisableKeyword("POINT"); this._material.SetTexture("_LightTexture0", this._light.get_cookie()); } bool flag = false; Vector3 vector3 = Vector3.op_Subtraction(((Component)this._light).get_transform().get_position(), ((Component)Camera.get_current()).get_transform().get_position()); if ((double)((Vector3) ref vector3).get_magnitude() >= (double)QualitySettings.get_shadowDistance()) { flag = true; } if (this._light.get_shadows() != null && !flag) { this._material.EnableKeyword("SHADOWS_CUBE"); this._commandBuffer.SetGlobalTexture("_ShadowMapTexture", RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)1)); this._commandBuffer.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)renderer.GetVolumeLightBuffer())); this._commandBuffer.DrawMesh(pointLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, this._commandBuffer, viewProj); } else { this._material.DisableKeyword("SHADOWS_CUBE"); renderer.GlobalCommandBuffer.DrawMesh(pointLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } }
/// <summary> /// /// </summary> /// <param name="renderer"></param> /// <param name="viewProj"></param> private void SetupPointLight(VolumetricLightRenderer renderer, Matrix4x4 viewProj) { int pass = 0; if (!IsCameraInPointLightBounds()) { pass = 2; } _material.SetPass(pass); Mesh mesh = VolumetricLightRenderer.GetPointLightMesh(); _commandBuffer.Clear(); float scale = _light.range * 2.0f; Matrix4x4 world = Matrix4x4.TRS(transform.position, _light.transform.rotation, new Vector3(scale, scale, scale)); _material.SetMatrix("_WorldViewProj", viewProj * world); _material.SetMatrix("_WorldView", Camera.current.worldToCameraMatrix * world); _material.SetVector("_VolumetricLight", new Vector4(Density, MieG, _light.range, 0)); if (Noise) { _material.EnableKeyword("NOISE"); } else { _material.DisableKeyword("NOISE"); } _material.SetVector("_LightPos", new Vector4(_light.transform.position.x, _light.transform.position.y, _light.transform.position.z, 1.0f / (_light.range * _light.range))); _material.SetVector("_LightColor", _light.color * _light.intensity); if (_light.cookie == null) { _material.EnableKeyword("POINT"); _material.DisableKeyword("POINT_COOKIE"); } else { Matrix4x4 view = Matrix4x4.TRS(_light.transform.position, _light.transform.rotation, Vector3.one).inverse; _material.SetMatrix("_MyLightMatrix0", view); _material.EnableKeyword("POINT_COOKIE"); _material.DisableKeyword("POINT"); _material.SetTexture("_LightTexture0", _light.cookie); } bool forceShadowsOff = false; if ((_light.transform.position - Camera.current.transform.position).magnitude >= QualitySettings.shadowDistance) { forceShadowsOff = true; } if (_light.shadows != LightShadows.None && forceShadowsOff == false) { _material.EnableKeyword("SHADOWS_CUBE"); _commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); if (renderer.Resolution == VolumetricLightRenderer.VolumtericResolution.Full) { _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer(), BuiltinRenderTextureType.CameraTarget); } else { _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); } _commandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, _commandBuffer, viewProj); } } else { _material.DisableKeyword("SHADOWS_CUBE"); renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } }
/// <summary> /// /// </summary> /// <param name="renderer"></param> /// <param name="viewProj"></param> private void SetupDirectionalLight(VolumetricLightRenderer renderer, Matrix4x4 viewProj) { int pass = 5; _material.SetPass(pass); Mesh mesh = VolumetricLightRenderer.GetPointLightMesh(); _commandBuffer.Clear(); float scale = DirLightFarPlane;// _light.range * 2.0f; Matrix4x4 world = Matrix4x4.TRS(Camera.current.transform.position, Quaternion.identity, new Vector3(scale, scale, scale)); _material.SetMatrix("_WorldViewProj", viewProj * world); _material.SetMatrix("_WorldView", Camera.current.worldToCameraMatrix * world); _material.SetVector("_VolumetricLight", new Vector4(Density, MieG, _light.range, 0)); if (Noise) { _material.EnableKeyword("NOISE"); } else { _material.DisableKeyword("NOISE"); } _material.SetVector("_LightPos", new Vector4(_light.transform.position.x, _light.transform.position.y, _light.transform.position.z, 1.0f / (_light.range * _light.range))); _material.SetVector("_LightColor", _light.color * _light.intensity); if (_light.cookie == null) { _material.EnableKeyword("DIRECTIONAL"); _material.DisableKeyword("DIRECTIONAL_COOKIE"); } else { _material.EnableKeyword("DIRECTIONAL_COOKIE"); _material.DisableKeyword("DIRECTIONAL"); _material.SetTexture("_LightTexture0", _light.cookie); } Texture texture = null; if (_light.shadows != LightShadows.None) { _material.EnableKeyword("SHADOWS_DEPTH"); //_commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); if (renderer.Resolution == VolumetricLightRenderer.VolumtericResolution.Full) { _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer(), BuiltinRenderTextureType.CameraTarget); } else { _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); } //_commandBuffer.Blit(texture, VolumetricLightRenderer.GetVolumeLightBuffer(), _material, pass); _commandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, _commandBuffer, viewProj); } } else { _material.DisableKeyword("SHADOWS_DEPTH"); //globalBuffer.Blit(texture, VolumetricLightRenderer.GetVolumeLightBuffer(), _material, pass); renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } }
private void SetupPointLight(VolumetricLightRenderer renderer, Matrix4x4 viewProj) { int num = 0; if (!this.IsCameraInPointLightBounds()) { num = 2; } this._material.SetPass(num); Mesh pointLightMesh = VolumetricLightRenderer.GetPointLightMesh(); float num2 = this._light.range * 2f; Matrix4x4 matrix4x = Matrix4x4.TRS(base.transform.position, this._light.transform.rotation, new Vector3(num2, num2, num2)); this._material.SetMatrix("_WorldViewProj", viewProj * matrix4x); this._material.SetMatrix("_WorldView", Camera.current.worldToCameraMatrix * matrix4x); if (this.Noise) { this._material.EnableKeyword("NOISE"); } else { this._material.DisableKeyword("NOISE"); } this._material.SetVector("_LightPos", new Vector4(this._light.transform.position.x, this._light.transform.position.y, this._light.transform.position.z, 1f / (this._light.range * this._light.range))); this._material.SetColor("_LightColor", this._light.color * this._light.intensity); if (this._light.cookie == null) { this._material.EnableKeyword("POINT"); this._material.DisableKeyword("POINT_COOKIE"); } else { Matrix4x4 inverse = Matrix4x4.TRS(this._light.transform.position, this._light.transform.rotation, Vector3.one).inverse; this._material.SetMatrix("_MyLightMatrix0", inverse); this._material.EnableKeyword("POINT_COOKIE"); this._material.DisableKeyword("POINT"); this._material.SetTexture("_LightTexture0", this._light.cookie); } bool flag = false; if ((this._light.transform.position - Camera.current.transform.position).magnitude >= QualitySettings.shadowDistance) { flag = true; } if (this._light.shadows != LightShadows.None && !flag) { this._material.EnableKeyword("SHADOWS_CUBE"); this._commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); this._commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); this._commandBuffer.DrawMesh(pointLightMesh, matrix4x, this._material, 0, num); if (this.CustomRenderEvent != null) { this.CustomRenderEvent(renderer, this, this._commandBuffer, viewProj); } } else { this._material.DisableKeyword("SHADOWS_CUBE"); renderer.GlobalCommandBuffer.DrawMesh(pointLightMesh, matrix4x, this._material, 0, num); if (this.CustomRenderEvent != null) { this.CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } }