Reputation: 817
I write HLSL
code for Shaders in Unity and i need a Tutorial or Documentation for know the Classes and Types. the Microsoft Docs is very poor Information (i search about Vector and i dont know to deal with it ).
And i need a ide or something work to autoCompelte syntax.
so if someone suggest a Docs or tutorial for leaning HLSL and know the function and classes inside it and the standard library , and ide for debugging and autoCompelte syntax.
Upvotes: 0
Views: 924
Reputation: 843
HLSL Tools for Visual Studio is a pretty good extension for VS, I've read that there are good tools for visual studio code as well, but I'm assuming you are using Visual Studio with Unity.
The Vector class is part of UnityEngine, so not usable from a shader. The extension will help quite a bit, but to get you started, most numerical variables are packaged as vectors (the numerical term for a collection of numbers) and can be used as float2
, float3
, or float4
for 2, 3, or 4 vectors (very similar to storing floats in Vector2, Vector3, or Vector4). You can use matrices in the same way: float3x3
, float2x4
, etc.
If you want to take the cross product of two vectors and normalize the result,
float3 a = float3(1,2,3);
float3 b = float3(5,3,2);
return normalize(cross(a,b));
You can take the dot product with dot(a,b)
and do matrix multiplication with mul(a,b)
.
Syntactically it's pretty similar to c++. Depending of what you're trying to accomplish, you could recreate most of the UnityEngine.Vector class functionality (more info here).
The quickest way to debug shaders in unity is to return some result as a test and evaluate it. If you are doing anything graphics related, that just means outputting an intermediate result. You can also write the same code as a single threaded cpu task and debug traditionally.
Upvotes: 1