I would like to store my fragment’s world coordinates into 3 textures which respectively represent x,y,z coordinates of the coordinate. Despite the textures are in the format ARGB32, I cant seem to write a value bigger than 1.0 Here is my shader code.
Shader "Custom/FirstPass"
{
Properties { }
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 5.0
#include "UnityCG.cginc"
struct vertexData
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 color : COLOR;
float4 texcoord0 : TEXCOORD0;
//...
};
struct fragmentData
{
float4 positionC : SV_POSITION;
float4 positionW : TEXCOORD1;
//float4 color : COLOR;
//...
};
struct fragmentOutput
{
float Gx : SV_Target0;
float Gy : SV_Target1;
float Gz : SV_Target2;
float depth:SV_Target3;
};
fragmentData vert(vertexData v)
{
fragmentData o;
o.positionW=mul(unity_ObjectToWorld,v.vertex);
o.positionC=UnityObjectToClipPos(v.vertex);
return o;
}
fragmentOutput frag(fragmentData fragment)
{
fragmentOutput output;
output.Gx =fragment.positionW.x;
output.Gy= fragment.positionW.y;
output.Gz = fragment.positionW.z;
output.depth=fragment.positionC.z;
//... write to other renderbuffers
return output;
}
ENDCG
}
}
}