Texture 在Compute Shader 中算是一个特别重要的应用了。
其实原理什么的都和上一篇说的一样。
下面说一些不一样的。
#pragma kernel CSMain
RWTexture2D<float4> Result;
[numthreads(8,8,1)]
void CSMain (uint2 id : SV_DispatchThreadID)
{
float x, y;
Result.GetDimensions(x, y);
Result[id] = float4(id.x/x,id.y/y,1,1);
}
-------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class _t2 : MonoBehaviour {
public RawImage ri;
public ComputeShader shader;
RenderTexture tex;
void Start () {
tex = new RenderTexture(64,64,0);
tex.enableRandomWrite = true;
tex.Create();
shader.SetTexture(0, "Result", tex);
shader.Dispatch(0, 8, 8, 1);
ri.texture = tex;
}
private void OnDestroy()
{
tex.Release();
}
}
1.RWTexture2D<float4> Result; 表示可随机写入的Textur

本文介绍了在Unity中如何使用Compute Shader处理Texture,强调了RWTexture2D<float4>的作用,获取Texture尺寸的方法以及开启RenderTexture的随机读写。还讨论了Texture在Compute Shader中的采样方式,包括基本采样、带Mipmap的采样以及使用SamplerState进行高级采样的方法。
最低0.47元/天 解锁文章
1328

被折叠的 条评论
为什么被折叠?



