# SetTextureFromGlobal

> Set a texture parameter from a global texture property.

## Definition

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

## SetTextureFromGlobal(int, int, int)

Set a texture parameter from a global texture property.

```csharp
public void SetTextureFromGlobal(int kernelIndex, int nameID, int globalTextureNameID)
```

### Parameters

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

Buffers and textures are set per-kernel. Use [ComputeShader.FindKernel](/engine/6000.3/script-reference/unityengine/computeshader/findkernel.md) to find kernel index by function name.

Additional Resources: [ComputeShader.FindKernel](/engine/6000.3/script-reference/unityengine/computeshader/findkernel.md), [ComputeShader.SetBuffer](/engine/6000.3/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetTexture](/engine/6000.3/script-reference/unityengine/computeshader/settexture.md), [Shader.SetGlobalTexture](/engine/6000.3/script-reference/unityengine/shader/setglobaltexture.md).

### Examples

```csharp
// Assign the CameraMotionVectorsTexture global texture to a compute texture
using 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.

```csharp
public void SetTextureFromGlobal(int kernelIndex, string name, string globalTextureName)
```

### Parameters

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

Buffers and textures are set per-kernel. Use [ComputeShader.FindKernel](/engine/6000.3/script-reference/unityengine/computeshader/findkernel.md) to find kernel index by function name.

Additional Resources: [ComputeShader.FindKernel](/engine/6000.3/script-reference/unityengine/computeshader/findkernel.md), [ComputeShader.SetBuffer](/engine/6000.3/script-reference/unityengine/computeshader/setbuffer.md), [ComputeShader.SetTexture](/engine/6000.3/script-reference/unityengine/computeshader/settexture.md), [Shader.SetGlobalTexture](/engine/6000.3/script-reference/unityengine/shader/setglobaltexture.md).

### Examples

```csharp
// Assign the CameraMotionVectorsTexture global texture to a compute texture
using 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);
    }
}
```
