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
For which kernel the texture is being set. See ComputeShader.FindKernel.
Property name ID, use Shader.PropertyToID to get it.
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.
Additional Resources: ComputeShader.FindKernel, ComputeShader.SetBuffer, ComputeShader.SetTexture, Shader.SetGlobalTexture.
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
For which kernel the texture is being set. See ComputeShader.FindKernel.
Name of the buffer variable in shader code.
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.
Additional Resources: ComputeShader.FindKernel, ComputeShader.SetBuffer, ComputeShader.SetTexture, Shader.SetGlobalTexture.
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); }}