Maybe I’m getting used to more informative error messages, this doesn’t mean much, I don’t know if it’s a regression, I didn’t do CS until async in 18.1 was introduced so maybe it’s just cryptic stuff you guys need to work on.
UnityException: SetTexture failed
UnityEngine.ComputeShader.SetTexture (Int32 kernelIndex, System.String name, UnityEngine.Texture texture) (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/Core/ComputeShaderBindings.gen.cs:146)
SimpleComputeShader.OnEnable () (at Assets/compute shader tutorials/SimpleComputeShader.cs:13)
A better message would tell me why this failed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleComputeShader : MonoBehaviour {
public ComputeShader shader;
Texture2D tex;
void OnEnable()
{
tex = new Texture2D(64, 64,TextureFormat.RGBAFloat, false);
shader.SetTexture(0, "tex", tex);
shader.Dispatch(0, tex.width / 8, tex.height / 8, 1);
}
private void OnGUI()
{
int w = Screen.width / 2;
int h = Screen.height / 2;
int s = 512;
GUI.DrawTexture(new Rect(w - s / 2, h - s / 2, s, s), tex);
}
}
#pragma kernel CSMain
RWTexture2D<float4> tex;
[numthreads(8,8,1)]
void CSMain (uint2 id : SV_DispatchThreadID)
{
float w,h;
tex.GetDimensions(w,h);
float uv = float2(idx/w, idy/h);
tex[id] = float4(uv,0.0,1.0);
}