Last active
February 3, 2018 12:39
-
-
Save aras-p/8e0c061d4e2490c1f8e2 to your computer and use it in GitHub Desktop.
Using VPOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// yeah it's not terribly nice | |
Shader "Foo" { | |
SubShader { | |
Pass { | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma target 3.0 | |
#include "UnityCG.cginc" | |
#if defined(SHADER_API_D3D9) | |
#define VPOS_TYPE float2 | |
#else | |
#define VPOS_TYPE float4 | |
#endif | |
struct appdata_t { | |
float4 vertex : POSITION; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f { | |
float2 texcoord : TEXCOORD0; | |
}; | |
v2f vert (appdata_t v, out float4 opos : SV_POSITION) | |
{ | |
v2f o; | |
opos = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.texcoord = v.texcoord; | |
return o; | |
} | |
fixed4 frag (v2f i, VPOS_TYPE ppp : VPOS) : SV_Target | |
{ | |
fixed4 c = 0; | |
c.xy = ppp; | |
c.xy *= 0.01; | |
return c; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not too bad either, but yea, unfortunately still requires workarounds.
The tag evidently needs to be changed to wpos as well. Also, as most other platforms work with float2/vpos, it makes sense to reverse the defines.
if defined(SHADER_API_D3D11)
define VPOS_TYPE float4
define VPOS_TAG WPOS
else
define VPOS_TYPE float2
define VPOS_TAG VPOS
endif
half4 frag( v2f IN, VPOS_TYPE in_vpos : VPOS_TAG ) : COLOR
{ ... }