Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetTextureFromGlobal

Set a texture parameter from a global texture property.
Read time 2 minutesLast updated 10 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

SetTextureFromGlobal(int, int, int)

Set a texture parameter from a global texture property.
public void SetTextureFromGlobal(int kernelIndex, int nameID, int globalTextureNameID)

Parameters

kernelIndex

For which kernel the texture is being set. See ComputeShader.FindKernel.

nameID

Property name ID, use Shader.PropertyToID to get it.

globalTextureNameID

Property name ID, use Shader.PropertyToID to get it.

Remarks

This function can either set a regular texture that is read in the compute shader, or an output texture that is written into by the shader. For an output texture, it has to be a RenderTexture with random write flag enabled, see RenderTexture.enableRandomWrite.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.

Examples

// Assign the CameraMotionVectorsTexture global texture to a compute textureusing System;using UnityEngine;public class SampleBehaviour : MonoBehaviour{ public int renderTargetWidth; public int renderTargetHeight; ComputeShader myComputeShader; void ComputeUsingMotionVector() { int kKernelIndex = 0; myComputeShader.SetTextureFromGlobal(kKernelIndex, "computeTexture", "_CameraMotionVectorsTexture"); myComputeShader.Dispatch(kKernelIndex, renderTargetWidth, renderTargetHeight, 1); }}

SetTextureFromGlobal(int, string, string)

Set a texture parameter from a global texture property.
public void SetTextureFromGlobal(int kernelIndex, string name, string globalTextureName)

Parameters

kernelIndex

For which kernel the texture is being set. See ComputeShader.FindKernel.

name

Name of the buffer variable in shader code.

globalTextureName

Global texture property to assign to shader.

Remarks

This function can either set a regular texture that is read in the compute shader, or an output texture that is written into by the shader. For an output texture, it has to be a RenderTexture with random write flag enabled, see RenderTexture.enableRandomWrite.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.

Examples

// Assign the CameraMotionVectorsTexture global texture to a compute textureusing System;using UnityEngine;public class SampleBehaviour : MonoBehaviour{ public int renderTargetWidth; public int renderTargetHeight; ComputeShader myComputeShader; void ComputeUsingMotionVector() { int kKernelIndex = 0; myComputeShader.SetTextureFromGlobal(kKernelIndex, "computeTexture", "_CameraMotionVectorsTexture"); myComputeShader.Dispatch(kKernelIndex, renderTargetWidth, renderTargetHeight, 1); }}