Hi,
If I understand well, constant buffers allow to group some variables so several different shaders can use them without duplicating it. Am I right?
Anyway, my big question is: how to pass values to these variables from scripts? I just can’t figure out how I should do that…
For example in TerrainEngine.cginc, how can I set the value of “_CameraPosition” from a script?
CBUFFER_START(UnityTerrain)
// grass
fixed4 _WavingTint;
float4 _WaveAndDistance; // wind speed, wave size, wind amount, max sqr distance
float4 _CameraPosition; // .xyz = camera position, .w = 1 / (max sqr distance)
float3 _CameraRight, _CameraUp;
// trees
float4 _Scale;
float4x4 _TerrainEngineBendTree;
float4 _SquashPlaneNormal;
float _SquashAmount;
// billboards
float3 _TreeBillboardCameraRight;
float4 _TreeBillboardCameraUp;
float4 _TreeBillboardCameraFront;
float4 _TreeBillboardCameraPos;
float4 _TreeBillboardDistances; // x = max distance ^ 2
CBUFFER_END
Thanks!