Unexpected identifier cbuffer error
I have a hlsli file and would like to port it into Unity.
However, it seems something wrong that Unity does not recognize some keywords such as "cbuffer", "textureCube", "texture2D".
The following is snippets of code, working in original file but not in Unity. Any includes or settings I am missing?
cbuffer cbDebug : CB_DEBUG
{
float g_debug;
float g_debugSlider0;
}
TextureCube<float3> g_texCubeDiffuse : TEX_CUBE_DIFFUSE;
Texture2D<float2> g_texVSM : TEX_VSM;
the error looks like this (cbuffer, texturecube, texture2d are all not recognized):
Shader error in 'Custom/skin': Unexpected identifier "cbuffer". Expected one of: typedef const void inline uniform nointerpolation extern shared static volatile row_major column_major struct or a user-defined type at Assets/Shader/common.cginc(51)
I have found the document https://docs.unity3d.com/Manual/SL-BuiltinMacros.html says we should use CBUFFER_START instead, but it does not mention how to deal with registers after the colon.
Some other documents mention we should use samplerCUBE instead of TextureCube, and sampler2D instead of Texture2D. However, none of them talked about how to deal with the angle brackets.
Any ideas how to correct the code to work with Unity?
Your answer
![](https://koobas.hobune.stream/wayback/20220612141355im_/https://answers.unity.com/themes/thub/images/avi.jpg)