// Whenever any camera will render us, add a command buffer to do the work on it public void OnWillRenderObject() { var act = gameObject.activeInHierarchy && enabled; if (!act) { Cleanup(); return; } var cam = Camera.current; if (!cam) return; CommandBuffer buf = null; // Did we already add the command buffer on this camera? Nothing to do then. if (m_Cameras.ContainsKey(cam)) return; if (!m_Material) { m_Material = new Material(m_BlurShader); m_Material.hideFlags = HideFlags.HideAndDontSave; } buf = new CommandBuffer(); buf.name = "Grab screen and blur"; m_Cameras[cam] = buf; // copy screen into temporary RT int screenCopyID = Shader.PropertyToID("_ScreenCopyTexture"); buf.GetTemporaryRT (screenCopyID, -1, -1, 0, FilterMode.Bilinear); buf.Blit (BuiltinRenderTextureType.CurrentActive, screenCopyID); // get two smaller RTs int blurredID = Shader.PropertyToID("_Temp1"); int blurredID2 = Shader.PropertyToID("_Temp2"); buf.GetTemporaryRT (blurredID, -2, -2, 0, FilterMode.Bilinear); buf.GetTemporaryRT (blurredID2, -2, -2, 0, FilterMode.Bilinear); // downsample screen copy into smaller RT, release screen RT buf.Blit (screenCopyID, blurredID); buf.ReleaseTemporaryRT (screenCopyID); // horizontal blur buf.SetGlobalVector("offsets", new Vector4(2.0f/Screen.width,0,0,0)); buf.Blit (blurredID, blurredID2, m_Material); // vertical blur buf.SetGlobalVector("offsets", new Vector4(0,2.0f/Screen.height,0,0)); buf.Blit (blurredID2, blurredID, m_Material); // horizontal blur buf.SetGlobalVector("offsets", new Vector4(4.0f/Screen.width,0,0,0)); buf.Blit (blurredID, blurredID2, m_Material); // vertical blur buf.SetGlobalVector("offsets", new Vector4(0,4.0f/Screen.height,0,0)); buf.Blit (blurredID2, blurredID, m_Material); buf.SetGlobalTexture("_GrabBlurTexture", blurredID); cam.AddCommandBuffer (CameraEvent.AfterSkybox, buf); }
void _OnEnable() { if (LastBuffer == null) { /*LastBuffer.GetTemporaryRT(texID, -1, -1, 0); * LastBuffer.Blit(BuiltinRenderTextureType.CameraTarget, texID); * // LastBuffer.ReleaseTemporaryRT( texID); * LastBuffer.SetGlobalTexture("_LastFrame", texID);*/ /*if (LastTexture == null) * { LastTexture = new RenderTexture(this_camera.pixelWidth, this_camera.pixelHeight, 32) * { * hideFlags = HideFlags.HideAndDontSave, * name = "EModules/MobileWater/LastFrame-RenderTexture" + gameObject.name, * }; * }*/ /* LastBuffer = new UnityEngine.Rendering.CommandBuffer() {name = "EMX Water Buffer" }; * texID = Shader.PropertyToID("_LastFrame"); * LastBuffer.GetTemporaryRT (texID, -1, -1, 0, FilterMode.Bilinear); * LastBuffer.Blit (BuiltinRenderTextureType.CurrentActive, texID);*/ int screenCopyID = Shader.PropertyToID("_ScreenCopyTexture"); LastBuffer.GetTemporaryRT(screenCopyID, -1, -1, 0, FilterMode.Bilinear); LastBuffer.Blit(BuiltinRenderTextureType.GBuffer2, screenCopyID); LastBuffer.SetGlobalTexture("_LastFrame", screenCopyID); Camera.main.AddCommandBuffer(CameraEvent.AfterEverything, LastBuffer); } }
private void Awake() { int lowResRenderTarget = Shader.PropertyToID("_LowResRenderTarget"); CommandBuffer cb = new CommandBuffer(); cb.GetTemporaryRT(lowResRenderTarget, this.width, this.height, 0, FilterMode.Trilinear, RenderTextureFormat.ARGB32); // Blit the low-res texture into itself, to re-draw it with the current material cb.Blit(lowResRenderTarget, lowResRenderTarget, this.material); // Blit the low-res texture into the camera's target render texture, effectively rendering it to the entire screen cb.Blit(lowResRenderTarget, BuiltinRenderTextureType.CameraTarget); cb.ReleaseTemporaryRT(lowResRenderTarget); // Tell the camera to execute our CommandBuffer before the forward opaque pass - that is, just before normal geometry starts rendering this.GetComponent<Camera>().AddCommandBuffer(CameraEvent.BeforeForwardOpaque, cb); }
/*void OnRenderImage(RenderTexture s, RenderTexture d) * { // LastTexture = s; * // s.ConvertToEquirect * StackBlit(s); * Graphics.Blit(s, d); * //LastTexture2 = d; * }*/ //static CameraEvent EventType {get {return TransparentFlag ? CameraEvent.BeforeImageEffects : CameraEvent.AfterForwardOpaque; } } void EnableLast2() { LastBuffer2 = new UnityEngine.Rendering.CommandBuffer() { name = "EMX Water Buffer" }; CheckLastTex(); LastBuffer2.Blit(BuiltinRenderTextureType.CurrentActive, LastTexture2); this_camera.AddCommandBuffer(EventType, LastBuffer2); //, UnityEngine.Rendering.ComputeQueueType.Background*/ }
void EnsureResolveDepthHooks() { if (m_copyDepthCB == null) { m_copyDepthCB = new UnityEngine.Rendering.CommandBuffer(); m_copyDepthCB.name = "CopyResolveReflectionDepth"; m_copyDepthCB.Blit( new UnityEngine.Rendering.RenderTargetIdentifier(UnityEngine.Rendering.BuiltinRenderTextureType.None), new UnityEngine.Rendering.RenderTargetIdentifier(m_reflectionDepthMap), m_convolveMaterial, 2 ); } if (m_reflectionCamera.commandBufferCount == 0) { m_reflectionCamera.AddCommandBuffer(UnityEngine.Rendering.CameraEvent.AfterEverything, m_copyDepthCB); } }
// Whenever any camera will render us, add a command buffer to do the work on it public void OnWillRenderObject() { // REQUIRES THIS OBJ TO HAVE MESHRENDERER COMPONENT!!!! var act = gameObject.activeInHierarchy && enabled; if (!act) { Cleanup(); return; } var cam = Camera.current; if (!cam) return; CommandBuffer buf = null; // clear CommandBuffer... why does this have to be done every frame? // Did we already add the command buffer on this camera? Nothing to do then. if (m_Cameras.ContainsKey(cam)) return; //if (!m_Material) { // m_Material = new Material(m_BlurShader); // m_Material.hideFlags = HideFlags.HideAndDontSave; // not sure what this does -- prevents garbage collection?? //} buf = new CommandBuffer(); buf.name = "TestDrawProcedural"; m_Cameras[cam] = buf; // fill in dictionary entry for this Camera // START!!! // Canvas First: canvasMaterial.SetColor("_Color", Color.gray); // initialize canvas canvasMaterial.SetTexture("_DepthTex", canvasDepthTex); canvasMaterial.SetFloat("_MaxDepth", 1.0f); // Create RenderTargets: int colorReadID = Shader.PropertyToID("_ColorTextureRead"); int colorWriteID = Shader.PropertyToID("_ColorTextureWrite"); int depthReadID = Shader.PropertyToID("_DepthTextureRead"); int depthWriteID = Shader.PropertyToID("_DepthTextureWrite"); buf.GetTemporaryRT(colorReadID, -1, -1, 0, FilterMode.Bilinear); buf.GetTemporaryRT(colorWriteID, -1, -1, 0, FilterMode.Bilinear); buf.GetTemporaryRT(depthReadID, -1, -1, 0, FilterMode.Bilinear); buf.GetTemporaryRT(depthWriteID, -1, -1, 0, FilterMode.Bilinear); RenderTargetIdentifier[] mrt = { colorWriteID, depthWriteID }; // Define multipleRenderTarget so I can render to color AND depth buf.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget); // Set render Targets buf.ClearRenderTarget(true, true, Color.white, 1.0f); // clear -- needed??? buf.DrawMesh(CreateFullscreenQuad(mainCam), Matrix4x4.identity, canvasMaterial); // Write into canvas Color & Depth buffers // Copy results into Read buffers for next pass: buf.Blit(colorWriteID, colorReadID); buf.Blit(depthWriteID, depthReadID); // Gesso/Primer Pass: gessoMaterial.SetPass(0); gessoMaterial.SetColor("_Color", new Color(0.19f, 0.192f, 0.194f, 1.0f)); buf.SetGlobalTexture("_ColorReadTex", colorReadID); buf.SetGlobalTexture("_DepthReadTex", depthReadID); buf.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget); // Set render Targets buf.DrawMesh(CreateFullscreenQuad(mainCam), Matrix4x4.identity, gessoMaterial); // Copy results into Read buffers for next pass: buf.Blit(colorWriteID, colorReadID); buf.Blit(depthWriteID, depthReadID); // MAIN BRUSHSTROKE CONTENTS PASS!!!: strokeMaterial.SetPass(0); strokeMaterial.SetColor("_Color", brushStrokeColor); strokeMaterial.SetVector("_Size", size); strokeMaterial.SetBuffer("strokeDataBuffer", strokeBuffer); strokeMaterial.SetBuffer("quadPointsBuffer", quadPointsBuffer); buf.SetGlobalTexture("_ColorReadTex", colorReadID); buf.SetGlobalTexture("_DepthReadTex", depthReadID); buf.SetRenderTarget(colorWriteID); buf.SetGlobalTexture("_FrameBufferTexture", BuiltinRenderTextureType.CameraTarget); // Copy the Contents of FrameBuffer into brushstroke material so it knows what color it should be buf.DrawProcedural(Matrix4x4.identity, strokeMaterial, 0, MeshTopology.Triangles, 6, strokeBuffer.count); // Apply brushstrokes // DISPLAY TO SCREEN: buf.Blit(colorWriteID, BuiltinRenderTextureType.CameraTarget); // copy canvas target into main displayTarget so it is what the player sees // apply the commandBuffer cam.AddCommandBuffer(CameraEvent.AfterFinalPass, buf); //buf.SetRenderTarget(canvasRT); //buf.ClearRenderTarget(true, true, Color.black, 1.0f); //int canvasID = Shader.PropertyToID("_CanvasTexture"); //int tempID = Shader.PropertyToID("_TempTexture"); //buf.GetTemporaryRT(canvasID, -1, -1, 0, FilterMode.Bilinear); // Create a Temporary RenderTarget for the "canvas" //buf.GetTemporaryRT(tempID, -1, -1, 0, FilterMode.Bilinear); // Create a Temporary RenderTarget for the "canvas" //buf.SetRenderTarget(canvasID); // Set commandBuffer target to this "canvas" so the DrawProcedural will apply to this //buf.ClearRenderTarget(true, true, Color.white, 1.0f); // Clear the target each frame and rebuild //buf.Blit(canvasID, tempID); // copy into temporary buffer //buf.Blit(tempID, canvasID, gessoBlitMaterial); // copy back into renderTarget, apply Gesso Primer //buf.SetGlobalTexture("_FrameBufferTexture", BuiltinRenderTextureType.CameraTarget); // Copy the Contents of FrameBuffer into brushstroke material so it knows what color it should be //buf.DrawProcedural(Matrix4x4.identity, strokeMaterial, 0, MeshTopology.Triangles, 6, strokeBuffer.count); // Apply brushstrokes // MRT example: //RenderTargetIdentifier[] mrt = { BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer2 }; //buf.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget); //buf.Blit(canvasID, BuiltinRenderTextureType.CameraTarget); // copy canvas target into main displayTarget so it is what the player sees //Material testMat = new Material(Shader.Find("Unlit/Color")); //testMat.color = Color.yellow; //buf.DrawMesh(CreateFullscreenQuad(mainCam), Matrix4x4.identity, testMat); //buf.ReleaseTemporaryRT(colorReadID); //buf.ReleaseTemporaryRT(colorWriteID); //buf.ReleaseTemporaryRT(depthReadID); //buf.ReleaseTemporaryRT(depthWriteID); }
void OnEnable() { m_cam = GetComponent<Camera>(); m_quad = FrameCapturerUtils.CreateFullscreenQuad(); m_mat_copy = new Material(m_sh_copy); if (m_cam.targetTexture != null) { m_mat_copy.EnableKeyword("OFFSCREEN"); } { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb = new CommandBuffer(); m_cb.name = "GifCapturer: copy frame buffer"; m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Point); m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid); // tid は意図的に開放しない m_cam.AddCommandBuffer(CameraEvent.AfterEverything, m_cb); } ResetRecordingState(); }
void InitializeContext() { m_num_video_frames = 0; // initialize scratch buffer UpdateScratchBuffer(); // initialize context and stream { m_mp4conf = fcAPI.fcMP4Config.default_value; m_mp4conf.video = m_captureVideo; m_mp4conf.audio = m_captureAudio; m_mp4conf.video_width = m_scratch_buffer.width; m_mp4conf.video_height = m_scratch_buffer.height; m_mp4conf.video_max_framerate = 60; m_mp4conf.video_bitrate = m_videoBitrate; m_mp4conf.audio_bitrate = m_audioBitrate; m_mp4conf.audio_sampling_rate = AudioSettings.outputSampleRate; m_mp4conf.audio_num_channels = fcAPI.fcGetNumAudioChannels(); m_ctx = fcAPI.fcMP4CreateContext(ref m_mp4conf); m_output_file = DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4"; m_ostream = fcAPI.fcCreateFileStream(GetOutputPath()); fcAPI.fcMP4AddOutputStream(m_ctx, m_ostream); } // initialize command buffer { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb = new CommandBuffer(); m_cb.name = "MP4Recorder: copy frame buffer"; m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Bilinear); m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb.SetRenderTarget(m_scratch_buffer); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 0); m_cb.ReleaseTemporaryRT(tid); } }
static public int Blit(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.BuiltinRenderTextureType), typeof(int))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.BuiltinRenderTextureType a1; checkEnum(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); self.Blit(a1, a2); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.BuiltinRenderTextureType), typeof(UnityEngine.RenderTexture))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.BuiltinRenderTextureType a1; checkEnum(l, 2, out a1); UnityEngine.RenderTexture a2; checkType(l, 3, out a2); self.Blit(a1, a2); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Texture), typeof(UnityEngine.RenderTexture))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Texture a1; checkType(l, 2, out a1); UnityEngine.RenderTexture a2; checkType(l, 3, out a2); self.Blit(a1, a2); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.BuiltinRenderTextureType), typeof(int), typeof(UnityEngine.Material))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.BuiltinRenderTextureType a1; checkEnum(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); self.Blit(a1, a2, a3); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.BuiltinRenderTextureType), typeof(UnityEngine.RenderTexture), typeof(UnityEngine.Material))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.BuiltinRenderTextureType a1; checkEnum(l, 2, out a1); UnityEngine.RenderTexture a2; checkType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); self.Blit(a1, a2, a3); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Texture), typeof(UnityEngine.RenderTexture), typeof(UnityEngine.Material))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Texture a1; checkType(l, 2, out a1); UnityEngine.RenderTexture a2; checkType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); self.Blit(a1, a2, a3); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.BuiltinRenderTextureType), typeof(int), typeof(UnityEngine.Material), typeof(int))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.BuiltinRenderTextureType a1; checkEnum(l, 2, out a1); System.Int32 a2; checkType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.Blit(a1, a2, a3, a4); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.BuiltinRenderTextureType), typeof(UnityEngine.RenderTexture), typeof(UnityEngine.Material), typeof(int))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.BuiltinRenderTextureType a1; checkEnum(l, 2, out a1); UnityEngine.RenderTexture a2; checkType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.Blit(a1, a2, a3, a4); pushValue(l, true); return(1); } else if (matchType(l, argc, 2, typeof(UnityEngine.Texture), typeof(UnityEngine.RenderTexture), typeof(UnityEngine.Material), typeof(int))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Texture a1; checkType(l, 2, out a1); UnityEngine.RenderTexture a2; checkType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.Blit(a1, a2, a3, a4); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
void OnEnable() { m_outputDir.CreateDirectory(); m_quad = FrameCapturerUtils.CreateFullscreenQuad(); m_mat_copy = new Material(m_shCopy); var cam = GetComponent<Camera>(); if (cam.targetTexture != null) { m_mat_copy.EnableKeyword("OFFSCREEN"); } #if UNITY_EDITOR if (m_captureGBuffer && !FrameCapturerUtils.IsRenderingPathDeferred(cam)) { Debug.LogWarning("PngRecorder: Rendering Path must be deferred to use Capture GBuffer mode."); m_captureGBuffer = false; } #endif // UNITY_EDITOR // initialize png context fcAPI.fcPngConfig conf = fcAPI.fcPngConfig.default_value; m_ctx = fcAPI.fcPngCreateContext(ref conf); // initialize render targets { m_frame_buffer = new RenderTexture(cam.pixelWidth, cam.pixelHeight, 0, RenderTextureFormat.ARGBHalf); m_frame_buffer.wrapMode = TextureWrapMode.Repeat; m_frame_buffer.Create(); var formats = new RenderTextureFormat[7] { RenderTextureFormat.ARGBHalf, // albedo (RGB) RenderTextureFormat.RHalf, // occlusion (R) RenderTextureFormat.ARGBHalf, // specular (RGB) RenderTextureFormat.RHalf, // smoothness (R) RenderTextureFormat.ARGBHalf, // normal (RGB) RenderTextureFormat.ARGBHalf, // emission (RGB) RenderTextureFormat.RHalf, // depth (R) }; m_gbuffer = new RenderTexture[7]; for (int i = 0; i < m_gbuffer.Length; ++i) { // last one is depth (1 channel) m_gbuffer[i] = new RenderTexture(cam.pixelWidth, cam.pixelHeight, 0, formats[i]); m_gbuffer[i].filterMode = FilterMode.Point; m_gbuffer[i].Create(); } } // initialize command buffers { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb_copy_fb = new CommandBuffer(); m_cb_copy_fb.name = "PngRecorder: Copy FrameBuffer"; m_cb_copy_fb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Point); m_cb_copy_fb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb_copy_fb.SetRenderTarget(m_frame_buffer); m_cb_copy_fb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 0); m_cb_copy_fb.ReleaseTemporaryRT(tid); m_cb_copy_gb = new CommandBuffer(); m_cb_copy_gb.name = "PngRecorder: Copy G-Buffer"; m_cb_copy_gb.SetRenderTarget( new RenderTargetIdentifier[] { m_gbuffer[0], m_gbuffer[1], m_gbuffer[2], m_gbuffer[3] }, m_gbuffer[0]); m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 4); m_cb_copy_gb.SetRenderTarget( new RenderTargetIdentifier[] { m_gbuffer[4], m_gbuffer[5], m_gbuffer[6], m_gbuffer[3] }, m_gbuffer[0]); m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 5); } }
private void UpdateVerticesGPU( CommandBuffer updateCB, bool starting ) { if ( !starting && m_wasVisible ) { AmplifyMotionEffectBase.DiscardContents( m_gpuPrevVertices ); updateCB.Blit( new RenderTargetIdentifier( m_gpuCurrVertices ), m_gpuPrevVertices ); } updateCB.SetGlobalMatrix( "_AM_WORLD_TO_LOCAL_MATRIX", m_worldToLocalMatrix ); AmplifyMotionEffectBase.DiscardContents( m_gpuCurrVertices ); RenderTexture dummy = null; updateCB.Blit( new RenderTargetIdentifier( dummy ), m_gpuCurrVertices, m_gpuSkinDeformMat, Mathf.Min( m_weightCount - 1, 2 ) ); if ( starting || !m_wasVisible ) { AmplifyMotionEffectBase.DiscardContents( m_gpuPrevVertices ); updateCB.Blit( new RenderTargetIdentifier( m_gpuCurrVertices ), m_gpuPrevVertices ); } }
// [ImageEffectOpaque] public void OnPreRender() { if (material == null) { return; } else if (Camera.current.actualRenderingPath != RenderingPath.DeferredShading) { return; } int downsampleAmount = (settings.reflectionSettings.reflectionQuality == SSRResolution.High) ? 1 : 2; var rtW = camera_.pixelWidth / downsampleAmount; var rtH = camera_.pixelHeight / downsampleAmount; float sWidth = camera_.pixelWidth; float sHeight = camera_.pixelHeight; float sx = sWidth / 2.0f; float sy = sHeight / 2.0f; const int maxMip = 5; RenderTextureFormat intermediateFormat = camera_.hdr ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32; material.SetInt("_RayStepSize", settings.reflectionSettings.stepSize); material.SetInt("_AdditiveReflection", settings.reflectionSettings.blendType == SSRReflectionBlendType.Additive ? 1 : 0); material.SetInt("_BilateralUpsampling", bilateralUpsample ? 1 : 0); material.SetInt("_TreatBackfaceHitAsMiss", treatBackfaceHitAsMiss ? 1 : 0); material.SetInt("_AllowBackwardsRays", settings.reflectionSettings.reflectBackfaces ? 1 : 0); material.SetInt("_TraceBehindObjects", traceBehindObjects ? 1 : 0); material.SetInt("_MaxSteps", settings.reflectionSettings.iterationCount); material.SetInt("_FullResolutionFiltering", 0); material.SetInt("_HalfResolution", (settings.reflectionSettings.reflectionQuality != SSRResolution.High) ? 1 : 0); material.SetInt("_HighlightSuppression", highlightSuppression ? 1 : 0); /** The height in pixels of a 1m object if viewed from 1m away. */ float pixelsPerMeterAtOneMeter = sWidth / (-2.0f * (float)(Math.Tan(camera_.fieldOfView / 180.0 * Math.PI * 0.5))); material.SetFloat("_PixelsPerMeterAtOneMeter", pixelsPerMeterAtOneMeter); material.SetFloat("_ScreenEdgeFading", settings.screenEdgeMask.intensity); material.SetFloat("_ReflectionBlur", settings.reflectionSettings.reflectionBlur); material.SetFloat("_MaxRayTraceDistance", settings.reflectionSettings.maxDistance); material.SetFloat("_FadeDistance", settings.intensitySettings.fadeDistance); material.SetFloat("_LayerThickness", settings.reflectionSettings.widthModifier); material.SetFloat("_SSRMultiplier", settings.intensitySettings.reflectionMultiplier); material.SetFloat("_FresnelFade", settings.intensitySettings.fresnelFade); material.SetFloat("_FresnelFadePower", settings.intensitySettings.fresnelFadePower); Matrix4x4 P = camera_.projectionMatrix; Vector4 projInfo = new Vector4 ((-2.0f / (sWidth * P[0])), (-2.0f / (sHeight * P[5])), ((1.0f - P[2]) / P[0]), ((1.0f + P[6]) / P[5])); Vector3 cameraClipInfo = (float.IsPositiveInfinity(camera_.farClipPlane)) ? new Vector3(camera_.nearClipPlane, -1.0f, 1.0f) : new Vector3(camera_.nearClipPlane * camera_.farClipPlane, camera_.nearClipPlane - camera_.farClipPlane, camera_.farClipPlane); material.SetVector("_ReflectionBufferSize", new Vector2(rtW, rtH)); material.SetVector("_ScreenSize", new Vector2(sWidth, sHeight)); material.SetVector("_InvScreenSize", new Vector2((float)(1.0f / sWidth), (float)(1.0f / sHeight))); material.SetVector("_ProjInfo", projInfo); // used for unprojection material.SetVector("_CameraClipInfo", cameraClipInfo); Matrix4x4 warpToScreenSpaceMatrix = new Matrix4x4(); warpToScreenSpaceMatrix.SetRow(0, new Vector4(sx, 0.0f, 0.0f, sx)); warpToScreenSpaceMatrix.SetRow(1, new Vector4(0.0f, sy, 0.0f, sy)); warpToScreenSpaceMatrix.SetRow(2, new Vector4(0.0f, 0.0f, 1.0f, 0.0f)); warpToScreenSpaceMatrix.SetRow(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); Matrix4x4 projectToPixelMatrix = warpToScreenSpaceMatrix * P; material.SetMatrix("_ProjectToPixelMatrix", projectToPixelMatrix); material.SetMatrix("_WorldToCameraMatrix", camera_.worldToCameraMatrix); material.SetMatrix("_CameraToWorldMatrix", camera_.worldToCameraMatrix.inverse); if (m_CommandBuffer == null) { m_CommandBuffer = new CommandBuffer(); m_CommandBuffer.name = "Screen Space Reflections"; // RGB: Normals, A: Roughness. // Has the nice benefit of allowing us to control the filtering mode as well. m_CommandBuffer.GetTemporaryRT(kNormalAndRoughnessTexture, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); m_CommandBuffer.GetTemporaryRT(kHitPointTexture, rtW, rtH, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); for (int i = 0; i < maxMip; ++i) { // We explicitly interpolate during bilateral upsampling. m_CommandBuffer.GetTemporaryRT(kReflectionTextures[i], rtW >> i, rtH >> i, 0, FilterMode.Bilinear, intermediateFormat); } m_CommandBuffer.GetTemporaryRT(kFilteredReflections, rtW, rtH, 0, bilateralUpsample ? FilterMode.Point : FilterMode.Bilinear, intermediateFormat); m_CommandBuffer.GetTemporaryRT(kFinalReflectionTexture, rtW, rtH, 0, FilterMode.Point, intermediateFormat); m_CommandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, kNormalAndRoughnessTexture, material, (int)PassIndex.BilateralKeyPack); m_CommandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, kHitPointTexture, material, (int)PassIndex.RayTraceStep); m_CommandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, kFilteredReflections, material, (int)PassIndex.HitPointToReflections); m_CommandBuffer.Blit(kFilteredReflections, kReflectionTextures[0], material, (int)PassIndex.PoissonBlur); for (int i = 1; i < maxMip; ++i) { int inputTex = kReflectionTextures[i - 1]; int lowMip = i; m_CommandBuffer.GetTemporaryRT(kBlurTexture, rtW >> lowMip, rtH >> lowMip, 0, FilterMode.Bilinear, intermediateFormat); m_CommandBuffer.SetGlobalVector("_Axis", new Vector4(1.0f, 0.0f, 0.0f, 0.0f)); m_CommandBuffer.SetGlobalFloat("_CurrentMipLevel", i - 1.0f); m_CommandBuffer.Blit(inputTex, kBlurTexture, material, (int)PassIndex.Blur); m_CommandBuffer.SetGlobalVector("_Axis", new Vector4(0.0f, 1.0f, 0.0f, 0.0f)); inputTex = kReflectionTextures[i]; m_CommandBuffer.Blit(kBlurTexture, inputTex, material, (int)PassIndex.Blur); m_CommandBuffer.ReleaseTemporaryRT(kBlurTexture); } m_CommandBuffer.Blit(kReflectionTextures[0], kFinalReflectionTexture, material, (int)PassIndex.CompositeSSR); m_CommandBuffer.GetTemporaryRT(kTempTexture, camera_.pixelWidth, camera_.pixelHeight, 0, FilterMode.Bilinear, intermediateFormat); m_CommandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, kTempTexture, material, (int)PassIndex.CompositeFinal); m_CommandBuffer.Blit(kTempTexture, BuiltinRenderTextureType.CameraTarget); m_CommandBuffer.ReleaseTemporaryRT(kTempTexture); camera_.AddCommandBuffer(CameraEvent.AfterFinalPass, m_CommandBuffer); } }
void OnPreRender() { m_material.SetInt("g_frame", Time.frameCount); m_material.SetInt("g_hdr", m_camera.hdr ? 1 : 0); m_material.SetInt("g_scene", m_scene); m_material.SetInt("g_enable_adaptive", m_enable_adaptive ? 1 : 0); m_material.SetInt("g_enable_temporal", m_enable_temporal ? 1 : 0); m_material.SetInt("g_enable_glowline", m_enable_glowline ? 1 : 0); RenderSettings.fogColor = m_fog_color; if (m_quad == null) { m_quad = RaymarcherUtils.GenerateQuad(); } if (m_detailed_quad == null) { m_detailed_quad = RaymarcherUtils.GenerateDetailedQuad(); } bool need_to_reflesh_command_buffer = false; Vector2 reso = new Vector2(m_camera.pixelWidth, m_camera.pixelHeight); if(m_resolution_prev!=reso) { m_resolution_prev = reso; need_to_reflesh_command_buffer = true; } if (m_enable_adaptive_prev != m_enable_adaptive) { m_enable_adaptive_prev = m_enable_adaptive; need_to_reflesh_command_buffer = true; } if (m_dbg_show_steps_prev != m_dbg_show_steps) { m_dbg_show_steps_prev = m_dbg_show_steps; need_to_reflesh_command_buffer = true; } if (need_to_reflesh_command_buffer) { need_to_reflesh_command_buffer = false; ClearCommandBuffer(); } if (m_cb_raymarch==null) { if (m_enable_adaptive) { RenderTargetIdentifier[] rt; m_cb_prepass = new CommandBuffer(); m_cb_prepass.name = "Raymarcher Adaptive PrePass"; int odepth = Shader.PropertyToID("ODepth"); int odepth_prev = Shader.PropertyToID("ODepthPrev"); int ovelocity = Shader.PropertyToID("OVelocity"); int qdepth = Shader.PropertyToID("QDepth"); int qdepth_prev = Shader.PropertyToID("QDepthPrev"); int hdepth = Shader.PropertyToID("HDepth"); int hdepth_prev = Shader.PropertyToID("HDepthPrev"); int adepth = Shader.PropertyToID("ADepth"); int adepth_prev = Shader.PropertyToID("ADepthPrev"); m_cb_prepass.GetTemporaryRT(odepth, m_camera.pixelWidth / 8, m_camera.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(odepth_prev,m_camera.pixelWidth / 8, m_camera.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(ovelocity, m_camera.pixelWidth / 8, m_camera.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RHalf); m_cb_prepass.GetTemporaryRT(qdepth, m_camera.pixelWidth / 4, m_camera.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(qdepth_prev,m_camera.pixelWidth / 4, m_camera.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth, m_camera.pixelWidth / 2, m_camera.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth_prev,m_camera.pixelWidth / 2, m_camera.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth, m_camera.pixelWidth / 1, m_camera.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth_prev,m_camera.pixelWidth / 1, m_camera.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); rt = new RenderTargetIdentifier[2] { odepth, ovelocity }; m_cb_prepass.SetGlobalTexture("g_depth_prev", odepth_prev); m_cb_prepass.SetRenderTarget(rt, odepth); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 1); m_cb_prepass.Blit(odepth, odepth_prev); m_cb_prepass.SetGlobalTexture("g_velocity", ovelocity); m_cb_prepass.SetRenderTarget(qdepth); m_cb_prepass.SetGlobalTexture("g_depth", odepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", qdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 2); m_cb_prepass.Blit(qdepth, qdepth_prev); m_cb_prepass.SetRenderTarget(hdepth); m_cb_prepass.SetGlobalTexture("g_depth", qdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", hdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 3); m_cb_prepass.Blit(hdepth, hdepth_prev); m_cb_prepass.SetRenderTarget(adepth); m_cb_prepass.SetGlobalTexture("g_depth", hdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", adepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 4); m_cb_prepass.Blit(adepth, adepth_prev); m_cb_prepass.SetGlobalTexture("g_depth", adepth); m_camera.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_prepass); } m_cb_raymarch = new CommandBuffer(); m_cb_raymarch.name = "Raymarcher"; m_cb_raymarch.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 0); m_camera.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_raymarch); } }
/// <summary> /// Return a new command buffer. /// This will be called the first time /// the mesh is rendered for each camera /// that renders the ocean. /// </summary> public override CommandBuffer Create(Camera cam) { CommandBuffer cmd = new CommandBuffer(); cmd.name = "Ceto DepthGrab Cmd: " + cam.name; //int width = cam.pixelWidth; //int height = cam.pixelHeight; //int scale = ResolutionToNumber(Resolution); //width /= scale; //height /= scale; RenderTextureFormat format; //screen grab currently disabled. /* if (cam.hdr) format = RenderTextureFormat.ARGBHalf; else format = RenderTextureFormat.ARGB32; //Copy screen into temporary RT. int grabID = Shader.PropertyToID("Ceto_GrabCopyTexture"); cmd.GetTemporaryRT(grabID, width, height, 0, FilterMode.Bilinear, format, RenderTextureReadWrite.Default); cmd.Blit(BuiltinRenderTextureType.CurrentActive, grabID); cmd.SetGlobalTexture(GrabName, grabID); */ if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RFloat)) format = RenderTextureFormat.RFloat; else format = RenderTextureFormat.RHalf; //Copy depths into temporary RT. int depthID = Shader.PropertyToID("Ceto_DepthCopyTexture"); cmd.GetTemporaryRT(depthID, cam.pixelWidth, cam.pixelHeight, 0, FilterMode.Point, format, RenderTextureReadWrite.Linear); cmd.Blit(BuiltinRenderTextureType.CurrentActive, depthID, m_copyDepthMat, 0); cmd.SetGlobalTexture(DepthName, depthID); cam.AddCommandBuffer(Event, cmd); CommandData data = new CommandData(); data.command = cmd; data.width = cam.pixelWidth; data.height = cam.pixelHeight; if (m_data.ContainsKey(cam)) m_data.Remove(cam); m_data.Add(cam, data); return cmd; }
void InitializeContext() { m_num_video_frames = 0; // initialize scratch buffer UpdateScratchBuffer(); // initialize context and stream { fcAPI.fcGifConfig conf; conf.width = m_scratch_buffer.width; conf.height = m_scratch_buffer.height; conf.num_colors = Mathf.Clamp(m_numColors, 1, 256); conf.max_active_tasks = 0; m_ctx = fcAPI.fcGifCreateContext(ref conf); } // initialize command buffer { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb = new CommandBuffer(); m_cb.name = "GifRecorder: copy frame buffer"; m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Bilinear); m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb.SetRenderTarget(m_scratch_buffer); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 0); m_cb.ReleaseTemporaryRT(tid); } }
void OnEnable() { System.IO.Directory.CreateDirectory(m_output_directory); m_cam = GetComponent<Camera>(); m_quad = FrameCapturerUtils.CreateFullscreenQuad(); m_mat_copy = new Material(m_sh_copy); if (m_cam.targetTexture != null) { m_mat_copy.EnableKeyword("OFFSCREEN"); } if (m_capture_framebuffer) { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb = new CommandBuffer(); m_cb.name = "ExrCapturer: copy frame buffer"; m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Point); m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid); // tid は意図的に開放しない m_cam.AddCommandBuffer(CameraEvent.AfterEverything, m_cb); m_frame_buffer = new RenderTexture(m_cam.pixelWidth, m_cam.pixelHeight, 0, RenderTextureFormat.ARGBHalf); m_frame_buffer.wrapMode = TextureWrapMode.Repeat; m_frame_buffer.Create(); } if (m_capture_gbuffer && m_cam.renderingPath != RenderingPath.DeferredShading && (m_cam.renderingPath == RenderingPath.UsePlayerSettings && PlayerSettings.renderingPath != RenderingPath.DeferredShading)) { Debug.Log("ExrCapturer: Rendering path must be deferred to use capture_gbuffer mode."); m_capture_gbuffer = false; } if(m_capture_gbuffer) { m_gbuffer = new RenderTexture[4]; m_rt_gbuffer = new RenderBuffer[4]; for (int i = 0; i < m_gbuffer.Length; ++i) { m_gbuffer[i] = new RenderTexture(m_cam.pixelWidth, m_cam.pixelHeight, 0, RenderTextureFormat.ARGBHalf); m_gbuffer[i].filterMode = FilterMode.Point; m_gbuffer[i].Create(); m_rt_gbuffer[i] = m_gbuffer[i].colorBuffer; } { RenderTextureFormat format = m_depth_format == DepthFormat.Half ? RenderTextureFormat.RHalf : RenderTextureFormat.RFloat; m_depth = new RenderTexture(m_cam.pixelWidth, m_cam.pixelHeight, 0, format); m_depth.filterMode = FilterMode.Point; m_depth.Create(); } } FrameCapturer.fcExrConfig conf; conf.max_active_tasks = m_max_active_tasks; m_exr = FrameCapturer.fcExrCreateContext(ref conf); }
void RenderReprojectionVectors( CommandBuffer commandBuffer, RenderTexture destination, float scale ) { commandBuffer.SetGlobalMatrix( "_AM_MATRIX_CURR_REPROJ", m_baseCamera.PrevViewProjMatrix * m_baseCamera.InvViewProjMatrix ); commandBuffer.SetGlobalFloat( "_AM_MOTION_SCALE", scale ); RenderTexture dummy = null; commandBuffer.Blit( new RenderTargetIdentifier( dummy ), destination, m_reprojectionMaterial ); }
void UpdateCommandBuffer() { var cam = GetComponent<Camera>(); RenderSettings.fogColor = m_fog_color; if (m_quad == null) { m_quad = RaymarcherUtils.GenerateQuad(); } bool reflesh_command_buffer = false; Vector2 reso = new Vector2(cam.pixelWidth, cam.pixelHeight); if(m_resolution_prev!=reso) { m_resolution_prev = reso; reflesh_command_buffer = true; } if (m_enable_adaptive_prev != m_enable_adaptive) { m_enable_adaptive_prev = m_enable_adaptive; reflesh_command_buffer = true; } if (m_dbg_show_steps_prev != m_dbg_show_steps) { m_dbg_show_steps_prev = m_dbg_show_steps; reflesh_command_buffer = true; } if (reflesh_command_buffer) { reflesh_command_buffer = false; ClearCommandBuffer(); } if (m_cb_raymarch==null) { if (m_enable_adaptive) { RenderTargetIdentifier[] rt; m_cb_prepass = new CommandBuffer(); m_cb_prepass.name = "Raymarcher Adaptive PrePass"; int odepth = Shader.PropertyToID("ODepth"); int odepth_prev = Shader.PropertyToID("ODepthPrev"); int ovelocity = Shader.PropertyToID("OVelocity"); int qdepth = Shader.PropertyToID("QDepth"); int qdepth_prev = Shader.PropertyToID("QDepthPrev"); int hdepth = Shader.PropertyToID("HDepth"); int hdepth_prev = Shader.PropertyToID("HDepthPrev"); int adepth = Shader.PropertyToID("ADepth"); int adepth_prev = Shader.PropertyToID("ADepthPrev"); m_cb_prepass.GetTemporaryRT(odepth, cam.pixelWidth / 8, cam.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(odepth_prev,cam.pixelWidth / 8, cam.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(ovelocity, cam.pixelWidth / 8, cam.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RHalf); m_cb_prepass.GetTemporaryRT(qdepth, cam.pixelWidth / 4, cam.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(qdepth_prev,cam.pixelWidth / 4, cam.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth, cam.pixelWidth / 2, cam.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth_prev,cam.pixelWidth / 2, cam.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth, cam.pixelWidth / 1, cam.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth_prev,cam.pixelWidth / 1, cam.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); rt = new RenderTargetIdentifier[2] { odepth, ovelocity }; m_cb_prepass.SetGlobalTexture("g_depth_prev", odepth_prev); m_cb_prepass.SetRenderTarget(rt, odepth); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 1); m_cb_prepass.Blit(odepth, odepth_prev); m_cb_prepass.SetGlobalTexture("g_velocity", ovelocity); m_cb_prepass.SetRenderTarget(qdepth); m_cb_prepass.SetGlobalTexture("g_depth", odepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", qdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 2); m_cb_prepass.Blit(qdepth, qdepth_prev); m_cb_prepass.SetRenderTarget(hdepth); m_cb_prepass.SetGlobalTexture("g_depth", qdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", hdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 3); m_cb_prepass.Blit(hdepth, hdepth_prev); m_cb_prepass.SetRenderTarget(adepth); m_cb_prepass.SetGlobalTexture("g_depth", hdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", adepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 4); m_cb_prepass.Blit(adepth, adepth_prev); m_cb_prepass.SetGlobalTexture("g_depth", adepth); cam.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_prepass); } m_cb_raymarch = new CommandBuffer(); m_cb_raymarch.name = "Raymarcher"; m_cb_raymarch.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 0); cam.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_raymarch); } }
public void Initialize() { if (combufPreLight == null) { int propsBufferID = Shader.PropertyToID("_UBERPropsBuffer"); // prepare material if (CopyPropsMat == null) { if (CopyPropsMat != null) { DestroyImmediate(CopyPropsMat); } CopyPropsMat = new Material(Shader.Find("Hidden/UBER_CopyPropsTexture")); CopyPropsMat.hideFlags = HideFlags.DontSave; } // take a copy of emission buffer.a where UBER stores its props (translucency, self-shadowing, wetness) combufPreLight = new CommandBuffer(); combufPreLight.name="UBERPropsPrelight"; combufPreLight.GetTemporaryRT(propsBufferID, -1, -1, 0, FilterMode.Point, RenderTextureFormat.RHalf); combufPreLight.Blit(BuiltinRenderTextureType.CameraTarget, propsBufferID, CopyPropsMat); // release temp buffer combufPostLight = new CommandBuffer(); combufPostLight.name="UBERPropsPostlight"; combufPostLight.ReleaseTemporaryRT (propsBufferID); } }
static public int Blit(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.RenderTargetIdentifier), typeof(UnityEngine.Rendering.RenderTargetIdentifier))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.RenderTargetIdentifier a1; checkValueType(l, 2, out a1); UnityEngine.Rendering.RenderTargetIdentifier a2; checkValueType(l, 3, out a2); self.Blit(a1, a2); return(0); } else if (matchType(l, argc, 2, typeof(UnityEngine.Texture), typeof(UnityEngine.Rendering.RenderTargetIdentifier))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Texture a1; checkType(l, 2, out a1); UnityEngine.Rendering.RenderTargetIdentifier a2; checkValueType(l, 3, out a2); self.Blit(a1, a2); return(0); } else if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.RenderTargetIdentifier), typeof(UnityEngine.Rendering.RenderTargetIdentifier), typeof(UnityEngine.Material))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.RenderTargetIdentifier a1; checkValueType(l, 2, out a1); UnityEngine.Rendering.RenderTargetIdentifier a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); self.Blit(a1, a2, a3); return(0); } else if (matchType(l, argc, 2, typeof(UnityEngine.Texture), typeof(UnityEngine.Rendering.RenderTargetIdentifier), typeof(UnityEngine.Material))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Texture a1; checkType(l, 2, out a1); UnityEngine.Rendering.RenderTargetIdentifier a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); self.Blit(a1, a2, a3); return(0); } else if (matchType(l, argc, 2, typeof(UnityEngine.Rendering.RenderTargetIdentifier), typeof(UnityEngine.Rendering.RenderTargetIdentifier), typeof(UnityEngine.Material), typeof(int))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Rendering.RenderTargetIdentifier a1; checkValueType(l, 2, out a1); UnityEngine.Rendering.RenderTargetIdentifier a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.Blit(a1, a2, a3, a4); return(0); } else if (matchType(l, argc, 2, typeof(UnityEngine.Texture), typeof(UnityEngine.Rendering.RenderTargetIdentifier), typeof(UnityEngine.Material), typeof(int))) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Texture a1; checkType(l, 2, out a1); UnityEngine.Rendering.RenderTargetIdentifier a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.Blit(a1, a2, a3, a4); return(0); } LuaDLL.luaL_error(l, "No matched override function to call"); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
private void InitializeBuffers() { m_isScatteringEnabled = SkinSettings.Enabled; m_isTransmissionEnabled = TransmissionSettings.Enabled || m_isScatteringEnabled; if (SkinSettings.Lut == null) { SkinSettings.Lut = SkinLut; #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif } if ((m_isTransmissionEnabled || m_isScatteringEnabled) && m_camera != null && DeferredTransmissionBlit != null && m_copyTransmission == null && m_releaseDeferredPlus == null) { int opacityBufferId = Shader.PropertyToID("_DeferredTransmissionBuffer"); int blurredNormalsBufferIdTemp = Shader.PropertyToID("_DeferredBlurredNormalBufferTemp"); int blurredNormalBuffer = Shader.PropertyToID("_DeferredBlurredNormalBuffer"); m_deferredTransmissionBlitMaterial = new Material(DeferredTransmissionBlit); m_deferredTransmissionBlitMaterial.hideFlags = HideFlags.HideAndDontSave; // Copy Gbuffer emission buffer so we can get at the alpha channel for transmission. m_copyTransmission = new CommandBuffer(); m_copyTransmission.name = c_copyTransmissionBufferName; m_copyTransmission.GetTemporaryRT(opacityBufferId, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32); m_copyTransmission.Blit(BuiltinRenderTextureType.CameraTarget, opacityBufferId, m_deferredTransmissionBlitMaterial); // Blurred normals for skin if (m_isScatteringEnabled) { GenerateNormalBlurMaterialAndCommandBuffer(blurredNormalBuffer, blurredNormalsBufferIdTemp, out m_deferredBlurredNormalsMaterial, out m_renderBlurredNormals); #if UNITY_EDITOR GenerateNormalBlurMaterialAndCommandBuffer(blurredNormalBuffer, blurredNormalsBufferIdTemp, out m_sceneViewBlurredNormalsMaterial, out m_sceneViewBlurredNormals); #endif } // Cleanup resources. m_releaseDeferredPlus = new CommandBuffer(); m_releaseDeferredPlus.name = c_releaseDeferredBuffer; m_releaseDeferredPlus.ReleaseTemporaryRT(opacityBufferId); if (m_isScatteringEnabled) { m_releaseDeferredPlus.ReleaseTemporaryRT(blurredNormalsBufferIdTemp); } #if UNITY_EDITOR SceneView.onSceneGUIDelegate += OnSceneGUIDelegate; #endif } AddCommandBuffersToCamera(m_camera, m_renderBlurredNormals); #if UNITY_EDITOR EditorUtility.SetDirty(m_camera); #endif }
/// <summary> /// Create a command buffer that renders the AR screen full screen at the right time. /// </summary> /// <returns>The AR screen command buffer.</returns> public static CommandBuffer CreateARScreenCommandBuffer() { CommandBuffer buf = new CommandBuffer(); #if UNITY_EDITOR _InternResourcesForEmulation(); buf.Blit((Texture)m_emulatedARScreenTexture, BuiltinRenderTextureType.CurrentActive, m_emulationArScreenMaterial); #else IntPtr func = API.TangoUnity_getRenderTextureFunction(); buf.IssuePluginEvent(func, 0); #endif return buf; }
private void GenerateNormalBlurMaterialAndCommandBuffer(int blurredNormalBuffer, int blurredNormalsBufferIdTemp, out Material blurMaterial, out CommandBuffer blurCommandBuffer) { blurMaterial = new Material(DeferredBlurredNormals); blurMaterial.hideFlags = HideFlags.HideAndDontSave; blurCommandBuffer = new CommandBuffer(); blurCommandBuffer.name = c_normalBufferName; blurCommandBuffer.GetTemporaryRT(blurredNormalsBufferIdTemp, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB2101010); blurCommandBuffer.GetTemporaryRT(blurredNormalBuffer, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB2101010); blurCommandBuffer.Blit(BuiltinRenderTextureType.GBuffer2, blurredNormalsBufferIdTemp, blurMaterial, 0); blurCommandBuffer.Blit(blurredNormalsBufferIdTemp, blurredNormalBuffer, blurMaterial, 1); blurCommandBuffer.Blit(blurredNormalBuffer, blurredNormalsBufferIdTemp, blurMaterial, 0); blurCommandBuffer.Blit(blurredNormalsBufferIdTemp, blurredNormalBuffer, blurMaterial, 1); }