public static void LoadShader() { if (Settings.betterLighting.Value) { //string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "deferredshader"); //AssetBundle bundle = AssetBundle.LoadFromFile(path); AssetBundle bundle = AssetBundle.LoadFromMemory(DeferredShader.shader); DeferredShader.shader = null; if (bundle == null) { VSideLoader.Logger.LogInfo("Loading bundle failed"); } else { Shader shader = bundle.LoadAsset("assets/internal-deferredshading.shader") as Shader; if (shader != null) { VSideLoader.Logger.LogInfo("Setting shader"); GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredShading, shader); } else { VSideLoader.Logger.LogInfo("Could not find shader"); } } } }
public DeferredShadingUtils() { AssetBundle AB = AssetBundle.LoadFromFile(Application.dataPath + "/../plugins/PHIBL/deferredskin"); if (AB == null) { Console.WriteLine("DeferredShadingUtil: \"deferredskin\" file missing!"); } DiffuseScatteringOnRing = AB.LoadAsset <Texture2D>("DiffuseScatteringOnRing"); DefaultSpotCookie = AB.LoadAsset <Texture2D>("DefaultSpotCookie"); AlloyBlurNormal = AB.LoadAsset <Shader>("Assets/Alloy/Scripts/DeferredRendererPlus/Shaders/BlurNormals.shader"); AlloyTransmissionBlit = AB.LoadAsset <Shader>("Assets/Alloy/Scripts/DeferredRendererPlus/Shaders/TransmissionBlit.shader"); GraphicsSettings.SetShaderMode(BuiltinShaderType.DeferredReflections, BuiltinShaderMode.UseCustom); GraphicsSettings.SetShaderMode(BuiltinShaderType.DeferredShading, BuiltinShaderMode.UseCustom); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredShading, AB.LoadAsset <Shader>("Assets/Alloy/Shaders/Alloy Deferred Skin.shader")); GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredReflections, AB.LoadAsset <Shader>("Assets/Alloy/Shaders/Alloy Deferred Reflections.shader")); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, AB.LoadAsset <Shader>("Assets/Psychose Interactive/NGSS/Internal-ScreenSpaceShadows.shader")); AlloyDeferredSkinShader = AB.LoadAsset <Material>("skin").shader; AlloyAlpha = AB.LoadAsset <Material>("nip").shader; if (AlloyDeferredSkinShader == null) { Console.WriteLine("DeferredShadingUtil: Can't find deferred skin shader!"); } AB.Unload(false); skinMaterials = new List <Material>(); }
///////////////////////////////////////////////////////////////////////////////// // initialization private void Start() { // don't initialize anything if is in editor and not playing if (IsEditing()) { return; } // initialize parameter factory StereoRenderManager.Instance.InitParamFactory(); // initialize stereo camera rig if (stereoCameraHead == null) { CreateStereoCameraRig(); } // FIX Unity 5.4 shadow bug (issue trakcer ID 686520) ++ #if UNITY_5_4 GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("ScreenSpaceShadows-ForCustomPerspectiveMat")); #endif // FIX Unity 5.4 shadow bug (issue trakcer ID 686520) -- // swap correct stereo shader for different unity versions; also create stereo material if nothing is there SwapStereoShader(); // create render textures as target of stereo rendering CreateRenderTextures(StereoRenderManager.Instance.paramFactory.GetRenderWidth(), StereoRenderManager.Instance.paramFactory.GetRenderHeight()); // get main camera and registor to StereoRenderManager StereoRenderManager.Instance.AddToManager(this); }
void GrabForeground(GameFrame targetFrame) { gameCamera.farClipPlane = targetFrame.playerDepth + 0.5f * layerOverlap; gameCamera.nearClipPlane = gameNearClipPlane; // gameCamera.clearFlags = CameraClearFlags.Color | CameraClearFlags.Depth; gameCamera.backgroundColor = new Color(0, 0, 0, 0); Shader originalScreenSpaceShadowShader = GraphicsSettings.GetCustomShader(BuiltinShaderType.ScreenSpaceShadows); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, noForegroundShadowFadeShader); LayerMask oldCull = gameCamera.cullingMask; if (forceToBackground > 0) { gameCamera.cullingMask = forceToBackground; gameCamera.RenderWithShader(blockoutBackgroundShader, null); gameCamera.clearFlags = CameraClearFlags.Nothing; //Whole point: next Render() respects this depth buffer } gameCamera.cullingMask = oldCull ^ forceToBackground; RenderGameCamera(gameCamera, targetFrame.foregroundBuffer); gameCamera.cullingMask = oldCull; GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, originalScreenSpaceShadowShader); gameCamera.nearClipPlane = gameNearClipPlane; gameCamera.farClipPlane = gameFarClipPlane; }
void RenderForeground() { float oldFar = gameCamera.farClipPlane; CameraClearFlags oldFlags = gameCamera.clearFlags; Color oldBackgroundColor = gameCamera.backgroundColor; gameCamera.farClipPlane = Mathf.Max(gameCamera.nearClipPlane + 0.001f, CalculatePlayerDepth() + 0.5f * layerOverlap); gameCamera.clearFlags = CameraClearFlags.SolidColor; gameCamera.backgroundColor = clearColor; Shader originalScreenSpaceShadowShader = GraphicsSettings.GetCustomShader(BuiltinShaderType.ScreenSpaceShadows); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, noForegroundShadowFadeShader); RenderGameCamera(gameCamera, quadrantTex); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, originalScreenSpaceShadowShader); gameCamera.farClipPlane = oldFar; gameCamera.clearFlags = oldFlags; gameCamera.backgroundColor = oldBackgroundColor; Graphics.SetRenderTarget(Output as RenderTexture); Graphics.DrawTexture(new Rect(Screen.width * 0.5f, 0, Screen.width * 0.5f, Screen.height * 0.5f), quadrantTex); }
void RenderForeground() { float oldFar = gameCamera.farClipPlane; CameraClearFlags oldFlags = gameCamera.clearFlags; Color oldBackgroundColor = gameCamera.backgroundColor; gameCamera.farClipPlane = Mathf.Max(gameCamera.nearClipPlane + 0.001f, CalculatePlayerDepth() + 0.5f * layerOverlap); gameCamera.clearFlags = CameraClearFlags.SolidColor; gameCamera.backgroundColor = new Color(clearColor.r, clearColor.g, clearColor.b, 0); Shader originalScreenSpaceShadowShader = GraphicsSettings.GetCustomShader(BuiltinShaderType.ScreenSpaceShadows); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, noForegroundShadowFadeShader); if (takeUnfilteredAlpha) { gameCamera.AddCommandBuffer(CameraEvent.BeforeImageEffects, grabAlphaCommand); //Instruction to copy out the state of the RenderTexture before Image Effects are applied } RenderGameCamera(gameCamera, quadrantTex); if (takeUnfilteredAlpha) { gameCamera.RemoveCommandBuffer(CameraEvent.BeforeImageEffects, grabAlphaCommand); Graphics.Blit(lastFrameAlpha, quadrantTex, copyAlphaMat); //Overwrite the potentially broken post-effects alpha channel with the pre-effect copy } GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, originalScreenSpaceShadowShader); gameCamera.farClipPlane = oldFar; gameCamera.clearFlags = oldFlags; gameCamera.backgroundColor = oldBackgroundColor; }
void RenderForeground(GameFrame targetFrame) { float oldFarClip = cleanProxyCamera.farClipPlane; LayerMask oldCull = cleanProxyCamera.cullingMask; CameraClearFlags oldClear = cleanProxyCamera.clearFlags; Color oldBGCol = cleanProxyCamera.backgroundColor; Color blackAndClear = new Color(0, 0, 0, 0); Graphics.SetRenderTarget(targetFrame.foregroundBuffer); GL.Clear(true, true, blackAndClear); cleanProxyCamera.farClipPlane = Mathf.Max(cleanProxyCamera.nearClipPlane + 0.001f, targetFrame.playerDist + 0.5f * layerOverlap); cleanProxyCamera.clearFlags = CameraClearFlags.Color | CameraClearFlags.Depth; //Just cleared cleanProxyCamera.backgroundColor = blackAndClear; if (forceToBackground > 0) { cleanProxyCamera.cullingMask = forceToBackground; //TODO: optimize by disabling all lighting in this render cleanProxyCamera.targetTexture = targetFrame.foregroundBuffer; cleanProxyCamera.RenderWithShader(blockoutBackgroundShader, null); //now depth buffer wont allow writes where the ground would have been cleanProxyCamera.clearFlags = CameraClearFlags.Nothing; } Shader originalScreenSpaceShadowShader = GraphicsSettings.GetCustomShader(BuiltinShaderType.ScreenSpaceShadows); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, noForegroundShadowFadeShader); cleanProxyCamera.cullingMask = oldCull ^ forceToBackground; if (MixCast.ProjectSettings.grabUnfilteredAlpha) { cleanProxyCamera.AddCommandBuffer(CameraEvent.BeforeImageEffects, grabAlphaCommand); //Instruction to copy out the state of the RenderTexture before Image Effects are applied } RenderGameCamera(cleanProxyCamera, targetFrame.foregroundBuffer); if (MixCast.ProjectSettings.grabUnfilteredAlpha) { cleanProxyCamera.RemoveCommandBuffer(CameraEvent.BeforeImageEffects, grabAlphaCommand); Graphics.Blit(LastFrameAlpha, targetFrame.foregroundBuffer, copyAlphaMat); //Overwrite the potentially broken post-effects alpha channel with the pre-effect copy } else { LastFrameAlpha = targetFrame.foregroundBuffer; } GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, originalScreenSpaceShadowShader); cleanProxyCamera.farClipPlane = oldFarClip; cleanProxyCamera.cullingMask = oldCull; cleanProxyCamera.clearFlags = oldClear; cleanProxyCamera.backgroundColor = oldBGCol; }
private void OnApplicationQuit() { if (this.isGraphicSet) { this.isGraphicSet = false; GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/Internal-ScreenSpaceShadows")); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseBuiltin); } this.RemoveCommandBuffers(); }
private void Awake() { cmr = GetComponent <Camera>(); mergeMat = new Material(mergeDepthShader); print(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap)); print(SystemInfo.supports2DArrayTextures); print((SystemInfo.copyTextureSupport & CopyTextureSupport.DifferentTypes) != 0); print((SystemInfo.copyTextureSupport & CopyTextureSupport.Copy3D) != 0); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, screenSpaceShadowsShader); }
void SetCustomShader() { if (depthNormalShader != null) { GraphicsSettings.SetShaderMode(BuiltinShaderType.DepthNormals, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.DepthNormals, depthNormalShader); } else { GraphicsSettings.SetShaderMode(BuiltinShaderType.DepthNormals, BuiltinShaderMode.UseBuiltin); } }
private void Init() { if (this.isInitialized) { return; } if (!this.isGraphicSet) { GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/NGSS_Directional")); this.isGraphicSet = true; } this.isInitialized = true; }
private void OnDisable() { this.isInitialized = false; if (this.KEEP_NGSS_ONDISABLE) { return; } if (this.isGraphicSet) { this.isGraphicSet = false; GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/Internal-ScreenSpaceShadows")); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseBuiltin); } }
public void Setup() { _light = GetComponent <Light>(); if (!_light) { return; } resolution = Mathf.ClosestPowerOfTwo(resolution); if (customShadowResolution) { _light.shadowCustomResolution = resolution; } else { _light.shadowCustomResolution = 0; } shader = Shader.Find(shaderName); // if (!Application.isEditor) // { // if (shader) // Debug.LogErrorFormat("Custom Shadow Shader Found: {0} | Supported {1}", shader.name, shader.isSupported); // else // Debug.LogError("Custom Shadow Shader Not Found!!!"); // } shadowmapPropID = Shader.PropertyToID("_ShadowMap"); copyShadowBuffer = new CommandBuffer(); copyShadowBuffer.name = "PCSS Shadows"; var buffers = _light.GetCommandBuffers(lightEvent); for (int i = 0; i < buffers.Length; i++) { if (buffers[i].name == "PCSS Shadows") { _light.RemoveCommandBuffer(lightEvent, buffers[i]); } } _light.AddCommandBuffer(lightEvent, copyShadowBuffer); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, shader); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); CreateShadowRenderTexture(); UpdateShaderValues(); UpdateCommandBuffer(); }
public void ResetShadowMode() { GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/Internal-ScreenSpaceShadows")); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.Disabled); _light.shadowCustomResolution = 0; DestroyImmediate(shadowRenderTexture); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseBuiltin); if (!_light) { return; } _light.RemoveCommandBuffer(LightEvent.AfterShadowMap, copyShadowBuffer); }
void Init() { if (isInitialized) { return; } if (isGraphicSet == false) { GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/NGSS_Directional"));//Shader.Find can sometimes return null in Player builds (careful). DirLight.shadows = LightShadows.Soft; isGraphicSet = true; } isInitialized = true; }
void Init() { if (isInitialized) { return; } if (isGraphicSet == false) { //QualitySettings.shadowProjection = ShadowProjection.StableFit; //QualitySettings.shadowCascades = 4; //QualitySettings.shadowCascade4Split = new Vector3(0.1f, 0.275f, 0.5f); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/NGSS_Directional"));//Shader.Find can sometimes return null in Player builds (careful). isGraphicSet = true; } isInitialized = true; }
void OnValidate() { if (enableInverseSquareFalloff) { GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredShading, deferredShading); GraphicsSettings.SetShaderMode(BuiltinShaderType.DeferredShading, BuiltinShaderMode.UseCustom); RegenerateFalloff(); } else { GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredShading, Shader.Find("Hidden/Internal-DeferredShading")); GraphicsSettings.SetShaderMode(BuiltinShaderType.DeferredShading, BuiltinShaderMode.Disabled); GraphicsSettings.SetShaderMode(BuiltinShaderType.DeferredShading, BuiltinShaderMode.UseBuiltin); } AssetDatabase.Refresh(); }
///////////////////////////////////////////////////////////////////////////////// // initialization private void Start() { // don't initialize anything if is in editor and not playing if (IsEditing()) { return; } // initialize parameter factory StereoRenderManager.Instance.InitParamFactory(); // initialize stereo camera rig if (stereoCameraHead == null) { CreateStereoCameraRig(); } // FIX Unity 5.4 shadow bug (issue trakcer ID 686520) ++ #if UNITY_5_4 GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("ScreenSpaceShadows-ForCustomPerspectiveMat")); #endif // FIX Unity 5.4 shadow bug (issue trakcer ID 686520) -- // swap correct stereo shader for different unity versions; also create stereo material if nothing is there SwapStereoShader(); // create render textures as target of stereo rendering CreateRenderTextures(StereoRenderManager.Instance.paramFactory.GetRenderWidth(), StereoRenderManager.Instance.paramFactory.GetRenderHeight()); // get main camera and registor to StereoRenderManager StereoRenderManager.Instance.AddToManager(this); // check "ignore layer" existence and set camera mask ignoreLayerNumber = LayerMask.NameToLayer(ignoreLayerName); if (ignoreWhenRender.Count != 0 && ignoreLayerNumber == -1) { Debug.LogError("Layer \"" + ignoreLayerName + "\" is not created."); } else { stereoCameraEye.cullingMask &= ~(1 << ignoreLayerNumber); } }
private void Init() { if (this.isInitialized) { return; } if (!this.isGraphicSet) { this.isGraphicSet = true; GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/NGSS_Directional")); } if (!this.PCSS_ENABLED) { return; } this.m_Light = base.GetComponent <Light>(); int num = (QualitySettings.shadowResolution != ShadowResolution.VeryHigh) ? ((QualitySettings.shadowResolution != ShadowResolution.High) ? ((QualitySettings.shadowResolution != ShadowResolution.Medium) ? 512 : 1024) : 2048) : 4096; this.m_ShadowmapCopy = null; this.m_ShadowmapCopy = new RenderTexture(num, num, 0, RenderTextureFormat.RFloat); this.m_ShadowmapCopy.filterMode = FilterMode.Bilinear; this.m_ShadowmapCopy.useMipMap = false; this.rawShadowDepthCB = new CommandBuffer { name = "NGSS Directional PCSS buffer" }; this.rawShadowDepthCB.Clear(); this.rawShadowDepthCB.SetShadowSamplingMode(BuiltinRenderTextureType.CurrentActive, ShadowSamplingMode.RawDepth); this.rawShadowDepthCB.Blit(BuiltinRenderTextureType.CurrentActive, this.m_ShadowmapCopy); this.rawShadowDepthCB.SetGlobalTexture("NGSS_DirectionalRawDepth", this.m_ShadowmapCopy); foreach (CommandBuffer commandBuffer in this.m_Light.GetCommandBuffers(LightEvent.AfterShadowMap)) { if (commandBuffer.name == this.rawShadowDepthCB.name) { this.isInitialized = true; return; } } this.m_Light.AddCommandBuffer(LightEvent.AfterShadowMap, this.rawShadowDepthCB); this.isInitialized = true; }
public void Setup() { _light = GetComponent <Light>(); if (!_light) { return; } resolution = Mathf.ClosestPowerOfTwo(resolution); if (customShadowResolution) { _light.shadowCustomResolution = resolution; } else { _light.shadowCustomResolution = 0; } shader = Shader.Find(shaderName); shadowmapPropID = Shader.PropertyToID("_ShadowMap"); copyShadowBuffer = new CommandBuffer(); copyShadowBuffer.name = "PCSS Shadows"; var buffers = _light.GetCommandBuffers(lightEvent); for (int i = 0; i < buffers.Length; i++) { if (buffers[i].name == "PCSS Shadows") { _light.RemoveCommandBuffer(lightEvent, buffers[i]); } } _light.AddCommandBuffer(lightEvent, copyShadowBuffer); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, shader); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); CreateShadowRenderTexture(); UpdateShaderValues(); UpdateCommandBuffer(); }
public static int SetCustomShader_s(IntPtr l) { int result; try { BuiltinShaderType type; LuaObject.checkEnum <BuiltinShaderType>(l, 1, out type); Shader shader; LuaObject.checkType <Shader>(l, 2, out shader); GraphicsSettings.SetCustomShader(type, shader); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
private void UpdateGraphics() { if (deferredShading == null) { deferredShading = Resources.Load <Shader>("Internal-DeferredShading-Dithering"); } if (screenSpaceShadows == null) { screenSpaceShadows = Resources.Load <Shader>("Internal-ScreenSpaceShadows-Dithering"); } if (noise == null) { noise = Resources.Load <Texture2D>("NoiseHigh"); } GraphicsSettings.SetShaderMode(DS, ((_point || _spot) && enabled) ? CUSTOM : BUILT_IN); GraphicsSettings.SetCustomShader(DS, ((_point || _spot) && enabled) ? deferredShading : null); GraphicsSettings.SetShaderMode(SSS, (direction && enabled) ? CUSTOM : BUILT_IN); GraphicsSettings.SetCustomShader(SSS, (direction && enabled) ? screenSpaceShadows : null); UpdateShaders(); }
//////Control Property End////// //////////////////////////////////////////////////////////////////////////////Property End/////////////////////////////////////////////////////////////////////////////////////////// void Awake() { RenderCamera = gameObject.GetComponent <Camera>(); StochasticScreenSpaceReflectionMaterial = new Material(Shader.Find("Hidden/StochasticScreenSpaceReflection")); BackDepthShader = Resources.Load("RenderBackDepth") as Shader; noise = Resources.Load("BlueNoise") as Texture2D; DeferredReflectionShader = Resources.Load("Custom-DeferredReflections") as Shader; GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredReflections, DeferredReflectionShader); //////Install RenderBuffer////// InstallRenderCommandBuffer(); #if UNITY_EDITOR //////DeBug FPS////// SetFPSFrame(DisableFPSLimit, -1); #endif //////Update don't need Tick Refresh Variable////// UpdateVariable(); //RenderCamera.depthTextureMode |= DepthTextureMode.MotionVectors; }
void Init() { if (isInitialized) { return; } if (isGraphicSet == false) { GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, Shader.Find("Hidden/NGSS_Directional"));//Shader.Find can sometimes return null in Player builds (careful). DirLight.shadows = DirLight.shadows == LightShadows.None ? LightShadows.None : LightShadows.Soft; isGraphicSet = true; } if (NGSS_NOISE_TEXTURE == null) { NGSS_NOISE_TEXTURE = Resources.Load <Texture2D>("BlueNoise_R8_8"); } Shader.SetGlobalTexture("_BlueNoiseTextureDir", NGSS_NOISE_TEXTURE); isInitialized = true; }
public void ResetShadowMode() { builtinShader = Shader.Find(builtinShaderName); // if (!Application.isEditor) // { // if (builtinShader) // Debug.LogErrorFormat("Built-In Shadow Shader Found: {0} | Supported {1}", builtinShader.name, builtinShader.isSupported); // else // Debug.LogError("Shadow Shader Not Found!!!"); // } GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, builtinShader); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.Disabled); _light.shadowCustomResolution = 0; DestroyImmediate(shadowRenderTexture); GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseBuiltin); if (!_light) { return; } _light.RemoveCommandBuffer(LightEvent.AfterShadowMap, copyShadowBuffer); }
/// <summary> /// Configure the materials and buffer for the deferred mode /// </summary> private void SetDeferred() { //Disable MSSA not supported with deferred #if UNITY_5_6_OR_NEWER mainCamera.allowMSAA = false; #endif ghasShadows = false; deferredMat = new Material(Resources.Load("Materials/Lighting/Mat_ZED_Deferred") as Material); blitMaterial = new Material(Resources.Load("Materials/PostProcessing/Mat_ZED_Blit") as Material); //Sets the custom shader for the deferred pipeline GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredShading, (Resources.Load("Materials/Lighting/Mat_ZED_Deferred_Lighting") as Material).shader); deferredMat.SetMatrix("_Model", canvas.transform.localToWorldMatrix.transpose); deferredMat.SetMatrix("_Projection", mainCamera.projectionMatrix); deferredMat.SetTexture("_MainTex", textureEye); deferredMat.SetTexture("_DepthXYZTex", depth); deferredMat.SetTexture("_NormalsTex", normals); //clear the buffers if (buffer[(int)ZED_RENDERING_MODE.FORWARD] != null) { mainCamera.RemoveCommandBuffer(CameraEvent.BeforeDepthTexture, buffer[(int)ZED_RENDERING_MODE.FORWARD]); } if (buffer[(int)ZED_RENDERING_MODE.DEFERRED] != null) { mainCamera.RemoveCommandBuffer(CameraEvent.AfterGBuffer, buffer[(int)ZED_RENDERING_MODE.DEFERRED]); } if (postProcessBuffer[(int)ZED_RENDERING_MODE.FORWARD] != null) { mainCamera.RemoveCommandBuffer(CameraEvent.AfterForwardAlpha, postProcessBuffer[(int)ZED_RENDERING_MODE.FORWARD]); } if (postProcessBuffer[(int)ZED_RENDERING_MODE.FORWARD] != null) { postProcessBuffer[(int)ZED_RENDERING_MODE.FORWARD].Dispose(); postProcessBuffer[(int)ZED_RENDERING_MODE.FORWARD] = null; } ClearDepthBuffers(); //Set the depths buffer, the buffer will be changed if the camera allow HDR buffer[(int)ZED_RENDERING_MODE.DEFERRED] = new CommandBuffer(); buffer[(int)ZED_RENDERING_MODE.DEFERRED].name = "ZED_DEPTH"; if (mainCamera.allowHDR) { RenderTargetIdentifier[] mrt = { BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer1, BuiltinRenderTextureType.GBuffer2, BuiltinRenderTextureType.CameraTarget }; buffer[(int)ZED_RENDERING_MODE.DEFERRED].SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget); } else { RenderTargetIdentifier[] mrt = { BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer1, BuiltinRenderTextureType.GBuffer2, BuiltinRenderTextureType.GBuffer3 }; buffer[(int)ZED_RENDERING_MODE.DEFERRED].SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget); } buffer[(int)ZED_RENDERING_MODE.DEFERRED].DrawMesh(meshCanvas.mesh, gameObject.transform.GetChild(0).transform.localToWorldMatrix, deferredMat); if (mask == null || !mask.IsCreated()) { mask = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.R8); } //Set the post process buffer postProcessBuffer[(int)ZED_RENDERING_MODE.DEFERRED] = new CommandBuffer(); postProcessBuffer[(int)ZED_RENDERING_MODE.DEFERRED].name = "ZED_FORWARD_POSTPROCESS"; postProcessBuffer[(int)ZED_RENDERING_MODE.DEFERRED].Blit(BuiltinRenderTextureType.GBuffer0, mask, blitMaterial, 0); postProcessBuffer[(int)ZED_RENDERING_MODE.DEFERRED].SetGlobalTexture("_ZEDMaskVirtual", mask); postprocessMaterial.SetTexture("ZEDMaskPostProcess", mask); postprocessMaterial.SetTexture("ZEDTex", textureEye); mainCamera.AddCommandBuffer(CameraEvent.AfterGBuffer, buffer[(int)ZED_RENDERING_MODE.DEFERRED]); mainCamera.AddCommandBuffer(CameraEvent.AfterFinalPass, postProcessBuffer[(int)ZED_RENDERING_MODE.DEFERRED]); //Congigure the invisible object if (forceShadowObject == null) { ConfigureForceShadowObject(); } transform.GetChild(0).GetComponent <MeshRenderer>().enabled = false; }
void OnEnable() { GraphicsSettings.SetShaderMode(BuiltinShaderType.DepthNormals, BuiltinShaderMode.UseCustom); GraphicsSettings.SetCustomShader(BuiltinShaderType.DepthNormals, customShader); }
void OnDisable() { GraphicsSettings.SetCustomShader(BuiltinShaderType.DepthNormals, customShader); }
void SetShadows() { if (HighLogic.LoadedScene != GameScenes.MAINMENU) { if (unifiedCameraMode && (mainSettings.d3d11ShadowFix || mainSettings.terrainShadows)) { QualitySettings.shadowProjection = ShadowProjection.StableFit; //way more resistant to jittering GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.UseCustom); if ((mainSettings.terrainShadows) && (mainSettings.unifiedCamShadowsDistance > 8000f)) { GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, ShaderReplacer.Instance.LoadedShaders [("Scatterer/longDistanceScreenSpaceShadows")]); partialUnifiedCameraDepthBuffer = (PartialDepthBuffer)nearCamera.gameObject.AddComponent(typeof(PartialDepthBuffer)); partialUnifiedCameraDepthBuffer.Init(nearCamera); } else { GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, ShaderReplacer.Instance.LoadedShaders [("Scatterer/fixedScreenSpaceShadows")]); } } if (mainSettings.shadowsOnOcean) { if (unifiedCameraMode || SystemInfo.graphicsDeviceVersion.Contains("Direct3D 11.0")) { QualitySettings.shadowProjection = ShadowProjection.StableFit; //StableFit + splitSpheres is the only thing that works Correctly for unified camera (dx11) ocean shadows //Otherwise we get artifacts near shadow cascade edges } else { QualitySettings.shadowProjection = ShadowProjection.CloseFit; //CloseFit without SplitSpheres seems to be the only setting that works for OpenGL for ocean shadows //Seems like I lack the correct variables to determine which shadow path to take //also try without the transparent tag } shadowMapRetriever = (ShadowMapRetrieveCommandBuffer)sunLight.gameObject.AddComponent(typeof(ShadowMapRetrieveCommandBuffer)); } if (mainSettings.terrainShadows) { QualitySettings.shadowDistance = unifiedCameraMode ? mainSettings.unifiedCamShadowsDistance : mainSettings.dualCamShadowsDistance; Utils.LogDebug("Set shadow distance: " + QualitySettings.shadowDistance.ToString()); Utils.LogDebug("Number of shadow cascades detected " + QualitySettings.shadowCascades.ToString()); if (sunLight) { //fixes checkerboard artifacts aka shadow acne float bias = unifiedCameraMode ? mainSettings.unifiedCamShadowNormalBiasOverride : mainSettings.dualCamShadowNormalBiasOverride; float normalBias = unifiedCameraMode ? mainSettings.unifiedCamShadowBiasOverride : mainSettings.dualCamShadowBiasOverride; if (bias > 0f) { sunLight.shadowBias = bias; } if (normalBias > 0f) { sunLight.shadowNormalBias = normalBias; } int customRes = unifiedCameraMode ? mainSettings.unifiedCamShadowResolutionOverride : mainSettings.dualCamShadowResolutionOverride; if (customRes != 0) { if (Utils.IsPowerOfTwo(customRes)) { Utils.LogDebug("Setting shadowmap resolution to: " + customRes.ToString()); sunLight.shadowCustomResolution = customRes; } else { Utils.LogError("Selected shadowmap resolution not a power of 2: " + customRes.ToString()); } } } //and finally force shadow Casting and receiving on celestial bodies if not already set foreach (CelestialBody _sc in scattererCelestialBodiesManager.CelestialBodies) { if (_sc.pqsController) { _sc.pqsController.meshCastShadows = true; _sc.pqsController.meshRecieveShadows = true; } } } } }
void Start() { #if UNITY_EDITOR UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect16by9, true); UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect16by10, false); UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect4by3, false); UnityEditor.PlayerSettings.SetAspectRatio(UnityEditor.AspectRatio.Aspect5by4, false); #endif bounds = new Bounds(transform.position, new Vector3(30, 30, 30)); sl.ZEDCamera zedCamera = sl.ZEDCamera.GetInstance(); //Set the camera parameters and scale the screen if (zedCamera.CameraIsReady) { mainCamera.fieldOfView = zedCamera.GetFOV() * Mathf.Rad2Deg; mainCamera.projectionMatrix = zedCamera.Projection; mainCamera.nearClipPlane = 0.2f; mainCamera.farClipPlane = 500.0f; scale(canvas.gameObject, GetFOVFromProjectionMatrix(mainCamera.projectionMatrix)); } else { scale(canvas.gameObject, mainCamera.fieldOfView); } if (xyz) { Shader.EnableKeyword("ZED_XYZ"); depthXYZZed = zedCamera.CreateTextureMeasureType(sl.MEASURE.XYZ); } else { Shader.DisableKeyword("ZED_XYZ"); depthXYZZed = zedCamera.CreateTextureMeasureType(sl.MEASURE.DEPTH); } camZedLeft = zedCamera.CreateTextureImageType(videoType); normals = zedCamera.CreateTextureMeasureType(sl.MEASURE.NORMALS); //If forward mode is activated if (mainCamera.actualRenderingPath == RenderingPath.Forward) { Shader.SetGlobalInt("_HasShadows", 0); gameObject.transform.GetChild(0).GetComponent <MeshRenderer>().enabled = true; //Set textures to the shader matRGB = canvas.GetComponent <Renderer>().material; matRGB.SetInt("_isLinear", System.Convert.ToInt32(QualitySettings.activeColorSpace)); forwardMat = Resources.Load("Materials/Mat_ZED_Forward") as Material; if (videoType == sl.VIEW.LEFT_GREY || videoType == sl.VIEW.RIGHT_GREY || videoType == sl.VIEW.LEFT_UNRECTIFIED_GREY || videoType == sl.VIEW.RIGHT_UNRECTIFIED_GREY) { matRGB.SetInt("_isGrey", 1); } else { matRGB.SetInt("_isGrey", 0); } GameObject o = GameObject.CreatePrimitive(PrimitiveType.Quad); o.name = "ZED_FORCE_SHADOW"; o.transform.parent = transform; o.transform.localScale = new Vector3(0.001f, 0.001f, 0.001f); o.transform.localPosition = new Vector3(0, 0, mainCamera.nearClipPlane); o.GetComponent <MeshRenderer>().sharedMaterial = Resources.Load("Materials/Mat_ZED_Nothing") as Material; Destroy(o.GetComponent <MeshCollider>()); o.hideFlags = HideFlags.HideAndDontSave; matRGB.SetTexture("_MainTex", camZedLeft); matRGB.SetTexture("_CameraTex", camZedLeft); matRGB.SetTexture("_DepthXYZTex", depthXYZZed); matRGB.SetTexture("_NormalsTex", normals); forwardMat.SetTexture("_MainTex", camZedLeft); forwardMat.SetTexture("_DepthXYZTex", depthXYZZed); buffer = new CommandBuffer(); buffer.name = "ZED_DEPTH"; buffer.SetRenderTarget(BuiltinRenderTextureType.CurrentActive, BuiltinRenderTextureType.Depth); buffer.DrawMesh(mesh.mesh, gameObject.transform.GetChild(0).transform.localToWorldMatrix, forwardMat); // mainCamera.AddCommandBuffer(CameraEvent.BeforeDepthTexture, buffer); computeBuffePointLight = new ComputeBuffer(NUMBER_POINT_LIGHT_MAX, SIZE_POINT_LIGHT_BYTES); computeBuffePointLight.SetData(pointLights); matRGB.SetBuffer("pointLights", computeBuffePointLight); computeBufferSpotLight = new ComputeBuffer(NUMBER_SPOT_LIGHT_MAX, SIZE_SPOT_LIGHT_BYTES); computeBufferSpotLight.SetData(spotLights); matRGB.SetBuffer("spotLights", computeBufferSpotLight); zedCamera.SetDepthMaxRangeValue(15); } else if (mainCamera.actualRenderingPath == RenderingPath.DeferredShading) { //Sets the custom shader for the deferred pipeline GraphicsSettings.SetCustomShader(BuiltinShaderType.DeferredShading, (Resources.Load("Materials/Mat_ZED_Custom_Deferred") as Material).shader); deferredMat = Resources.Load("Materials/Mat_ZED_Deferred") as Material; deferredMat.SetTexture("_MainTex", camZedLeft); deferredMat.SetTexture("_DepthXYZTex", depthXYZZed); deferredMat.SetTexture("_NormalsTex", normals); //gameObject.transform.GetChild(0).GetComponent<MeshRenderer>().enabled = false; buffer = new CommandBuffer(); buffer.name = "ZED_DEPTH"; RenderTargetIdentifier[] mrt = { BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer1, BuiltinRenderTextureType.GBuffer2, BuiltinRenderTextureType.GBuffer3 }; buffer.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget); buffer.DrawMesh(mesh.mesh, gameObject.transform.GetChild(0).transform.localToWorldMatrix, deferredMat); //Set an object in the scene to force shadow casting gameObject.transform.GetChild(0).position = new Vector3(0, 0, mainCamera.nearClipPlane); gameObject.transform.GetChild(0).localScale = new Vector3(0.01f, 0.01f, 0.01f); gameObject.transform.GetChild(0).GetComponent <MeshRenderer>().sharedMaterial = Resources.Load("Materials/Mat_ZED_Nothing") as Material; buffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); mainCamera.AddCommandBuffer(CameraEvent.AfterGBuffer, buffer); } else { Debug.LogError(" [ ZED Plugin ] : The rendering path " + mainCamera.actualRenderingPath.ToString() + " is not compatible with the ZED"); } }