private Camera CreateBakingCamera() { GameObject tempCam = new GameObject(); tempCam.name = "Reflection Probe Cam"; Camera cam = tempCam.AddComponent <Camera>(); cam.enabled = false; cam.gameObject.SetActive(true); cam.cameraType = CameraType.Reflection; cam.fieldOfView = 90; cam.farClipPlane = myProbe.farClipPlane; cam.nearClipPlane = myProbe.nearClipPlane; cam.cullingMask = myProbe.cullingMask; cam.clearFlags = (CameraClearFlags)myProbe.clearFlags; cam.backgroundColor = myProbe.backgroundColor; cam.allowHDR = myProbe.hdr; cam.targetTexture = cubemap; #if ENVIRO_HD && !ENVIRO_HDRP if (EnviroSkyMgr.instance != null && EnviroSkyMgr.instance.currentEnviroSkyVersion == EnviroSkyMgr.EnviroSkyVersion.HD) { EnviroSkyRendering eSky = tempCam.AddComponent <EnviroSkyRendering>(); eSky.isAddionalCamera = true; eSky.useGlobalRenderingSettings = false; eSky.customRenderingSettings.useVolumeClouds = true; eSky.customRenderingSettings.useVolumeLighting = false; eSky.customRenderingSettings.useDistanceBlur = false; eSky.customRenderingSettings.useFog = true; } #endif tempCam.hideFlags = HideFlags.HideAndDontSave; return(cam); }
private void InitImageEffects() { this.skyRender = (EnviroSkyRendering)((Component)this.myCam).get_gameObject().GetComponent <EnviroSkyRendering>(); if (Object.op_Equality((Object)this.skyRender, (Object)null)) { this.skyRender = (EnviroSkyRendering)((Component)this.myCam).get_gameObject().AddComponent <EnviroSkyRendering>(); } this.skyRender.isAddionalCamera = true; EnviroLightShafts[] components = (EnviroLightShafts[])((Component)this.myCam).get_gameObject().GetComponents <EnviroLightShafts>(); if (components.Length > 0) { this.lightShaftsScriptSun = components[0]; } if (Object.op_Inequality((Object)this.lightShaftsScriptSun, (Object)null)) { Object.DestroyImmediate((Object)this.lightShaftsScriptSun.sunShaftsMaterial); Object.DestroyImmediate((Object)this.lightShaftsScriptSun.simpleClearMaterial); this.lightShaftsScriptSun.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); this.lightShaftsScriptSun.sunShaftsShader = this.lightShaftsScriptSun.sunShaftsMaterial.get_shader(); this.lightShaftsScriptSun.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); this.lightShaftsScriptSun.simpleClearShader = this.lightShaftsScriptSun.simpleClearMaterial.get_shader(); } else { this.lightShaftsScriptSun = (EnviroLightShafts)((Component)this.myCam).get_gameObject().AddComponent <EnviroLightShafts>(); this.lightShaftsScriptSun.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); this.lightShaftsScriptSun.sunShaftsShader = this.lightShaftsScriptSun.sunShaftsMaterial.get_shader(); this.lightShaftsScriptSun.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); this.lightShaftsScriptSun.simpleClearShader = this.lightShaftsScriptSun.simpleClearMaterial.get_shader(); } if (components.Length > 1) { this.lightShaftsScriptMoon = components[1]; } if (Object.op_Inequality((Object)this.lightShaftsScriptMoon, (Object)null)) { Object.DestroyImmediate((Object)this.lightShaftsScriptMoon.sunShaftsMaterial); Object.DestroyImmediate((Object)this.lightShaftsScriptMoon.simpleClearMaterial); this.lightShaftsScriptMoon.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); this.lightShaftsScriptMoon.sunShaftsShader = this.lightShaftsScriptMoon.sunShaftsMaterial.get_shader(); this.lightShaftsScriptMoon.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); this.lightShaftsScriptMoon.simpleClearShader = this.lightShaftsScriptMoon.simpleClearMaterial.get_shader(); } else { this.lightShaftsScriptMoon = (EnviroLightShafts)((Component)this.myCam).get_gameObject().AddComponent <EnviroLightShafts>(); this.lightShaftsScriptMoon.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); this.lightShaftsScriptMoon.sunShaftsShader = this.lightShaftsScriptMoon.sunShaftsMaterial.get_shader(); this.lightShaftsScriptMoon.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); this.lightShaftsScriptMoon.simpleClearShader = this.lightShaftsScriptMoon.simpleClearMaterial.get_shader(); } }
/// <summary> /// /// </summary> /// <param name="renderer"></param> /// <param name="viewProj"></param> private void VolumetricLightRenderer_PreRenderEvent(EnviroSkyRendering renderer, Matrix4x4 viewProj, Matrix4x4 viewProjSP) { if (EnviroSky.instance == null) { return; } // light was destroyed without deregistring, deregister now if (_light == null || _light.gameObject == null) { EnviroSkyRendering.PreRenderEvent -= VolumetricLightRenderer_PreRenderEvent; return; } if (!_light.gameObject.activeInHierarchy || _light.enabled == false) { return; } if (_material == null) { _material = new Material(volumeLightShader); } _material.SetVector("_CameraForward", Camera.current.transform.forward); _material.SetInt("_SampleCount", SampleCount); _material.SetVector("_NoiseVelocity", new Vector4(EnviroSky.instance.volumeLightSettings.noiseVelocity.x, EnviroSky.instance.volumeLightSettings.noiseVelocity.y) * EnviroSky.instance.volumeLightSettings.noiseScale); _material.SetVector("_NoiseData", new Vector4(EnviroSky.instance.volumeLightSettings.noiseScale, EnviroSky.instance.volumeLightSettings.noiseIntensity, EnviroSky.instance.volumeLightSettings.noiseIntensityOffset)); _material.SetVector("_MieG", new Vector4(1 - (Anistropy * Anistropy), 1 + (Anistropy * Anistropy), 2 * Anistropy, 1.0f / (4.0f * Mathf.PI))); float scatter = ScatteringCoef; if (scaleWithTime) { scatter = ScatteringCoef * (1 - EnviroSky.instance.GameTime.solarTime); } _material.SetVector("_VolumetricLight", new Vector4(scatter, ExtinctionCoef, _light.range, 1.0f));// - SkyboxExtinctionCoef)); _material.SetTexture("_CameraDepthTexture", renderer.GetVolumeLightDepthBuffer()); _material.SetFloat("_ZTest", (int)UnityEngine.Rendering.CompareFunction.Always); if (_light.type == LightType.Point) { SetupPointLight(renderer, viewProj, viewProjSP); } else if (_light.type == LightType.Spot) { SetupSpotLight(renderer, viewProj, viewProjSP); } }
private void VolumetricLightRenderer_PreRenderEvent( EnviroSkyRendering renderer, Matrix4x4 viewProj, Matrix4x4 viewProjSP) { if (Object.op_Equality((Object)EnviroSky.instance, (Object)null)) { return; } if (Object.op_Equality((Object)this._light, (Object)null) || Object.op_Equality((Object)((Component)this._light).get_gameObject(), (Object)null)) { EnviroSkyRendering.PreRenderEvent -= new Action <EnviroSkyRendering, Matrix4x4, Matrix4x4>(this.VolumetricLightRenderer_PreRenderEvent); } if (!((Component)this._light).get_gameObject().get_activeInHierarchy() || !((Behaviour)this._light).get_enabled()) { return; } this._material.SetVector("_CameraForward", Vector4.op_Implicit(((Component)Camera.get_current()).get_transform().get_forward())); this._material.SetInt("_SampleCount", this.SampleCount); this._material.SetVector("_NoiseVelocity", Vector4.op_Multiply(new Vector4((float)EnviroSky.instance.volumeLightSettings.noiseVelocity.x, (float)EnviroSky.instance.volumeLightSettings.noiseVelocity.y), EnviroSky.instance.volumeLightSettings.noiseScale)); this._material.SetVector("_NoiseData", new Vector4(EnviroSky.instance.volumeLightSettings.noiseScale, EnviroSky.instance.volumeLightSettings.noiseIntensity, EnviroSky.instance.volumeLightSettings.noiseIntensityOffset)); this._material.SetVector("_MieG", new Vector4((float)(1.0 - (double)this.Anistropy * (double)this.Anistropy), (float)(1.0 + (double)this.Anistropy * (double)this.Anistropy), 2f * this.Anistropy, 0.07957747f)); float num = this.ScatteringCoef; if (this.scaleWithTime) { num = this.ScatteringCoef * (1f - EnviroSky.instance.GameTime.solarTime); } this._material.SetVector("_VolumetricLight", new Vector4(num, this.ExtinctionCoef, this._light.get_range(), 1f)); this._material.SetTexture("_CameraDepthTexture", (Texture)renderer.GetVolumeLightDepthBuffer()); this._material.SetFloat("_ZTest", 8f); if (this._light.get_type() == 2) { this.SetupPointLight(renderer, viewProj, viewProjSP); } else { if (this._light.get_type() != null) { return; } this.SetupSpotLight(renderer, viewProj, viewProjSP); } }
// Creation private void CreateRenderCamera() { if (renderCamObj == null) { renderCamObj = new GameObject(); renderCamObj.name = "Reflection Probe Cam"; renderCamObj.hideFlags = HideFlags.HideAndDontSave; renderCam = renderCamObj.AddComponent <Camera>(); renderCam.gameObject.SetActive(true); renderCam.cameraType = CameraType.Reflection; renderCam.fieldOfView = 90; renderCam.farClipPlane = myProbe.farClipPlane; renderCam.nearClipPlane = myProbe.nearClipPlane; renderCam.clearFlags = (CameraClearFlags)myProbe.clearFlags; renderCam.backgroundColor = myProbe.backgroundColor; renderCam.allowHDR = myProbe.hdr; renderCam.targetTexture = cubemap; renderCam.enabled = false; #if VEGETATION_STUDIO_PRO // VegetationStudioManager.Instance.AddCamera(renderCam); #endif #if ENVIRO_HD && !ENVIRO_HDRP if (EnviroSkyMgr.instance != null && EnviroSkyMgr.instance.currentEnviroSkyVersion == EnviroSkyMgr.EnviroSkyVersion.HD) { eSky = renderCamObj.AddComponent <EnviroSkyRendering>(); eSky.isAddionalCamera = true; eSky.useGlobalRenderingSettings = false; eSky.customRenderingSettings.useVolumeClouds = EnviroSkyMgr.instance.useVolumeClouds; eSky.customRenderingSettings.useVolumeLighting = false; eSky.customRenderingSettings.useDistanceBlur = false; eSky.customRenderingSettings.useFog = EnviroSkyMgr.instance.ReflectionSettings.globalReflectionUseFog; if (customCloudsQuality != null) { eSky.customRenderingSettings.customCloudsQuality = customCloudsQuality; } } #endif } }
private void InitImageEffects() { if (addEnviroSkyRendering) { skyRender = myCam.gameObject.GetComponent <EnviroSkyRendering>(); if (skyRender == null) { skyRender = myCam.gameObject.AddComponent <EnviroSkyRendering>(); } skyRender.isAddionalCamera = true; #if UNITY_EDITOR string[] assets = UnityEditor.AssetDatabase.FindAssets("enviro_spot_cookie", null); for (int idx = 0; idx < assets.Length; idx++) { string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]); if (path.Length > 0) { skyRender.DefaultSpotCookie = UnityEditor.AssetDatabase.LoadAssetAtPath <Texture>(path); } } #endif } if (addEnviroSkyPostProcessing) { enviroPostProcessing = myCam.gameObject.GetComponent <EnviroPostProcessing>(); if (enviroPostProcessing == null) { enviroPostProcessing = myCam.gameObject.AddComponent <EnviroPostProcessing>(); } } }
private void InitImageEffects() { skyRender = myCam.gameObject.GetComponent <EnviroSkyRendering>(); if (skyRender == null) { skyRender = myCam.gameObject.AddComponent <EnviroSkyRendering>(); } skyRender.isAddionalCamera = true; #if UNITY_EDITOR string[] assets = UnityEditor.AssetDatabase.FindAssets("enviro_spot_cookie", null); for (int idx = 0; idx < assets.Length; idx++) { string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]); if (path.Length > 0) { skyRender.DefaultSpotCookie = UnityEditor.AssetDatabase.LoadAssetAtPath <Texture>(path); } } #endif EnviroLightShafts[] shaftScripts = myCam.gameObject.GetComponents <EnviroLightShafts>(); if (shaftScripts.Length > 0) { lightShaftsScriptSun = shaftScripts[0]; } if (lightShaftsScriptSun != null) { DestroyImmediate(lightShaftsScriptSun.sunShaftsMaterial); DestroyImmediate(lightShaftsScriptSun.simpleClearMaterial); lightShaftsScriptSun.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); lightShaftsScriptSun.sunShaftsShader = lightShaftsScriptSun.sunShaftsMaterial.shader; lightShaftsScriptSun.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); lightShaftsScriptSun.simpleClearShader = lightShaftsScriptSun.simpleClearMaterial.shader; } else { lightShaftsScriptSun = myCam.gameObject.AddComponent <EnviroLightShafts>(); lightShaftsScriptSun.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); lightShaftsScriptSun.sunShaftsShader = lightShaftsScriptSun.sunShaftsMaterial.shader; lightShaftsScriptSun.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); lightShaftsScriptSun.simpleClearShader = lightShaftsScriptSun.simpleClearMaterial.shader; } if (shaftScripts.Length > 1) { lightShaftsScriptMoon = shaftScripts[1]; } if (lightShaftsScriptMoon != null) { DestroyImmediate(lightShaftsScriptMoon.sunShaftsMaterial); DestroyImmediate(lightShaftsScriptMoon.simpleClearMaterial); lightShaftsScriptMoon.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); lightShaftsScriptMoon.sunShaftsShader = lightShaftsScriptMoon.sunShaftsMaterial.shader; lightShaftsScriptMoon.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); lightShaftsScriptMoon.simpleClearShader = lightShaftsScriptMoon.simpleClearMaterial.shader; } else { lightShaftsScriptMoon = myCam.gameObject.AddComponent <EnviroLightShafts>(); lightShaftsScriptMoon.sunShaftsMaterial = new Material(Shader.Find("Enviro/Effects/LightShafts")); lightShaftsScriptMoon.sunShaftsShader = lightShaftsScriptMoon.sunShaftsMaterial.shader; lightShaftsScriptMoon.simpleClearMaterial = new Material(Shader.Find("Enviro/Effects/ClearLightShafts")); lightShaftsScriptMoon.simpleClearShader = lightShaftsScriptMoon.simpleClearMaterial.shader; } }
/// <summary> /// /// </summary> /// <param name="renderer"></param> /// <param name="viewProj"></param> private void SetupSpotLight(EnviroSkyRendering renderer, Matrix4x4 viewProj, Matrix4x4 viewProjSP) { _commandBuffer.Clear(); int pass = 1; if (!IsCameraInSpotLightBounds()) { pass = 3; } Mesh mesh = EnviroSkyRendering.GetSpotLightMesh(); float scale = _light.range; float angleScale = Mathf.Tan((_light.spotAngle + 1) * 0.5f * Mathf.Deg2Rad) * _light.range; Matrix4x4 world = Matrix4x4.TRS(transform.position, transform.rotation, new Vector3(angleScale, angleScale, scale)); Matrix4x4 view = Matrix4x4.TRS(_light.transform.position, _light.transform.rotation, Vector3.one).inverse; Matrix4x4 clip = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.0f), Quaternion.identity, new Vector3(-0.5f, -0.5f, 1.0f)); Matrix4x4 proj = Matrix4x4.Perspective(_light.spotAngle, 1, 0, 1); _material.SetMatrix("_MyLightMatrix0", clip * proj * view); _material.SetMatrix("_WorldViewProj", viewProj * world); _material.SetMatrix("_WorldViewProj_SP", viewProjSP * 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.SetVector("_LightColor", _light.color * _light.intensity); Vector3 apex = transform.position; Vector3 axis = transform.forward; // plane equation ax + by + cz + d = 0; precompute d here to lighten the shader Vector3 center = apex + axis * _light.range; float d = -Vector3.Dot(center, axis); // update material _material.SetFloat("_PlaneD", d); _material.SetFloat("_CosAngle", Mathf.Cos((_light.spotAngle + 1) * 0.5f * Mathf.Deg2Rad)); _material.SetVector("_ConeApex", new Vector4(apex.x, apex.y, apex.z)); _material.SetVector("_ConeAxis", new Vector4(axis.x, axis.y, axis.z)); _material.EnableKeyword("SPOT"); if (Noise) { _material.EnableKeyword("NOISE"); } else { _material.DisableKeyword("NOISE"); } if (_light.cookie == null) { _material.SetTexture("_LightTexture0", EnviroSkyRendering.GetDefaultSpotCookie()); } else { _material.SetTexture("_LightTexture0", _light.cookie); } bool forceShadowsOff = false; if ((_light.transform.position - EnviroSky.instance.PlayerCamera.transform.position).magnitude >= QualitySettings.shadowDistance) { forceShadowsOff = true; } if (_light.shadows != LightShadows.None && forceShadowsOff == false) { if (EnviroSky.instance.PlayerCamera.stereoEnabled) { if (EnviroSky.instance.singlePassVR) { clip = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, new Vector3(0.5f, 0.5f, 0.5f)); if (_reversedZ) { proj = Matrix4x4.Perspective(_light.spotAngle, 1, _light.range, _light.shadowNearPlane); } else { proj = Matrix4x4.Perspective(_light.spotAngle, 1, _light.shadowNearPlane, _light.range); } Matrix4x4 m = clip * proj; m [0, 2] *= -1; m [1, 2] *= -1; m [2, 2] *= -1; m [3, 2] *= -1; //view = _light.transform.worldToLocalMatrix; _material.SetMatrix("_MyWorld2Shadow", m * view); _material.SetMatrix("_WorldView", m * view); _material.EnableKeyword("SHADOWS_DEPTH"); _commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); _commandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, _commandBuffer, viewProj); } } else { _material.DisableKeyword("SHADOWS_DEPTH"); renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } } else { clip = Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, new Vector3(0.5f, 0.5f, 0.5f)); if (_reversedZ) { proj = Matrix4x4.Perspective(_light.spotAngle, 1, _light.range, _light.shadowNearPlane); } else { proj = Matrix4x4.Perspective(_light.spotAngle, 1, _light.shadowNearPlane, _light.range); } Matrix4x4 m = clip * proj; m [0, 2] *= -1; m [1, 2] *= -1; m [2, 2] *= -1; m [3, 2] *= -1; //view = _light.transform.worldToLocalMatrix; _material.SetMatrix("_MyWorld2Shadow", m * view); _material.SetMatrix("_WorldView", m * view); _material.EnableKeyword("SHADOWS_DEPTH"); _commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); _commandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, _commandBuffer, viewProj); } } } else { _material.DisableKeyword("SHADOWS_DEPTH"); if (EnviroSky.instance.PlayerCamera.actualRenderingPath == RenderingPath.Forward) { //renderer.GlobalCommandBufferForward.Clear (); renderer.GlobalCommandBufferForward.SetRenderTarget(renderer.GetVolumeLightBuffer()); renderer.GlobalCommandBufferForward.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBufferForward, viewProj); } } else { 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 SetupPointLight(EnviroSkyRendering renderer, Matrix4x4 viewProj, Matrix4x4 viewProjSP) { _commandBuffer.Clear(); int pass = 0; if (!IsCameraInPointLightBounds()) { pass = 2; } _material.SetPass(pass); Mesh mesh = EnviroSkyRendering.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("_WorldViewProj_SP", viewProjSP * world); 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.SetColor("_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 - EnviroSky.instance.PlayerCamera.transform.position).magnitude >= QualitySettings.shadowDistance) { forceShadowsOff = true; } if (_light.shadows != LightShadows.None && forceShadowsOff == false) { if (EnviroSky.instance.PlayerCamera.stereoEnabled) { if (EnviroSky.instance.singlePassVR) { _material.EnableKeyword("SHADOWS_CUBE"); _commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); _commandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, _commandBuffer, viewProj); } } else { /* _commandBuffer.SetShadowSamplingMode (BuiltinRenderTextureType.CurrentActive, ShadowSamplingMode.CompareDepths); * _commandBuffer.Blit (BuiltinRenderTextureType.CurrentActive,new RenderTargetIdentifier(temp)); * renderer._afterLightPass.Clear (); * renderer._afterLightPass.SetGlobalTexture ("_ShadowMapTexture", temp); * _material.SetTexture ("_ShadowMapTexture", temp); * renderer._afterLightPass.SetRenderTarget (renderer.GetVolumeLightBuffer ()); * renderer._afterLightPass.DrawMesh (mesh, world, _material, 0, pass); * * if (CustomRenderEvent != null) * CustomRenderEvent (renderer, this, _commandBuffer, viewProj);*/ _material.DisableKeyword("SHADOWS_CUBE"); renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } } else { _material.EnableKeyword("SHADOWS_CUBE"); _commandBuffer.SetGlobalTexture("_ShadowMapTexture", BuiltinRenderTextureType.CurrentActive); _commandBuffer.SetRenderTarget(renderer.GetVolumeLightBuffer()); _commandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, _commandBuffer, viewProj); } } } else { _material.DisableKeyword("SHADOWS_DEPTH"); if (EnviroSky.instance.PlayerCamera.actualRenderingPath == RenderingPath.Forward) { //renderer.GlobalCommandBufferForward.Clear (); renderer.GlobalCommandBufferForward.SetRenderTarget(renderer.GetVolumeLightBuffer()); renderer.GlobalCommandBufferForward.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBufferForward, viewProj); } } else { renderer.GlobalCommandBuffer.DrawMesh(mesh, world, _material, 0, pass); if (CustomRenderEvent != null) { CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } } }
private void SetupSpotLight( EnviroSkyRendering renderer, Matrix4x4 viewProj, Matrix4x4 viewProjSP) { this._commandBuffer.Clear(); int num1 = 1; if (!this.IsCameraInSpotLightBounds()) { num1 = 3; } Mesh spotLightMesh = EnviroSkyRendering.GetSpotLightMesh(); float range = this._light.get_range(); float num2 = Mathf.Tan((float)(((double)this._light.get_spotAngle() + 1.0) * 0.5 * (Math.PI / 180.0))) * this._light.get_range(); Matrix4x4 matrix4x4_1 = Matrix4x4.TRS(((Component)this).get_transform().get_position(), ((Component)this).get_transform().get_rotation(), new Vector3(num2, num2, range)); Matrix4x4 matrix4x4_2 = Matrix4x4.TRS(((Component)this._light).get_transform().get_position(), ((Component)this._light).get_transform().get_rotation(), Vector3.get_one()); Matrix4x4 inverse = ((Matrix4x4) ref matrix4x4_2).get_inverse(); this._material.SetMatrix("_MyLightMatrix0", Matrix4x4.op_Multiply(Matrix4x4.op_Multiply(Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.0f), Quaternion.get_identity(), new Vector3(-0.5f, -0.5f, 1f)), Matrix4x4.Perspective(this._light.get_spotAngle(), 1f, 0.0f, 1f)), inverse)); this._material.SetMatrix("_WorldViewProj", Matrix4x4.op_Multiply(viewProj, matrix4x4_1)); this._material.SetMatrix("_WorldViewProj_SP", Matrix4x4.op_Multiply(viewProjSP, matrix4x4_1)); 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.SetVector("_LightColor", Color.op_Implicit(Color.op_Multiply(this._light.get_color(), this._light.get_intensity()))); Vector3 position = ((Component)this).get_transform().get_position(); Vector3 forward = ((Component)this).get_transform().get_forward(); this._material.SetFloat("_PlaneD", -Vector3.Dot(Vector3.op_Addition(position, Vector3.op_Multiply(forward, this._light.get_range())), forward)); this._material.SetFloat("_CosAngle", Mathf.Cos((float)(((double)this._light.get_spotAngle() + 1.0) * 0.5 * (Math.PI / 180.0)))); this._material.SetVector("_ConeApex", new Vector4((float)position.x, (float)position.y, (float)position.z)); this._material.SetVector("_ConeAxis", new Vector4((float)forward.x, (float)forward.y, (float)forward.z)); this._material.EnableKeyword("SPOT"); if (this.Noise) { this._material.EnableKeyword("NOISE"); } else { this._material.DisableKeyword("NOISE"); } if (Object.op_Equality((Object)this._light.get_cookie(), (Object)null)) { this._material.SetTexture("_LightTexture0", EnviroSkyRendering.GetDefaultSpotCookie()); } else { this._material.SetTexture("_LightTexture0", this._light.get_cookie()); } bool flag = false; Vector3 vector3 = Vector3.op_Subtraction(((Component)this._light).get_transform().get_position(), ((Component)EnviroSky.instance.PlayerCamera).get_transform().get_position()); if ((double)((Vector3) ref vector3).get_magnitude() >= (double)QualitySettings.get_shadowDistance()) { flag = true; } if (this._light.get_shadows() != null && !flag) { if (EnviroSky.instance.PlayerCamera.get_stereoEnabled()) { if (EnviroSky.instance.singlePassVR) { Matrix4x4 matrix4x4_3 = Matrix4x4.op_Multiply(Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.get_identity(), new Vector3(0.5f, 0.5f, 0.5f)), !this._reversedZ ? Matrix4x4.Perspective(this._light.get_spotAngle(), 1f, this._light.get_shadowNearPlane(), this._light.get_range()) : Matrix4x4.Perspective(this._light.get_spotAngle(), 1f, this._light.get_range(), this._light.get_shadowNearPlane())); // ISSUE: variable of a reference type Matrix4x4& local1; ((Matrix4x4)(local1 = ref matrix4x4_3)).set_Item(0, 2, ((Matrix4x4) ref local1).get_Item(0, 2) * -1f); // ISSUE: variable of a reference type Matrix4x4& local2; ((Matrix4x4)(local2 = ref matrix4x4_3)).set_Item(1, 2, ((Matrix4x4) ref local2).get_Item(1, 2) * -1f); // ISSUE: variable of a reference type Matrix4x4& local3; ((Matrix4x4)(local3 = ref matrix4x4_3)).set_Item(2, 2, ((Matrix4x4) ref local3).get_Item(2, 2) * -1f); // ISSUE: variable of a reference type Matrix4x4& local4; ((Matrix4x4)(local4 = ref matrix4x4_3)).set_Item(3, 2, ((Matrix4x4) ref local4).get_Item(3, 2) * -1f); this._material.SetMatrix("_MyWorld2Shadow", Matrix4x4.op_Multiply(matrix4x4_3, inverse)); this._material.SetMatrix("_WorldView", Matrix4x4.op_Multiply(matrix4x4_3, inverse)); this._material.EnableKeyword("SHADOWS_DEPTH"); this._commandBuffer.SetGlobalTexture("_ShadowMapTexture", RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)1)); this._commandBuffer.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)renderer.GetVolumeLightBuffer())); this._commandBuffer.DrawMesh(spotLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, this._commandBuffer, viewProj); } else { this._material.DisableKeyword("SHADOWS_DEPTH"); renderer.GlobalCommandBuffer.DrawMesh(spotLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } else { Matrix4x4 matrix4x4_3 = Matrix4x4.op_Multiply(Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0.5f), Quaternion.get_identity(), new Vector3(0.5f, 0.5f, 0.5f)), !this._reversedZ ? Matrix4x4.Perspective(this._light.get_spotAngle(), 1f, this._light.get_shadowNearPlane(), this._light.get_range()) : Matrix4x4.Perspective(this._light.get_spotAngle(), 1f, this._light.get_range(), this._light.get_shadowNearPlane())); // ISSUE: variable of a reference type Matrix4x4& local1; ((Matrix4x4)(local1 = ref matrix4x4_3)).set_Item(0, 2, ((Matrix4x4) ref local1).get_Item(0, 2) * -1f); // ISSUE: variable of a reference type Matrix4x4& local2; ((Matrix4x4)(local2 = ref matrix4x4_3)).set_Item(1, 2, ((Matrix4x4) ref local2).get_Item(1, 2) * -1f); // ISSUE: variable of a reference type Matrix4x4& local3; ((Matrix4x4)(local3 = ref matrix4x4_3)).set_Item(2, 2, ((Matrix4x4) ref local3).get_Item(2, 2) * -1f); // ISSUE: variable of a reference type Matrix4x4& local4; ((Matrix4x4)(local4 = ref matrix4x4_3)).set_Item(3, 2, ((Matrix4x4) ref local4).get_Item(3, 2) * -1f); this._material.SetMatrix("_MyWorld2Shadow", Matrix4x4.op_Multiply(matrix4x4_3, inverse)); this._material.SetMatrix("_WorldView", Matrix4x4.op_Multiply(matrix4x4_3, inverse)); this._material.EnableKeyword("SHADOWS_DEPTH"); this._commandBuffer.SetGlobalTexture("_ShadowMapTexture", RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)1)); this._commandBuffer.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)renderer.GetVolumeLightBuffer())); this._commandBuffer.DrawMesh(spotLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, this._commandBuffer, viewProj); } } else { this._material.DisableKeyword("SHADOWS_DEPTH"); if (EnviroSky.instance.PlayerCamera.get_actualRenderingPath() == 1) { renderer.GlobalCommandBufferForward.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)renderer.GetVolumeLightBuffer())); renderer.GlobalCommandBufferForward.DrawMesh(spotLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, renderer.GlobalCommandBufferForward, viewProj); } else { renderer.GlobalCommandBuffer.DrawMesh(spotLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } }
private void SetupPointLight( EnviroSkyRendering renderer, Matrix4x4 viewProj, Matrix4x4 viewProjSP) { this._commandBuffer.Clear(); int num1 = 0; if (!this.IsCameraInPointLightBounds()) { num1 = 2; } this._material.SetPass(num1); Mesh pointLightMesh = EnviroSkyRendering.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("_WorldViewProj_SP", Matrix4x4.op_Multiply(viewProjSP, 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)EnviroSky.instance.PlayerCamera).get_transform().get_position()); if ((double)((Vector3) ref vector3).get_magnitude() >= (double)QualitySettings.get_shadowDistance()) { flag = true; } if (this._light.get_shadows() != null && !flag) { if (EnviroSky.instance.PlayerCamera.get_stereoEnabled()) { if (EnviroSky.instance.singlePassVR) { 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); } } else { 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_DEPTH"); if (EnviroSky.instance.PlayerCamera.get_actualRenderingPath() == 1) { renderer.GlobalCommandBufferForward.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)renderer.GetVolumeLightBuffer())); renderer.GlobalCommandBufferForward.DrawMesh(pointLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, renderer.GlobalCommandBufferForward, viewProj); } else { renderer.GlobalCommandBuffer.DrawMesh(pointLightMesh, matrix4x4_1, this._material, 0, num1); if (this.CustomRenderEvent == null) { return; } this.CustomRenderEvent(renderer, this, renderer.GlobalCommandBuffer, viewProj); } } }