'Returning local position as color
I am trying to pass the local position of an object from vertex to fragment shader in Unity to encode it later in a rendertexture.
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct MeshData
{
float4 vertex : POSITION;
};
struct Interpolators
{
float4 vertex : SV_POSITION;
float3 objectVertex : TEXCOORD0;
};
Interpolators vert (MeshData v)
{
Interpolators o;
o.objectVertex = v.vertex.xyz;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag (Interpolators i) : SV_Target
{
return float4(i.objectVertex,1);
}
ENDCG
}
The result I want to achieve is on the right, my result is on the left:

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
