Hi,
I’ve got a geometry shader rendering a compute buffer full of points in local space.
I’m transforming their position into world space by just adding the position of the object to the local position. I’m just wondering if there are any built in functions that will handle the bulk of this work for me before I go implement it the long way.
For reference this is the shader so far: Next step is to add rotation and scale transformations in the Vert function. Then adding in the geometry function to render more than just a point at each point.
Shader "Geometry/PointGeometryShader"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct data
{
float3 pos;
};
StructuredBuffer<data> buf_Points;
float3 _worldPos;
struct ps_input
{
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
ps_input vert(uint id : SV_VertexID)
{
ps_input o;
float3 worldPos = buf_Points[id].pos + _worldPos;
o.pos = UnityObjectToClipPos(float4(worldPos, 1.0f));
o.color = worldPos;
return o;
}
float4 frag(ps_input i) : COLOR
{
float4 col = float4(i.color, 1);
if (i.color.r <= 0 && i.color.g <= 0 && i.color.b <= 0)
col.rgb = float3(0, 1, 1);
//col = float4(1,1,1,1);
return col;
}
ENDCG
}
}
}