# SetTexture

> Set a texture parameter.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## SetTexture(int, int, Texture, int)

Set a texture parameter.

```csharp
public void SetTexture(int kernelIndex, int nameID, Texture texture, int mipLevel)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): For which kernel the texture is being set. See [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Property name ID, use [Shader.PropertyToID](/engine/6000.6/script-reference/unityengine/shader/propertytoid.md) to get it.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): Texture to set.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): 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](/engine/6000.6/script-reference/unityengine/rendertexture.md) with random write flag enabled, see [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md).

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](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md) 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](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md), Additional Resources: [ComputeShader.SetFloat](/engine/6000.6/script-reference/unityengine/computeshader/setfloat.md), [ComputeShader.SetFloats](/engine/6000.6/script-reference/unityengine/computeshader/setfloats.md), [ComputeShader.SetInt](/engine/6000.6/script-reference/unityengine/computeshader/setint.md), [ComputeShader.SetInts](/engine/6000.6/script-reference/unityengine/computeshader/setints.md), [ComputeShader.SetBool](/engine/6000.6/script-reference/unityengine/computeshader/setbool.md), [ComputeShader.SetBuffer](/engine/6000.6/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetMatrix](/engine/6000.6/script-reference/unityengine/computeshader/setmatrix.md), [ComputeShader.SetMatrixArray](/engine/6000.6/script-reference/unityengine/computeshader/setmatrixarray.md),  [ComputeShader.SetVector](/engine/6000.6/script-reference/unityengine/computeshader/setvector.md), [ComputeShader.SetVectorArray](/engine/6000.6/script-reference/unityengine/computeshader/setvectorarray.md)., [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md), [RenderTextureSubElement](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement.md).

## SetTexture(int, int, Texture)

Set a texture parameter.

```csharp
public void SetTexture(int kernelIndex, int nameID, Texture texture)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): For which kernel the texture is being set. See [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Property name ID, use [Shader.PropertyToID](/engine/6000.6/script-reference/unityengine/shader/propertytoid.md) to get it.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/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](/engine/6000.6/script-reference/unityengine/rendertexture.md) with random write flag enabled, see [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md).

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](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md) 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](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md), Additional Resources: [ComputeShader.SetFloat](/engine/6000.6/script-reference/unityengine/computeshader/setfloat.md), [ComputeShader.SetFloats](/engine/6000.6/script-reference/unityengine/computeshader/setfloats.md), [ComputeShader.SetInt](/engine/6000.6/script-reference/unityengine/computeshader/setint.md), [ComputeShader.SetInts](/engine/6000.6/script-reference/unityengine/computeshader/setints.md), [ComputeShader.SetBool](/engine/6000.6/script-reference/unityengine/computeshader/setbool.md), [ComputeShader.SetBuffer](/engine/6000.6/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetMatrix](/engine/6000.6/script-reference/unityengine/computeshader/setmatrix.md), [ComputeShader.SetMatrixArray](/engine/6000.6/script-reference/unityengine/computeshader/setmatrixarray.md),  [ComputeShader.SetVector](/engine/6000.6/script-reference/unityengine/computeshader/setvector.md), [ComputeShader.SetVectorArray](/engine/6000.6/script-reference/unityengine/computeshader/setvectorarray.md)., [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md), [RenderTextureSubElement](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement.md).

## SetTexture(int, string, Texture)

Set a texture parameter.

```csharp
public void SetTexture(int kernelIndex, string name, Texture texture)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): For which kernel the texture is being set. See [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md).**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of the buffer variable in shader code.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/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](/engine/6000.6/script-reference/unityengine/rendertexture.md) with random write flag enabled, see [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md).

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](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md) 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](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md), Additional Resources: [ComputeShader.SetFloat](/engine/6000.6/script-reference/unityengine/computeshader/setfloat.md), [ComputeShader.SetFloats](/engine/6000.6/script-reference/unityengine/computeshader/setfloats.md), [ComputeShader.SetInt](/engine/6000.6/script-reference/unityengine/computeshader/setint.md), [ComputeShader.SetInts](/engine/6000.6/script-reference/unityengine/computeshader/setints.md), [ComputeShader.SetBool](/engine/6000.6/script-reference/unityengine/computeshader/setbool.md), [ComputeShader.SetBuffer](/engine/6000.6/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetMatrix](/engine/6000.6/script-reference/unityengine/computeshader/setmatrix.md), [ComputeShader.SetMatrixArray](/engine/6000.6/script-reference/unityengine/computeshader/setmatrixarray.md),  [ComputeShader.SetVector](/engine/6000.6/script-reference/unityengine/computeshader/setvector.md), [ComputeShader.SetVectorArray](/engine/6000.6/script-reference/unityengine/computeshader/setvectorarray.md)., [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md), [RenderTextureSubElement](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement.md).

## SetTexture(int, string, Texture, int)

Set a texture parameter.

```csharp
public void SetTexture(int kernelIndex, string name, Texture texture, int mipLevel)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): For which kernel the texture is being set. See [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md).**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of the buffer variable in shader code.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): Texture to set.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): 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](/engine/6000.6/script-reference/unityengine/rendertexture.md) with random write flag enabled, see [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md).

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](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md) 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](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md), Additional Resources: [ComputeShader.SetFloat](/engine/6000.6/script-reference/unityengine/computeshader/setfloat.md), [ComputeShader.SetFloats](/engine/6000.6/script-reference/unityengine/computeshader/setfloats.md), [ComputeShader.SetInt](/engine/6000.6/script-reference/unityengine/computeshader/setint.md), [ComputeShader.SetInts](/engine/6000.6/script-reference/unityengine/computeshader/setints.md), [ComputeShader.SetBool](/engine/6000.6/script-reference/unityengine/computeshader/setbool.md), [ComputeShader.SetBuffer](/engine/6000.6/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetMatrix](/engine/6000.6/script-reference/unityengine/computeshader/setmatrix.md), [ComputeShader.SetMatrixArray](/engine/6000.6/script-reference/unityengine/computeshader/setmatrixarray.md),  [ComputeShader.SetVector](/engine/6000.6/script-reference/unityengine/computeshader/setvector.md), [ComputeShader.SetVectorArray](/engine/6000.6/script-reference/unityengine/computeshader/setvectorarray.md)., [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md), [RenderTextureSubElement](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement.md).

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

Set a texture parameter.

```csharp
public void SetTexture(int kernelIndex, int nameID, RenderTexture texture, int mipLevel, RenderTextureSubElement element)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): For which kernel the texture is being set. See [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Property name ID, use [Shader.PropertyToID](/engine/6000.6/script-reference/unityengine/shader/propertytoid.md) to get it.**** (\[RenderTexture]\(/engine/6000.6/script-reference/unityengine/rendertexture)): Texture to set.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Optional mipmap level of the read-write texture.**** (\[RenderTextureSubElement]\(/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement)): 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](/engine/6000.6/script-reference/unityengine/rendertexture.md) with random write flag enabled, see [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md).

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](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md) 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](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md), Additional Resources: [ComputeShader.SetFloat](/engine/6000.6/script-reference/unityengine/computeshader/setfloat.md), [ComputeShader.SetFloats](/engine/6000.6/script-reference/unityengine/computeshader/setfloats.md), [ComputeShader.SetInt](/engine/6000.6/script-reference/unityengine/computeshader/setint.md), [ComputeShader.SetInts](/engine/6000.6/script-reference/unityengine/computeshader/setints.md), [ComputeShader.SetBool](/engine/6000.6/script-reference/unityengine/computeshader/setbool.md), [ComputeShader.SetBuffer](/engine/6000.6/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetMatrix](/engine/6000.6/script-reference/unityengine/computeshader/setmatrix.md), [ComputeShader.SetMatrixArray](/engine/6000.6/script-reference/unityengine/computeshader/setmatrixarray.md),  [ComputeShader.SetVector](/engine/6000.6/script-reference/unityengine/computeshader/setvector.md), [ComputeShader.SetVectorArray](/engine/6000.6/script-reference/unityengine/computeshader/setvectorarray.md)., [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md), [RenderTextureSubElement](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement.md).

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

Set a texture parameter.

```csharp
public void SetTexture(int kernelIndex, string name, RenderTexture texture, int mipLevel, RenderTextureSubElement element)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): For which kernel the texture is being set. See [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md).**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of the buffer variable in shader code.**** (\[RenderTexture]\(/engine/6000.6/script-reference/unityengine/rendertexture)): Texture to set.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Optional mipmap level of the read-write texture.**** (\[RenderTextureSubElement]\(/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement)): 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](/engine/6000.6/script-reference/unityengine/rendertexture.md) with random write flag enabled, see [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md).

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](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md) 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](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [ComputeShader.FindKernel](/engine/6000.6/script-reference/unityengine/computeshader/findkernel.md), Additional Resources: [ComputeShader.SetFloat](/engine/6000.6/script-reference/unityengine/computeshader/setfloat.md), [ComputeShader.SetFloats](/engine/6000.6/script-reference/unityengine/computeshader/setfloats.md), [ComputeShader.SetInt](/engine/6000.6/script-reference/unityengine/computeshader/setint.md), [ComputeShader.SetInts](/engine/6000.6/script-reference/unityengine/computeshader/setints.md), [ComputeShader.SetBool](/engine/6000.6/script-reference/unityengine/computeshader/setbool.md), [ComputeShader.SetBuffer](/engine/6000.6/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetMatrix](/engine/6000.6/script-reference/unityengine/computeshader/setmatrix.md), [ComputeShader.SetMatrixArray](/engine/6000.6/script-reference/unityengine/computeshader/setmatrixarray.md),  [ComputeShader.SetVector](/engine/6000.6/script-reference/unityengine/computeshader/setvector.md), [ComputeShader.SetVectorArray](/engine/6000.6/script-reference/unityengine/computeshader/setvectorarray.md)., [RenderTexture.enableRandomWrite](/engine/6000.6/script-reference/unityengine/rendertexture/enablerandomwrite.md), [RenderTextureSubElement](/engine/6000.6/script-reference/unityengine/rendering/rendertexturesubelement.md).
