Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetTexture

Set a texture parameter.
Read time 6 minutesLast updated 6 days ago

Definition

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

SetTexture(int, int, Texture, int)

Set a texture parameter.
public void SetTexture(int kernelIndex, int nameID, Texture texture, int mipLevel)

Parameters

kernelIndex

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

nameID

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

texture

Texture to set.

mipLevel

Optional mipmap level of the read-write texture.

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.
Please note that the mipLevel parameter is ignored unless the shader specifies a read-write (unordered access) texture.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.
By specifying a
RenderTextureSubElement
, you can indicate which type of data to set from the RenderTexture. The possible options are: RenderTextureSubElement.Color, RenderTextureSubElement.Depth, and RenderTextureSubElement.Stencil.

SetTexture(int, int, Texture)

Set a texture parameter.
public void SetTexture(int kernelIndex, int nameID, Texture texture)

Parameters

kernelIndex

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

nameID

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

texture

Texture to set.

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.
Please note that the mipLevel parameter is ignored unless the shader specifies a read-write (unordered access) texture.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.
By specifying a
RenderTextureSubElement
, you can indicate which type of data to set from the RenderTexture. The possible options are: RenderTextureSubElement.Color, RenderTextureSubElement.Depth, and RenderTextureSubElement.Stencil.

SetTexture(int, string, Texture)

Set a texture parameter.
public void SetTexture(int kernelIndex, string name, Texture texture)

Parameters

kernelIndex

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

name

Name of the buffer variable in shader code.

texture

Texture to set.

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.
Please note that the mipLevel parameter is ignored unless the shader specifies a read-write (unordered access) texture.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.
By specifying a
RenderTextureSubElement
, you can indicate which type of data to set from the RenderTexture. The possible options are: RenderTextureSubElement.Color, RenderTextureSubElement.Depth, and RenderTextureSubElement.Stencil.

SetTexture(int, string, Texture, int)

Set a texture parameter.
public void SetTexture(int kernelIndex, string name, Texture texture, int mipLevel)

Parameters

kernelIndex

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

name

Name of the buffer variable in shader code.

texture

Texture to set.

mipLevel

Optional mipmap level of the read-write texture.

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.
Please note that the mipLevel parameter is ignored unless the shader specifies a read-write (unordered access) texture.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.
By specifying a
RenderTextureSubElement
, you can indicate which type of data to set from the RenderTexture. The possible options are: RenderTextureSubElement.Color, RenderTextureSubElement.Depth, and RenderTextureSubElement.Stencil.

SetTexture(int, int, RenderTexture, int, RenderTextureSubElement)

Set a texture parameter.
public void SetTexture(int kernelIndex, int nameID, RenderTexture texture, int mipLevel, RenderTextureSubElement element)

Parameters

kernelIndex

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

nameID

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

Texture to set.

mipLevel

Optional mipmap level of the read-write texture.

Optional parameter that specifies the type of data to set from the RenderTexture.

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.
Please note that the mipLevel parameter is ignored unless the shader specifies a read-write (unordered access) texture.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.
By specifying a
RenderTextureSubElement
, you can indicate which type of data to set from the RenderTexture. The possible options are: RenderTextureSubElement.Color, RenderTextureSubElement.Depth, and RenderTextureSubElement.Stencil.

SetTexture(int, string, RenderTexture, int, RenderTextureSubElement)

Set a texture parameter.
public void SetTexture(int kernelIndex, string name, RenderTexture texture, int mipLevel, RenderTextureSubElement element)

Parameters

kernelIndex

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

name

Name of the buffer variable in shader code.

Texture to set.

mipLevel

Optional mipmap level of the read-write texture.

Optional parameter that specifies the type of data to set from the RenderTexture.

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.
Please note that the mipLevel parameter is ignored unless the shader specifies a read-write (unordered access) texture.
Buffers and textures are set per-kernel. Use ComputeShader.FindKernel to find kernel index by function name.
By specifying a
RenderTextureSubElement
, you can indicate which type of data to set from the RenderTexture. The possible options are: RenderTextureSubElement.Color, RenderTextureSubElement.Depth, and RenderTextureSubElement.Stencil.