• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# RenderTexture类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中RenderTexture的典型用法代码示例。如果您正苦于以下问题:C# RenderTexture类的具体用法?C# RenderTexture怎么用?C# RenderTexture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RenderTexture类属于命名空间,在下文中一共展示了RenderTexture类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Terrain

 public Terrain(Device device, String texture, int pitch, Renderer renderer)
 {
     HeightMap = new System.Drawing.Bitmap(@"Data/Textures/"+texture);
     WaterShader = new WaterShader(device);
     TerrainShader = new TerrainShader(device);
     _width = HeightMap.Width-1;
     _height = HeightMap.Height-1;
     _pitch = pitch;
     _terrainTextures = new ShaderResourceView[4];
     _terrainTextures[0] = new Texture(device, "Sand.png").TextureResource;
     _terrainTextures[1] = new Texture(device, "Grass.png").TextureResource;
     _terrainTextures[2] = new Texture(device, "Ground.png").TextureResource;
     _terrainTextures[3] = new Texture(device, "Rock.png").TextureResource;
     _reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
     _refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f);
     _noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000);
     _reflectionTexture = new RenderTexture(device, renderer.ScreenSize);
     _refractionTexture = new RenderTexture(device, renderer.ScreenSize);
     _renderer = renderer;
     _bitmap = new Bitmap(device,_refractionTexture.ShaderResourceView,renderer.ScreenSize, new Vector2I(100, 100), 0);
     _bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0);
     _bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0);
     _bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120);
     _bumpMap = _renderer.TextureManager.Create("OceanWater.png");
     _skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png"));
     BuildBuffers(device);
     WaveTranslation = new Vector2(0,0);
 }
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:28,代码来源:Terrain.cs


示例2: OnRenderImage

	protected virtual void OnRenderImage(RenderTexture source, RenderTexture destination)
	{
		material.SetVector("_RedClamp", red);
		material.SetVector("_GreenClamp", green);
		material.SetVector("_BlueClamp", blue);
		Graphics.Blit(source, destination, material);
	}
开发者ID:Fromfame,项目名称:RED,代码行数:7,代码来源:CC_ChannelClamper.cs


示例3: OnRenderImage

    void OnRenderImage( RenderTexture source ,   RenderTexture destination  )
    {
        #if UNITY_EDITOR
        FindShaders ();
        CheckSupport ();
        CreateMaterials ();
        #endif

        agonyTint = Mathf.Clamp01 (agonyTint - Time.deltaTime * 2.75f);

        RenderTexture tempRtLowA = RenderTexture.GetTemporary (source.width / 4, source.height / 4,0, rtFormat);
        RenderTexture tempRtLowB = RenderTexture.GetTemporary (source.width / 4, source.height / 4, 0,rtFormat);

        // prepare data

        apply.SetColor ("_ColorMix", colorMix);
        apply.SetVector ("_Parameter",new Vector4 (colorMixBlend * 0.25f,  0.0f, 0.0f, 1.0f - intensity - agonyTint));

        // downsample & blur

        Graphics.Blit (source, tempRtLowA, apply, agonyTint < 0.5f ? 1 : 5);
        Graphics.Blit (tempRtLowA, tempRtLowB, apply, 2);
        Graphics.Blit (tempRtLowB, tempRtLowA, apply, 3);

        // apply

        apply.SetTexture ("_Bloom", tempRtLowA);
        Graphics.Blit (source, destination, apply, QualityManager.quality > Quality.Medium ? 4 : 0);

        RenderTexture.ReleaseTemporary (tempRtLowA);
        RenderTexture.ReleaseTemporary (tempRtLowB);
    }
开发者ID:cn00,项目名称:U3D5_CSharp_AngryBots,代码行数:32,代码来源:MobileBloom.cs


示例4: LateUpdate

 void LateUpdate()
 {
     if(_isActive != isActive)
     {
         _isActive = isActive;
         if(isActive)
         {
             depthTexture = new RenderTexture(TextureSize,TextureSize, 16, RenderTextureFormat.ARGB32);
             depthTexture.filterMode = FilterMode.Point;
         }else
         {
             RenderTexture.DestroyImmediate(depthTexture);
         }
     }
     if(isActive)
     {
         depthCamera.cullingMask = casterLayer;
         depthCamera.orthographicSize = Size;
         depthCamera.farClipPlane = Far;
         depthCamera.Render();
         Matrix4x4 depthProjectionMatrix = depthCamera.projectionMatrix;
         Matrix4x4 depthViewMatrix = depthCamera.worldToCameraMatrix;
         Matrix4x4 depthVP = depthProjectionMatrix * depthViewMatrix ;
         Matrix4x4 depthVPBias = biasMatrix * depthVP;
         Shader.SetGlobalMatrix("_depthVPBias", depthVPBias);
         Shader.SetGlobalMatrix("_depthV", depthViewMatrix);
         Shader.SetGlobalTexture("_kkShadowMap", depthCamera.targetTexture);
         Shader.SetGlobalFloat("_bias", Bias);
         Shader.SetGlobalFloat("_strength", 1 - Strength);
         Shader.SetGlobalFloat("_texmapScale", 1f/TextureSize);
         Shader.SetGlobalFloat("_farplaneScale", 1/Far);
     }
 }
开发者ID:kokichi88,项目名称:shadowmapping,代码行数:33,代码来源:GenerateDepthTexture2.cs


示例5: Create

 // Make a material that points to the target texture.  Texture scale
 // and offset will be controlled by rect.
 public void Create(RenderTexture target) {
   meshRenderer.material = new Material(Shader.Find("Cardboard/GUIScreen")) {
     mainTexture = target,
     mainTextureOffset = rect.position,
     mainTextureScale = rect.size
   };
 }
开发者ID:CaminhoneiroHell,项目名称:demo_cardboard,代码行数:9,代码来源:CardboardOnGUIWindow.cs


示例6: OnRenderImage

    void OnRenderImage (RenderTexture source, RenderTexture destination)
	{
		if (CheckResources()==false)
		{
            Graphics.Blit (source, destination);
            return;
        }

		int rtW = source.width >> downsample;
		int rtH = source.height >> downsample;

		// downsample
		RenderTexture rt = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);

		rt.filterMode = FilterMode.Bilinear;

		Graphics.Blit (source, rt, material, 0);

		Debug.Log("MSKFNAN");

		if (!winner) {
			material.SetVector("iResolution",new Vector4(Screen.width,Screen.height,0,0));
			material.SetFloat("distFromOrigin", DistFromOrigin );
			material.SetVector("buddyPos",BuddyBoy.transform.position);
			material.SetFloat("distFromPath", DistFromPath );
			material.SetVector("camForward",BuddyBoy.transform.forward);
			material.SetVector("camRight",BuddyBoy.transform.right);
			material.SetVector("camUp",BuddyBoy.transform.up);
		}

		Graphics.Blit (rt, destination);
		RenderTexture.ReleaseTemporary (rt);
    }
开发者ID:rbrt,项目名称:GGJ16,代码行数:33,代码来源:ShaderToy.cs


示例7: OnRenderImage

	void OnRenderImage (RenderTexture source, RenderTexture destination){

		Graphics.Blit(source,destination,mat);
		//mat is the material which contains the shader
		//we are passing the destination RenderTexture to


		int width = Screen.width;
		int height = Screen.height;

		Debug.Log (width.ToString ());
		Debug.Log (height.ToString ());

		Texture2D tex = new Texture2D(width, height);
		tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);


		if (flag == true) {
			string[] blue = new string[width * height];

			for (int i = 0; i < height; i++) {
				for (int j=0; j < width; j++) {
					blue[(i * width) + j]  = tex.GetPixel (j, i).b.ToString ();
				}
			}
			string output = string.Join(",", blue);
			File.WriteAllText ("/Users/mettinger/Desktop/temp/output.txt", output);
			flag = false;
		}
		Debug.Log (tex.GetPixel(x,y).b.ToString());
	
	}
开发者ID:mettinger,项目名称:unity,代码行数:32,代码来源:PostProcessDepthGrayscale.cs


示例8: OnRenderImage

 // Called by camera to apply image effect
 void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     base.material.SetFloat("_Intense1", intense1);
     base.material.SetFloat("_Intense2", intense2);
     base.material.SetFloat("_Count", count);
     Graphics.Blit (source, destination, material);
 }
开发者ID:lightnarcissus,项目名称:Hashtagger,代码行数:8,代码来源:PP_Scanlines.cs


示例9: OnRenderImage

    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (_material == null) {
            _material = new Material(_shader);
            _material.hideFlags = HideFlags.DontSave;
        }

        if (_noise > 0.01f || _invert > 0.01f || _whiteout > 0.01f)
        {
            if (_noise > 0.01f)
            {
                _material.EnableKeyword("NOISE_ON");
                _material.SetFloat("_NoiseThreshold", Mathf.Clamp01(1.0f - _noise * 1.2f));
                _material.SetFloat("_NoiseDisplace", 0.01f + Mathf.Pow(_noise, 3) * 0.1f);
            }
            else
            {
                _material.DisableKeyword("NOISE_ON");
            }

            _material.SetFloat("_Invert", _invert);
            _material.SetFloat("_Whiteout", _whiteout);

            Graphics.Blit(source, destination, _material);
        }
        else
        {
            Graphics.Blit(source, destination);
        }
    }
开发者ID:Garridus,项目名称:VJ04,代码行数:30,代码来源:VJ04Vfx.cs


示例10: CreateTextures

    public void CreateTextures()
    {
        if (texW == 0) texW = 1;//TODO rm
        if (texH == 0) texH = 1;
        if (texW == 0) throw new System.Exception("texW must be > 0");
        if (texH == 0) throw new System.Exception("texH must be > 0");
        texelSize = new Vector2(1f / texW, 1f / texH);
        maxTexelDistance = texelSize.magnitude;

        //Create textures
        texCur = new RenderTexture(texW, texH, 0, RenderTextureFormat.RFloat);
        texCur.enableRandomWrite = true;
        texCur.generateMips = false;
        texCur.Create();
        texDest = new RenderTexture(texW, texH, 0, RenderTextureFormat.RFloat);
        texDest.enableRandomWrite = true;
        texDest.generateMips = false;
        texCur.filterMode = FilterMode.Point;
        texDest.Create();

        //Clear textures
        Graphics.SetRenderTarget(texCur);
        GL.Clear(true, true, Color.white);
        Graphics.SetRenderTarget(texDest);
        GL.Clear(true, true, Color.white);
        Graphics.SetRenderTarget(null);

        //Instantiate material
        renderMaterial = new Material(visibilityOverlayMaterial);
        renderMaterial.SetTexture("_Mask", texCur);
    }
开发者ID:XZelnar,项目名称:PlanetoidMapGen,代码行数:31,代码来源:MapChunkVisibilityOverlay.cs


示例11: ComputeFocusScores

    public static void ComputeFocusScores(RenderTexture instanceIdBuffer, RenderTexture depthBuffer)
    {
        //ComputeShaderManager.Get.ComputeColorInfo.SetBuffer(3, "_ClearBuffer", GPUBuffers.Get.ProteinFocusScore);
        //ComputeShaderManager.Get.ComputeColorInfo.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);

        ComputeShaderManager.Get.ComputeColorInfo.SetBuffer(3, "_ClearBuffer", GPUBuffers.Get.ProteinFocusScore);
        ComputeShaderManager.Get.ComputeColorInfo.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);
        

        //*************************************************//

        GPUBuffers.Get.IngredientsColorInfo.SetData(CPUBuffers.Get.IngredientsDisplayInfo.ToArray());
        GPUBuffers.Get.IngredientGroupsColorInfo.SetData(CPUBuffers.Get.IngredientGroupsDisplayInfo.ToArray());

        ComputeShaderManager.Get.ComputeColorInfo.SetInt("_Width", instanceIdBuffer.width);
        ComputeShaderManager.Get.ComputeColorInfo.SetInt("_Height", instanceIdBuffer.height);


        ComputeShaderManager.Get.ComputeColorInfo.SetTexture(4, "_DepthBuffer", depthBuffer);
        ComputeShaderManager.Get.ComputeColorInfo.SetTexture(4, "_InstanceIdBuffer", instanceIdBuffer);

        //ComputeShaderManager.Get.ComputeColorInfo.SetBuffer(4, "_IngredientsInfo", GPUBuffers.Get.IngredientsInfo);
        //ComputeShaderManager.Get.ComputeColorInfo.SetBuffer(4, "_LipidInstancesInfo", GPUBuffers.Get.LipidInstancesInfo);
        ComputeShaderManager.Get.ComputeColorInfo.SetBuffer(4, "_ProteinInstancesInfo", GPUBuffers.Get.ProteinInstancesInfo);
        ComputeShaderManager.Get.ComputeColorInfo.SetBuffer(4, "_RWProteinFocusScore", GPUBuffers.Get.IngredientsColorInfo);

        ComputeShaderManager.Get.ComputeColorInfo.Dispatch(4, Mathf.CeilToInt(instanceIdBuffer.width / 8.0f), Mathf.CeilToInt(instanceIdBuffer.height / 8.0f), 1);
    }
开发者ID:matmuze,项目名称:cellVIEW_color,代码行数:28,代码来源:ColorCompositeUtils.cs


示例12: OnRenderImage

    // Called by camera to apply image effect
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        material.SetFloat("_PixelWidth", pixelWidth);
        material.SetFloat("_PixelHeight", pixelHeight);

        Graphics.Blit (source, destination, material, 0);
    }
开发者ID:vorrin,项目名称:samurai,代码行数:8,代码来源:Pixelated.cs


示例13: Start

    // Use this for initialization
    void Start()
    {
        //eyeDistance_s = S3DVM.eyeDistance;
        //focalDistance_s = S3DVM.focalDistance;

        camera = GetComponent<Camera>();

        //leftEye = new GameObject ("leftEye");
        //rightEye = new GameObject ("rightEye");

        //leftEye.AddComponent<Camera>();
        //rightEye.AddComponent<Camera>();

        //leftEye.GetComponent<Camera>().CopyFrom (camera);
        //rightEye.GetComponent<Camera>().CopyFrom (camera);

        FrontRT = new RenderTexture ((int)(Screen.width*textureResolution), (int)(Screen.height*textureResolution), 24);
        BackRT = new RenderTexture ((int)(Screen.width*textureResolution), (int)(Screen.height*textureResolution), 24);

        FrontCam.GetComponent<Camera>().targetTexture = FrontRT;
        BackCam.GetComponent<Camera>().targetTexture = BackRT;

        MergedCameras.SetTexture ("_FrontTex", FrontRT);
        MergedCameras.SetTexture ("_BackTex", BackRT);
    }
开发者ID:merlinsaw,项目名称:diplom,代码行数:26,代码来源:CameraMapping.cs


示例14: CaptureCamera

    /// <summary>
    /// 对相机截图。 
    /// </summary>
    /// <returns>The screenshot2.</returns>
    /// <param name="camera">Camera.要被截屏的相机</param>
    /// <param name="rect">Rect.截屏的区域</param>
    Texture2D CaptureCamera(Camera camera, Rect rect)
    {
        // 创建一个RenderTexture对象
        Debug.Log(rect.width + " " + rect.height);
        RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
        // 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
        camera.targetTexture = rt;
        camera.Render();
        //--- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
        //camera2.targetTexture = rt;
        //camera2.Render();
        //-------------------------------------------------------------------
        // 激活这个rt, 并从中中读取像素。
        RenderTexture.active = rt;
        Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
        screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
        screenShot.Apply();

        // 重置相关参数,以使用camera继续在屏幕上显示
        camera.targetTexture = null;
        //ps: camera2.targetTexture = null;
        RenderTexture.active = null; // JC: added to avoid errors
        GameObject.Destroy(rt);
        CacheFactory.SaveToPicture(screenShot, "/ScreenShot.png",CacheFactory.PictureType.JPG);
        return screenShot;
    }
开发者ID:xiaozhuzhaoge,项目名称:QinCloudSuper,代码行数:32,代码来源:Screenshot.cs


示例15: Render4TapQuad

    // =============================================================================
    // =============================================================================
    // METHODS STATIC --------------------------------------------------------------
    private static void Render4TapQuad( RenderTexture dest, float offsetX, float offsetY )
    {
        GL.Begin( GL.QUADS );

        // Direct3D needs interesting texel offsets!
        Vector2 off = Vector2.zero;
        if( dest != null )
        {
            off = dest.GetTexelOffset()*0.75f;
        }

        Set4TexCoords( off.x, off.y, offsetX, offsetY );
        GL.Vertex3( 0f, 0f, 0.1f );

        Set4TexCoords( 1.0f + off.x, off.y, offsetX, offsetY );
        GL.Vertex3( 1f, 0f, 0.1f );

        Set4TexCoords( 1.0f + off.x, 1.0f + off.y, offsetX, offsetY );
        GL.Vertex3( 1f, 1f, 0.1f );

        Set4TexCoords( off.x, 1.0f + off.y, offsetX, offsetY );
        GL.Vertex3( 0f, 1f, 0.1f );

        GL.End();
    }
开发者ID:Jonas90,项目名称:iss,代码行数:28,代码来源:FunkyGlowingThingsEffect.cs


示例16: Bake

    public Material Bake()
    {
        Camera camera = transform.FindChild("Camera").camera;
        RenderTexture render_texture = new RenderTexture(256, 256, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default);
        render_texture.useMipMap = true;
        render_texture.filterMode = FilterMode.Trilinear;
        render_texture.mipMapBias = -0.5f;
        camera.targetTexture = render_texture;

        transform.FindChild("Title").gameObject.layer = LayerMask.NameToLayer("Active Card Render Texture");
        transform.FindChild("Rules").gameObject.layer = LayerMask.NameToLayer("Active Card Render Texture");

        Transform tile_mesh = transform.FindChild("Tile_base").FindChild("default");
        Material material = new Material(tile_mesh.renderer.material);
        material.mainTexture = render_texture;

        camera.Render();

        transform.FindChild("Title").gameObject.layer = LayerMask.NameToLayer("Card Render Texture");
        transform.FindChild("Rules").gameObject.layer = LayerMask.NameToLayer("Card Render Texture");

        Material return_material = new Material(multiply);
        return_material.mainTexture = render_texture;

        return return_material;
    }
开发者ID:JamesWilko,项目名称:FTJ,代码行数:26,代码来源:TileScript.cs


示例17: Screenshot

 IEnumerator Screenshot()
 {
     if (!Directory.Exists(outPath))
     {
         Directory.CreateDirectory(outPath);
     }
     while (record)
     {
         /*counter++;
         Application.CaptureScreenshot(outPath + counter.ToString("D8") + ".png", 0);
         UnityEngine.Debug.Log("PNG Created " + counter);
         yield return new WaitForSeconds(recordStep);*/
         counter++;
         RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
         camera.targetTexture = rt;
         Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
         camera.Render();
         RenderTexture.active = rt;
         screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
         camera.targetTexture = null;
         RenderTexture.active = null; // JC: added to avoid errors
         Destroy(rt);
         byte[] bytes = screenShot.EncodeToPNG();
         string filename = outPath + counter.ToString("D8") + ".png";//8 didget naming scheme limits us to videos roughly 28.9 days long
         System.IO.File.WriteAllBytes(filename, bytes);
         UnityEngine.Debug.Log(string.Format("Took screenshot to: {0}", filename));
         yield return new WaitForSeconds(recordStep);
         }
     yield break;
 }
开发者ID:denzelr,项目名称:UnityRecording,代码行数:30,代码来源:CapturePNG.cs


示例18: OnRenderImage

    void OnRenderImage(RenderTexture source, RenderTexture dest) 
    {
        if (m_Shader != null) 
        {
            Material.SetColor("_SephiaColor", m_Sephia);
            Material.SetFloat("_VignetteAmount", m_VignetteAmount);
            Material.SetFloat("_OldEffectAmount", m_OldEffectAmount);

            if (m_Vignette)
                Material.SetTexture("_Vignette", m_Vignette);

            if (m_Scratches)
            {
                Material.SetTexture("_Scratches", m_Scratches);
                Material.SetFloat("_ScratchesXSpeed", m_ScratchesXSpeed);
                Material.SetFloat("_ScratchesYSpeed", m_ScratchesYSpeed);
            }

            if (m_Dust)
            {
                Material.SetTexture("_Dust", m_Dust);
                Material.SetFloat("_DustXSpeed", m_DustXSpeed);
                Material.SetFloat("_DustYSpeed", m_DustYSpeed);
                Material.SetFloat("_RandomValue", m_RandomValue);
            }

            Graphics.Blit(source, dest, Material);
        }
        else
            Graphics.Blit(source, dest, null);

    }
开发者ID:Shahdee,项目名称:shaders,代码行数:32,代码来源:OldMovie.cs


示例19: OnRenderImage

    void OnRenderImage(RenderTexture src,RenderTexture dst)
    {
        RenderTexture blurTex = RenderTexture.GetTemporary(Screen.width /1, Screen.height / 1);
        //
        Graphics.Blit(src, blurTex, mat,0);
        //Graphics.Blit(blurTex, dst);
        RenderTexture buffer = RenderTexture.GetTemporary(src.width / 4, src.height / 4, 0);
        RenderTexture buffer2 = RenderTexture.GetTemporary(src.width / 4, src.height / 4, 0);

        DownSample4x(blurTex, buffer);//
        // Graphics.Blit(buffer, dst);
        bool oddEven = true;
        for (int i = 0; i < times; i++)
        {
            if (oddEven)
                FourTapCone(buffer, buffer2, i);
            else
                FourTapCone(buffer2, buffer, i);
            oddEven = !oddEven;
        }
        if (oddEven)
        {
            mat.SetTexture("_Energy", buffer);
            Graphics.Blit(src, dst,mat,1);
        }
        else
        {
            mat.SetTexture("_Energy", buffer2);
            Graphics.Blit(src, dst,mat,1);
        }
        RenderTexture.ReleaseTemporary(buffer);
        RenderTexture.ReleaseTemporary(buffer2);

        RenderTexture.ReleaseTemporary(blurTex);
    }
开发者ID:trojanfoe,项目名称:UnityShader,代码行数:35,代码来源:BlurEnergy_2Blur.cs


示例20: CaptureCamera

    /// <summary>
    /// 对相机截图。 
    /// </summary>
    /// <returns>The screenshot2.</returns>
    /// <param name="camera">Camera.要被截屏的相机</param>
    /// <param name="rect">Rect.截屏的区域</param>
    public static Texture2D CaptureCamera(string _fileParentPath, string _fileName)
    {
        // 创建一个RenderTexture对象
        RenderTexture rt = new RenderTexture((int)Screen.width, (int)Screen.height, 24);
        // 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
        Camera.main.targetTexture = rt;
        Camera.main.Render();
        //ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
        //ps: camera2.targetTexture = rt;
        //ps: camera2.Render();
        //ps: -------------------------------------------------------------------

        // 激活这个rt, 并从中中读取像素。
        RenderTexture.active = rt;
        screenShot = new Texture2D((int)Screen.width * 3 / 4, (int)Screen.height, TextureFormat.RGB24, false);
        screenShot.ReadPixels(new Rect(Screen.width * 1 / 8, 0, Screen.width * 3 / 4, Screen.height), 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
        screenShot.Apply();

        // 重置相关参数,以使用camera继续在屏幕上显示
        Camera.main.targetTexture = null;
        //ps: camera2.targetTexture = null;
        RenderTexture.active = null; // JC: added to avoid errors
        GameObject.Destroy(rt);
        // 最后将这些纹理数据,成一个png图片文件
        //byte[] bytes = screenShot.EncodeToPNG();
        byte[] bytes = screenShot.EncodeToJPG();
        string filename = _fileParentPath + _fileName;
        System.IO.File.WriteAllBytes(filename, bytes);

        return screenShot;
    }
开发者ID:sorpcboy,项目名称:moredo,代码行数:37,代码来源:ScreenShot.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RenderTextureFormat类代码示例发布时间:2022-05-24
下一篇:
C# RenderTargetView类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap