I’m trying something that is supposed to be simple but i’m missing some unity configuration or setup. I want to perform a UV unwrapping to a model and render into a render texture but its giving me some trouble, only a couple models work at all (All the models I tried had correct uvs in the vertex data).
The shader is really simple, it takes the uv values, transforms it into Normalized Device Coordinates and pass that as the output position to the pipeline.
Shader "Unlit/UnrwapModel"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 hpos : SV_POSITION;
};
v2f vert(appdata IN) {
v2f OUT;
OUT.hpos.xy = IN.uv * 2 - 1;
OUT.hpos.z = 0.5;
OUT.hpos.w = 1;
return OUT;
}
fixed4 frag () : SV_Target
{
return fixed4(0.5,1,1,1);
}
ENDCG
}
}
}
I’m getting really odd stuff with this: in the material preview, only the cylinder actually maps correctly (and im not even sure if that’s how its supposed to look at all, cause that doesn’t really look like a UV)
And the fun thing is, the default unity cylinder only renders on the preview, in an actual scene no fragments are generated at all and I get a black screen. That is for 90% of the models I tried.
I already made sure the models are placed inside the camera view volume so they wont get culled.
Here’s a snapshot of this exact frame. Everything looks correct, the UV values are right (i’ve even mapped these uv’s myself), the SV_POS are all in NDC, Z values are also inside the view volume, and I tried all Z values from [-1,1] with no luck of getting it rendered.
Now for the funny part, here’s a model that kinda works.
I can’t really grasp what I’m missing here, any help is appreciated.