当前位置: 首页>>代码示例>>C#>>正文


C# CommandBuffer.SetGlobalTexture方法代码示例

本文整理汇总了C#中UnityEngine.Rendering.CommandBuffer.SetGlobalTexture方法的典型用法代码示例。如果您正苦于以下问题:C# CommandBuffer.SetGlobalTexture方法的具体用法?C# CommandBuffer.SetGlobalTexture怎么用?C# CommandBuffer.SetGlobalTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Rendering.CommandBuffer的用法示例。


在下文中一共展示了CommandBuffer.SetGlobalTexture方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnWillRenderObject

	// 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);
	}
开发者ID:rbrt,项目名称:Animations,代码行数:61,代码来源:CommandBufferBlurRefraction.cs

示例2: OnEnable

        void OnEnable()
        {
            m_outputDir.CreateDirectory();
            m_quad = FrameCapturerUtils.CreateFullscreenQuad();
            m_mat_copy = new Material(m_shCopy);

            // initialize exr context
            fcAPI.fcExrConfig conf = fcAPI.fcExrConfig.default_value;
            m_ctx = fcAPI.fcExrCreateContext(ref conf);

            // initialize render targets
            m_scratch_buffers = new RenderTexture[m_targets.Length];
            for (int i = 0; i < m_scratch_buffers.Length; ++i)
            {
                var rt = m_targets[i];
                m_scratch_buffers[i] = new RenderTexture(rt.width, rt.height, 0, rt.format);
                m_scratch_buffers[i].Create();
            }

            // initialize command buffers
            {
                m_cb_copy = new CommandBuffer();
                m_cb_copy.name = "PngOffscreenRecorder: Copy";
                for (int i = 0; i < m_targets.Length; ++i)
                {
                    m_cb_copy.SetRenderTarget(m_scratch_buffers[i]);
                    m_cb_copy.SetGlobalTexture("_TmpRenderTarget", m_targets[i]);
                    m_cb_copy.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 3);
                }
            }
        }
开发者ID:ClintChil,项目名称:FrameCapturer,代码行数:31,代码来源:ExrOffscreenRecorder.cs

示例3: UpdateCommandBuffer

    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();
//.........这里部分代码省略.........
开发者ID:stlck,项目名称:FractalTest,代码行数:101,代码来源:Raymarcher.cs

示例4: OnWillRenderObject

    // 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
//.........这里部分代码省略.........
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:101,代码来源:PaintRenderMain01.cs

示例5: EnsureHookedLightSource

	void EnsureHookedLightSource(Light light) {
		if(!light)
			return;

		if(light.commandBufferCount == 2)
			return;

		//Debug.Log("Hooking scattering command buffers on light source: " + light.name);

		// NOTE: This doesn't really play nicely with other users of light events.
		//       Currently not an issue since this code was written pre-5.1 (and light events
		//       are a new feature in 5.1), but might need a proper solution in the future.
		light.RemoveAllCommandBuffers();

		if(m_occlusionCmdAfterShadows != null)
			m_occlusionCmdAfterShadows.Dispose();
		if(m_occlusionCmdBeforeScreen != null)
			m_occlusionCmdBeforeScreen.Dispose();

		m_occlusionCmdAfterShadows = new UnityEngine.Rendering.CommandBuffer();
		m_occlusionCmdAfterShadows.name = "Scatter Occlusion Pass 1";
		m_occlusionCmdAfterShadows.SetGlobalTexture("u_CascadedShadowMap", new UnityEngine.Rendering.RenderTargetIdentifier(UnityEngine.Rendering.BuiltinRenderTextureType.CurrentActive));
		m_occlusionCmdBeforeScreen = new UnityEngine.Rendering.CommandBuffer();
		m_occlusionCmdBeforeScreen.name = "Scatter Occlusion Pass 2";

		light.AddCommandBuffer(UnityEngine.Rendering.LightEvent.AfterShadowMap, m_occlusionCmdAfterShadows);
		light.AddCommandBuffer(UnityEngine.Rendering.LightEvent.BeforeScreenspaceMask, m_occlusionCmdBeforeScreen);
	}
开发者ID:markdion,项目名称:Unity-Projects,代码行数:28,代码来源:AtmosphericScattering.cs

示例6: InitializeContext

        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
            {
                m_cb = new CommandBuffer();
                m_cb.name = "GifOffscreenRecorder: copy frame buffer";
                m_cb.SetRenderTarget(m_scratch_buffer);
                m_cb.SetGlobalTexture("_TmpRenderTarget", m_target);
                m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 3);
            }
        }
开发者ID:ClintChil,项目名称:FrameCapturer,代码行数:26,代码来源:GifOffscreenRecorder.cs

示例7: OnPreRender

    public void OnPreRender()
    {
        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 (!DepthMaterial)
        {
            DepthMaterial = new Material(DepthShader);
            DepthMaterial.hideFlags = HideFlags.HideAndDontSave;
        }

        buf = new CommandBuffer();
        buf.name = "Render Grass Depth Reference";
        m_Cameras[cam] = buf;

        int referenceDepthID = Shader.PropertyToID("_rdepth");
        buf.GetTemporaryRT(referenceDepthID, -1, -1, 24, FilterMode.Point, RenderTextureFormat.Depth);
        buf.SetRenderTarget(new RenderTargetIdentifier(referenceDepthID));
        buf.ClearRenderTarget(true, false, Color.white, 1);

        foreach (MeshRenderer r in GrassMeshes)
            buf.DrawRenderer(r, DepthMaterial);

        buf.SetRenderTarget(new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget));

        buf.SetGlobalTexture("_ReferenceDepth", referenceDepthID);

        cam.AddCommandBuffer(CameraEvent.BeforeImageEffects, buf);
        Debug.Log("Add Command Buffer");
    }
开发者ID:Flafla2,项目名称:Screen-Space-Grass,代码行数:43,代码来源:GrassManager.cs

示例8: RenderVectors

	internal override void RenderVectors( Camera camera, CommandBuffer renderCB, float scale, AmplifyMotion.Quality quality )
	{
		if ( m_initialized && !m_error && m_renderer.isVisible )
		{
			Profiler.BeginSample( "Skinned.Update" );

			if ( !m_useFallback )
			{
				if ( !m_useGPU )
					WaitForAsyncUpdate();
			}

			Profiler.EndSample();

			Profiler.BeginSample( "Skinned.Render" );
			if ( !m_useGPU )
			{
				if ( !m_useFallback )
					m_clonedMesh.vertices = m_currVertices;
				m_clonedMesh.normals = m_prevVertices;
			}

			const float rcp255 = 1 / 255.0f;
			bool mask = ( m_owner.Instance.CullingMask & ( 1 << m_obj.gameObject.layer ) ) != 0;
			int objectId = mask ? m_owner.Instance.GenerateObjectId( m_obj.gameObject ) : 255;

			Matrix4x4 prevModelViewProj;
			if ( m_obj.FixedStep )
				prevModelViewProj = m_owner.PrevViewProjMatrixRT * m_currLocalToWorld;
			else
				prevModelViewProj = m_owner.PrevViewProjMatrixRT * m_prevLocalToWorld;

			renderCB.SetGlobalMatrix( "_AM_MATRIX_PREV_MVP", prevModelViewProj );
			renderCB.SetGlobalFloat( "_AM_OBJECT_ID", objectId * rcp255 );
			renderCB.SetGlobalFloat( "_AM_MOTION_SCALE", mask ? scale : 0 );

			if ( m_useGPU )
			{
			#if !UNITY_4
				Vector4 vertexTexelSize = new Vector4( 1.0f / m_gpuVertexTexWidth, 1.0f / m_gpuVertexTexHeight, m_gpuVertexTexWidth, m_gpuVertexTexHeight );

				renderCB.SetGlobalVector( "_AM_VERTEX_TEXEL_SIZE", vertexTexelSize );
				renderCB.SetGlobalVector( "_AM_VERTEX_TEXEL_HALFSIZE", vertexTexelSize * 0.5f );

				renderCB.SetGlobalTexture( "_AM_PREV_VERTEX_TEX", m_gpuPrevVertices );
				renderCB.SetGlobalTexture( "_AM_CURR_VERTEX_TEX", m_gpuCurrVertices );
			#endif
			}

			int hardwarePass = m_useGPU ? 4 : 0;
			int qualityPass = ( quality == AmplifyMotion.Quality.Mobile ) ? 0 : 2;
			int basePass = hardwarePass + qualityPass;

			for ( int i = 0; i < m_sharedMaterials.Length; i++ )
			{
				MaterialDesc matDesc = m_sharedMaterials[ i ];
				int pass = basePass + ( matDesc.coverage ? 1 : 0 );

				if ( matDesc.coverage )
				{
					Texture mainTex = matDesc.material.mainTexture;
					if ( mainTex != null )
						matDesc.propertyBlock.SetTexture( "_MainTex", mainTex );
					if ( matDesc.cutoff )
						matDesc.propertyBlock.SetFloat( "_Cutoff", matDesc.material.GetFloat( "_Cutoff" ) );
				}

				renderCB.DrawMesh( m_clonedMesh, m_currLocalToWorld, m_owner.Instance.SkinnedVectorsMaterial, i, pass, matDesc.propertyBlock );
			}

			Profiler.EndSample();
		}
	}
开发者ID:mirrorfishmedia,项目名称:GGJ2016,代码行数:73,代码来源:SkinnedState.cs

示例9: OnPreRender

    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);
//.........这里部分代码省略.........
开发者ID:ClintChil,项目名称:FrameCapturer,代码行数:101,代码来源:Raymarcher.cs

示例10: Start

    /// <summary>
    /// 
    /// </summary>
    void Start()
    {
        _commandBuffer = new CommandBuffer();
        _commandBuffer.name = "Light Command Buffer";

        _cascadeShadowCommandBuffer = new CommandBuffer();
        _cascadeShadowCommandBuffer.name = "Dir Light Command Buffer";
        _cascadeShadowCommandBuffer.SetGlobalTexture("_CascadeShadowMapTexture", new UnityEngine.Rendering.RenderTargetIdentifier(UnityEngine.Rendering.BuiltinRenderTextureType.CurrentActive));

        _light = GetComponent<Light>();
        _light.RemoveAllCommandBuffers();
        if(_light.type == LightType.Directional)
        {
            _light.AddCommandBuffer(LightEvent.BeforeScreenspaceMask, _commandBuffer);
            _light.AddCommandBuffer(LightEvent.AfterShadowMap, _cascadeShadowCommandBuffer);

        }
        else
            _light.AddCommandBuffer(LightEvent.AfterShadowMap, _commandBuffer);

        _material = new Material(Shader.Find("Sandbox/VolumetricLight")); // new Material(VolumetricLightRenderer.GetLightMaterial());
    }
开发者ID:FranciscoAlonso,项目名称:VolumetricLights,代码行数:25,代码来源:VolumetricLight.cs

示例11: Create

        /// <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;
        }
开发者ID:BenjaminLovegrove,项目名称:ATR,代码行数:60,代码来源:RefractionCommand.cs

示例12: InitializeContext

        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
            {
                m_cb = new CommandBuffer();
                m_cb.name = "MP4OffscreenRecorder: copy frame buffer";
                m_cb.SetRenderTarget(m_scratch_buffer);
                m_cb.SetGlobalTexture("_TmpRenderTarget", m_target);
                m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 3);
            }
        }
开发者ID:ClintChil,项目名称:FrameCapturer,代码行数:35,代码来源:MP4OffscreenRecorder.cs


注:本文中的UnityEngine.Rendering.CommandBuffer.SetGlobalTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。