|
8 | 8 | ZWrite Off |
9 | 9 | ZTest Always |
10 | 10 | Blend SrcAlpha OneMinusSrcAlpha |
11 | | - |
| 11 | + |
| 12 | + |
| 13 | + |
12 | 14 | LOD 100 |
13 | 15 |
|
14 | 16 | Pass |
15 | 17 | { |
16 | 18 |
|
17 | 19 | CGPROGRAM |
| 20 | + |
18 | 21 | #pragma vertex vert |
19 | 22 | #pragma fragment frag |
20 | 23 |
|
21 | 24 | #include "UnityCG.cginc" |
22 | 25 |
|
23 | 26 |
|
| 27 | + |
24 | 28 | struct v2f |
25 | 29 | { |
26 | 30 | float2 uv : TEXCOORD0; |
|
58 | 62 | float3 vertexPos = float3(0.,0.,0.); |
59 | 63 | float2 v2_1 = float2(0.,0.); // generic name. Now it is uv, I will use the register for other things later |
60 | 64 |
|
61 | | - |
62 | | - |
| 65 | + // Dealing with API differences. Not quite sure what is happening, the DirectX11 is clock wise |
| 66 | + // and OpenGl counterclockwise as default values, but I would have expected that Unity takes care |
| 67 | + // of this automaticly. However the triangle stream at this point is already past the Vertex Assembler |
| 68 | + // which might have a different settings. At anycase differnece between the Z axis between the two |
| 69 | + // is to be expected, the projection matrix should have maybe taken care of it, but maybe in Unity |
| 70 | + // the negation there is handeled by the camera matrix which I am not using. I just changed the |
| 71 | + // Z coordinates per API. |
| 72 | + |
| 73 | +#if SHADER_API_D3D11 || SHADER_API_D3D11_9X |
| 74 | + // Counter clockwise binding |
63 | 75 | [branch] switch (vertexCase) { |
64 | 76 | case 0: vertexPos = float3(-0.5, 0.5, 0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad |
65 | 77 | case 1: vertexPos = float3(-0.5,-0.5, 0.5); v2_1 = float2(0.,0.);break; // lower left of the Quad |
|
69 | 81 | case 5: vertexPos = float3(-0.5, 0.5, 0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad |
70 | 82 | } |
71 | 83 |
|
| 84 | + |
| 85 | +#else // Clock wise binding |
| 86 | + [branch] switch (vertexCase) { |
| 87 | + case 0: vertexPos = float3(-0.5, 0.5, -0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad |
| 88 | + case 1: vertexPos = float3( 0.5,-0.5, -0.5); v2_1 = float2(1.,0.);break; // lower left of the Quad |
| 89 | + case 2: vertexPos = float3(-0.5,-0.5, -0.5); v2_1 = float2(0.,0.);break; // lower right of the Quad |
| 90 | + case 3: vertexPos = float3( 0.5,-0.5, -0.5); v2_1 = float2(1.,0.);break; // lower right of the Quad |
| 91 | + case 4: vertexPos = float3(-0.5, 0.5, -0.5); v2_1 = float2(0.,1.);break; // upper right of the Quad |
| 92 | + case 5: vertexPos = float3( 0.5, 0.5, -0.5); v2_1 = float2(1.,1.);break; // upper left of the Quad |
| 93 | + } |
| 94 | + |
| 95 | +#endif |
72 | 96 | v2f o; |
73 | 97 | o.uv = v2_1; |
74 | 98 |
|
|
91 | 115 |
|
92 | 116 | vertexPos = mul(brushModelMat, float4(vertexPos.xyz, 1.)); |
93 | 117 |
|
94 | | - o.vertex = mul(UNITY_MATRIX_P, float4(vertexPos.xyz, 1.)); |
95 | | - o.vertex = float4(vertexPos.xyz,1.); |
| 118 | + |
| 119 | + o.vertex = float4(vertexPos.xyz, 1.); |
96 | 120 | return o; |
97 | 121 | } |
98 | 122 |
|
|
0 commit comments