/
Geometry.vcgh
82 lines (70 loc) · 2 KB
/
Geometry.vcgh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 1 "shaders/VertexCommon.cgh"
float4 TransformPosition (
in float4x4 ModelViewMatrix,
in float4x4 ProjectionMatrix,
float4 position
) {
return mul(mul(position, ProjectionMatrix), ModelViewMatrix);
}
inline float2 ComputeRegionSize(
in float4 textureRegion
) {
return textureRegion.zw - textureRegion.xy;
}
inline float2 ComputeCorner(
in float cornerIndex,
in float2 regionSize
) {
if (cornerIndex == 0)
return float2(0, 0);
else if (cornerIndex == 1)
return float2(regionSize.x, 0);
else if (cornerIndex == 2)
return regionSize;
else
return float2(0, regionSize.y);
}
inline float2 ComputeTexCoord(
in uniform float2 halfTexel,
in float cornerIndex,
in float2 corner,
in float4 textureRegion
) {
float2 texTL = min(textureRegion.xy, textureRegion.zw) - halfTexel;
float2 texBR = max(textureRegion.xy, textureRegion.zw) + halfTexel;
return clamp((textureRegion.xy + corner) + halfTexel, texTL, texBR);
}
inline float2 ComputeRotatedCorner(
in uniform float2 halfTexel,
in uniform float2 bitmapTextureSize,
in float2 corner,
in float4 textureRegion,
in float4 scaleOrigin,
in float rotation
) {
corner = abs(corner);
corner -= (scaleOrigin.zw * abs(textureRegion.zw - textureRegion.xy));
float2 sinCos, rotatedCorner;
corner *= scaleOrigin.xy;
corner *= bitmapTextureSize;
sincos(rotation, sinCos.x, sinCos.y);
return float2(
(sinCos.y * corner.x) - (sinCos.x * corner.y),
(sinCos.x * corner.x) + (sinCos.y * corner.y)
) - halfTexel;
}
# 3 "shaders/Geometry.vcgh"
void main(
in uniform float4x4 ProjectionMatrix,
in uniform float4x4 ModelViewMatrix,
in uniform float2 ViewportScale,
in uniform float2 ViewportPosition,
in float2 position : POSITION,
in float4 color : COLOR0,
out float4 transformedPosition : POSITION,
out float4 colorOut : COLOR0
) {
position.xy += 0.5;
transformedPosition = TransformPosition(ProjectionMatrix, ModelViewMatrix, float4(position.xy, 0, 1));
colorOut = color;
}