- Home /
Question by
Jacktang · Feb 28, 2012 at 04:28 PM ·
shaderuvvertexshader
Unwrap a mesh with a vertex shader
Hello, I'm trying to unwrap a mesh according to its UV coordinates from a vertex shader and display it in screen space. I can't quite figure out why what I'm doing isn't working out. I apply it to a sphere and i just see nothing in the viewport. On occasion it will simply crash Unity. Any ideas?
Shader "Custom/UnwrapShader" {
Properties {
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert_main
#pragma fragment frag_main
#include "UnityCG.cginc"
struct Output_Struct {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Vertex_Struct {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
Output_Struct vert_main (Vertex_Struct v) {
Output_Struct OUT;
OUT.position.xy = v.texcoord.xy * 2.0 - 1;
OUT.position.z = 0.0;
OUT.position.w = 1.0;
return OUT;
}
float4 frag_main (Output_Struct OUT) : COLOR {
return float4(1,1,0,1);
}
ENDCG
}
}
FallBack "Diffuse"
}
Comment