Skip to content

Instantly share code, notes, and snippets.

@pixelmager
Last active June 8, 2017 05:57
Show Gist options
  • Save pixelmager/e391ea5808fa8a0e4bd1 to your computer and use it in GitHub Desktop.
Save pixelmager/e391ea5808fa8a0e4bd1 to your computer and use it in GitHub Desktop.
1) : VPOS not supported for pixel-position in fragment program
NOT FUNCTIONAL workaround: (see https://gist.github.com/aras-p/8e0c061d4e2490c1f8e2 )
#if defined(SHADER_API_D3D11)
#define VPOS_TYPE float4
#define VPOS_SEM WPOS
#else
#define VPOS_TYPE float2
#define VPOS_SEM VPOS
#endif
half4 frag( v2f IN, VPOS_TYPE in_vpos : VPOS_SEM ) : COLOR
{ ... }
// ENDED UP NOT USING VPOS ON ANY PLATFORMS, CALCULATING SCREENPOS USING UnityCg.cginc->ComputeScreenPos()
2) surface shaders with vertex-programs relying on implicit generation of uv_MainTex fails,
due to vertex-shader not manually filling out struct.
- it can't be 'inout' as 'out' is forced by surface shaders.
workaround: as per Aras' comment: add UNITY_INITIALIZE_OUTPUT( Input, IN ) to all verts.
#define D3D11_HACKAROUND IN.uv_MainTex = float2(0,0);
void myVertexProgram( inout appdata_full v, out Input IN )
{
#if defined( D3D11_HACKAROUND )
D3D11_HACKAROUND
#endif //D3D11_HACKAROUND
...
}
// =========
// from auto-generated surface-shader:
struct Input {
float2 uv_MainTex : TEXCOORD0; //note: set automagically
float fogfact : TEXCOORD1;
};
void vert_fog( inout appdata_full v, out Input IN )
{
IN.fogfact = calcFogFactor( v.vertex.xyz );
}
struct v2f_surf {
float4 pos : SV_POSITION;
float2 pack0 : TEXCOORD0;
float cust_fogfact : TEXCOORD1;
fixed3 normal : TEXCOORD2;
};
float4 _MainTex_ST;
v2f_surf vert_surf (appdata_full v) {
v2f_surf o;
Input customInputData;
vert_fog (v, customInputData); //NOTE: uv_MainTex not filled out manually, as will be transferred from pack0 later.
o.cust_fogfact = customInputData.fogfact;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
o.normal = mul((float3x3)_Object2World, SCALED_NORMAL);
return o;
}
3)
- this causes an internal error in unity, as it allocates memory for a vec3 but tries to set a vec4
uniform float3 _SphereScale;
mpb.AddVector( "_SphereScale", new Vector4() );
workaround: just declare as float4 _SphereScale;
3.1) same thing happens for
Properties {
_MyVector( "itsavector", Vector) = (0.25, 0.25, 0.25, 0.25)
}
Pass {
float3 _MyVector; // <-- this should be float4 or d3d11 will keel over
...
}
4) UNITY_MATRIX_MVP somewhat different...
workaround: TBD
// DENORMALS
5) denormals are handled differently (or at all) in d3d11
- divide by zero blows up..!
6) ...something about large numbers (seen with exp2(-large_negative_number)) - min(anyvalue, brokennumber) appears to fix the denormals(!?!)
7) normalize(0) on d3d9 returns 1, on d3d11 it returns 0
@aras-p
Copy link

aras-p commented Sep 2, 2014

I'd suggest just adding a UNITY_INITIALIZE_OUTPUT(Input, IN); as first thing in myVertexProgram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment