@woosh/meep-engine 2.40.1 → 2.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/core/collection/HashMap.d.ts +2 -0
  2. package/core/collection/HashMap.js +22 -0
  3. package/core/geom/3d/apply_mat4_transform_to_v3_array.js +2 -4
  4. package/core/geom/3d/normal/hemioct/encode_unit3_hemioct.js +5 -0
  5. package/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.js +31 -0
  6. package/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.js +33 -0
  7. package/core/geom/3d/normal/octahedron/encoding.spec.js +29 -0
  8. package/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +28 -0
  9. package/core/geom/3d/topology/struct/BinaryTopology.js +112 -0
  10. package/core/geom/Quaternion.js +14 -0
  11. package/core/math/sign_not_zero.js +8 -0
  12. package/core/parser/simple/SimpleParser.js +3 -86
  13. package/core/parser/simple/readUnsignedInteger.js +66 -0
  14. package/core/parser/simple/skipWhitespace.js +21 -0
  15. package/engine/EngineHarness.js +13 -3
  16. package/engine/asset/AssetDescription.spec.js +27 -0
  17. package/engine/asset/loaders/GLTFAssetLoader.js +5 -3
  18. package/engine/ecs/foliage/ImpostorFoliage.js +4 -0
  19. package/engine/ecs/transform/Transform.js +23 -3
  20. package/engine/graphics/ecs/decal/v2/Decal.d.ts +11 -0
  21. package/engine/graphics/ecs/decal/v2/Decal.js +50 -0
  22. package/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +8 -0
  23. package/engine/graphics/ecs/decal/v2/FPDecalSystem.js +213 -0
  24. package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +237 -0
  25. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +8 -1
  26. package/engine/graphics/ecs/mesh-v2/build_three_object.js +4 -0
  27. package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +22 -7
  28. package/engine/graphics/filter/ImageFilter.js +2 -1
  29. package/engine/graphics/geometry/MikkT/MikkTSpace.js +466 -305
  30. package/engine/graphics/geometry/MikkT/MikkTSpace.spec.js +7 -1
  31. package/engine/{asset/loaders/geometry/geometry → graphics/geometry/buffered}/computeBufferAttributeHash.js +1 -1
  32. package/engine/{asset/loaders/geometry/geometry → graphics/geometry/buffered}/computeGeometryEquality.js +2 -2
  33. package/engine/{asset/loaders/geometry/geometry → graphics/geometry/buffered}/computeGeometryHash.js +1 -1
  34. package/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +2 -2
  35. package/engine/graphics/impostors/card_cluster/FacePlaneAssignment.js +30 -0
  36. package/engine/graphics/impostors/card_cluster/README.md +13 -0
  37. package/engine/graphics/impostors/octahedral/ImpostorBaker.js +345 -0
  38. package/engine/graphics/impostors/octahedral/ImpostorCaptureType.js +10 -0
  39. package/engine/graphics/impostors/octahedral/ImpostorDescription.js +69 -0
  40. package/engine/graphics/impostors/octahedral/README.md +30 -0
  41. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.js +45 -0
  42. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere_radius_only.js +37 -0
  43. package/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +117 -0
  44. package/engine/graphics/impostors/octahedral/grid/HemiOctahedralUvEncoder.js +20 -0
  45. package/engine/graphics/impostors/octahedral/grid/OctahedralUvEncoder.js +25 -0
  46. package/engine/graphics/impostors/octahedral/grid/UvEncoder.js +21 -0
  47. package/engine/graphics/impostors/octahedral/prototypeBaker.js +237 -0
  48. package/engine/graphics/impostors/octahedral/shader/BakeShaderStandard.js +196 -0
  49. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderStandard.js +306 -0
  50. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +349 -0
  51. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV1.js +74 -0
  52. package/engine/graphics/impostors/octahedral/shader/glsl/common.glsl +206 -0
  53. package/engine/graphics/impostors/octahedral/shader/glsl/v1/common.glsl +209 -0
  54. package/engine/graphics/impostors/octahedral/shader/glsl/v1/flagment.glsl +80 -0
  55. package/engine/graphics/impostors/octahedral/shader/glsl/v1/vertex.glsl +350 -0
  56. package/engine/graphics/micron/convert_three_object_to_micron.js +2 -2
  57. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +2 -2
  58. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  59. package/engine/graphics/particles/node-based/codegen/CodeGenerator.js +1 -1
  60. package/engine/graphics/particles/node-based/nodes/noise/CurlNoiseNode.js +1 -1
  61. package/engine/graphics/render/forward_plus/LightManager.js +1 -1
  62. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +1 -3
  63. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +2 -1
  64. package/engine/graphics/render/forward_plus/model/Decal.js +19 -2
  65. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +32 -10
  66. package/engine/graphics/shaders/ScreenSpaceQuadShader.js +4 -14
  67. package/engine/graphics/shaders/glsl_gen_swizzled_read.js +39 -0
  68. package/engine/graphics/texture/sampler/Sampler2D.js +10 -10
  69. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +117 -11
  70. package/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +66 -0
  71. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +2 -2
  72. package/engine/ui/GUIEngine.js +8 -1
  73. package/package.json +1 -1
  74. package/view/tooltip/gml/parser/readReferenceToken.js +1 -1
  75. package/engine/asset/GameAssetManager.js +0 -137
@@ -0,0 +1,74 @@
1
+ import {
2
+ AddEquation,
3
+ CustomBlending,
4
+ GLSL3,
5
+ OneFactor,
6
+ OneMinusSrcAlphaFactor,
7
+ RawShaderMaterial,
8
+ Vector3
9
+ } from "three";
10
+ import shader_vx from '../shader/glsl/v1/vertex.glsl';
11
+ import shader_fg from '../shader/glsl/v1/flagment.glsl';
12
+
13
+ export class ImpostorShaderV1 extends RawShaderMaterial {
14
+ constructor() {
15
+ super({
16
+ fragmentShader: shader_fg,
17
+ vertexShader: shader_vx,
18
+ uniforms: {
19
+ /**
20
+ * RGB + Alpha
21
+ */
22
+ tBase: {
23
+ value: null
24
+ },
25
+ /**
26
+ * Normal+Depth
27
+ */
28
+ tGeometry: {
29
+ value: null
30
+ },
31
+ /**
32
+ * Material properties: Occlusion, Roughness, Metalness
33
+ * Alpha unused
34
+ */
35
+ tMaterial: {
36
+ value: null
37
+ },
38
+ /**
39
+ * Number of frames
40
+ */
41
+ uFrames: {
42
+ value: 0
43
+ },
44
+ /**
45
+ * Radius of bounding sphere of the impostor
46
+ */
47
+ uRadius: {
48
+ value: 0
49
+ },
50
+ /**
51
+ * Impostor offset
52
+ */
53
+ uOffset: {
54
+ value: new Vector3(0, 0, 0)
55
+ },
56
+ uIsFullSphere: {
57
+ value: false
58
+ },
59
+ uDepthScale:{
60
+ // value should be in range between 0 and 1
61
+ value:1
62
+ }
63
+ },
64
+ glslVersion: GLSL3
65
+ });
66
+
67
+ // Save some effort by disabling blending
68
+ this.blending = CustomBlending;
69
+ this.blendEquation = AddEquation;
70
+ this.blendSrc = OneFactor;
71
+ this.blendDst = OneMinusSrcAlphaFactor;
72
+
73
+ }
74
+ }
@@ -0,0 +1,206 @@
1
+ struct ImposterData
2
+ {
3
+ vec2 uv;
4
+ vec2 grid;
5
+ vec4 frame0;
6
+ vec4 frame1;
7
+ vec4 frame2;
8
+ vec4 vertex;
9
+ };
10
+
11
+ struct Ray
12
+ {
13
+ vec3 Origin;
14
+ vec3 Direction;
15
+ };
16
+
17
+ //for hemisphere
18
+ vec3 OctaHemiEnc(vec2 coord)
19
+ {
20
+ coord = vec2(coord.x + coord.y, coord.x - coord.y) * 0.5;
21
+ vec3 vec = vec3(coord.x, 1.0 - dot(vec2(1.0, 1.0), abs(coord.xy)), coord.y);
22
+ return vec;
23
+ }
24
+ //for sphere
25
+ vec3 OctaSphereEnc(vec2 coord)
26
+ {
27
+ vec3 vec = vec3(coord.x, 1.0 - dot(vec2(1.0), abs(coord)), coord.y);
28
+ if (vec.y < 0.0)
29
+ {
30
+ vec2 flip = vec.xz >= 0.0 ? vec2(1.0, 1.0) : vec2(-1.0, -1.0);
31
+ vec.xz = (1-abs(vec.zx)) * flip;
32
+ }
33
+ return vec;
34
+ }
35
+
36
+ vec3 GridToVector(vec2 coord)
37
+ {
38
+ vec3 vec;
39
+ if (_ImposterFullSphere)
40
+ {
41
+ vec = OctaSphereEnc(coord);
42
+ }
43
+ else
44
+ {
45
+ vec = OctaHemiEnc(coord);
46
+ }
47
+ return vec;
48
+ }
49
+
50
+ //for hemisphere
51
+ vec2 VecToHemiOct(vec3 vec)
52
+ {
53
+ vec.xz /= dot(1.0, abs(vec));
54
+ return vec2(vec.x + vec.z, vec.x - vec.z);
55
+ }
56
+
57
+ vec2 VecToSphereOct(vec3 vec)
58
+ {
59
+ vec.xz /= dot(1, abs(vec));
60
+ if (vec.y <= 0)
61
+ {
62
+ vec2 flip = vec.xz >= 0 ? vec2(1, 1) : vec2(-1, -1);
63
+ vec.xz = (1-abs(vec.zx)) * flip;
64
+ }
65
+ return vec.xz;
66
+ }
67
+
68
+ vec2 VectorToGrid(vec3 vec)
69
+ {
70
+ vec2 coord;
71
+
72
+ if (_ImposterFullSphere)
73
+ {
74
+ coord = VecToSphereOct(vec);
75
+ }
76
+ else
77
+ {
78
+ vec.y = max(0.001, vec.y);
79
+ vec = normalize(vec);
80
+ coord = VecToHemiOct(vec);
81
+ }
82
+ return coord;
83
+ }
84
+
85
+ vec3 SpriteProjection(vec3 pivotToCameraRayLocal, float frames, vec2 size, vec2 coord){
86
+ vec3 gridVec = pivotToCameraRayLocal;
87
+
88
+ //octahedron vector, pivot to camera
89
+ vec3 y = normalize(gridVec);
90
+
91
+ vec3 x = normalize(cross(y, vec3(0.0, 1.0, 0.0)));
92
+ vec3 z = normalize(cross(x, y));
93
+
94
+ vec2 uv = ((coord*frames)-0.5) * 2.0;//-1 to 1
95
+
96
+ vec3 newX = x * uv.x;
97
+ vec3 newZ = z * uv.y;
98
+
99
+ vec2 halfSize = size*0.5;
100
+
101
+ newX *= halfSize.x;
102
+ newZ *= halfSize.y;
103
+
104
+ vec3 res = newX + newZ;
105
+
106
+ return res;
107
+ }
108
+
109
+ vec4 TriangleInterpolate(vec2 uv){
110
+ uv = frac(uv);
111
+
112
+ vec2 omuv = vec2(1.0, 1.0) - uv.xy;
113
+
114
+ vec4 res = vec4(0, 0, 0, 0);
115
+ //frame 0
116
+ res.x = min(omuv.x, omuv.y);
117
+ //frame 1
118
+ res.y = abs(dot(uv, vec2(1.0, -1.0)));
119
+ //frame 2
120
+ res.z = min(uv.x, uv.y);
121
+ //mask
122
+ res.w = saturate(ceil(uv.x-uv.y));
123
+
124
+ return res;
125
+ }
126
+
127
+ //frame and framecout, returns
128
+ vec3 FrameXYToRay(vec2 frame, vec2 frameCountMinusOne)
129
+ {
130
+ //divide frame x y by framecount minus one to get 0-1
131
+ vec2 f = frame.xy / frameCountMinusOne;
132
+
133
+ //bias and scale to -1 to 1
134
+ f = (f-0.5)*2.0;
135
+
136
+ //convert to vector, either full sphere or hemi sphere
137
+ vec3 vec = GridToVector(f);
138
+
139
+ vec = normalize(vec);
140
+
141
+ return vec;
142
+ }
143
+
144
+ vec3 ITBasis(vec3 vec, vec3 basedX, vec3 basedY, vec3 basedZ)
145
+ {
146
+ return vec3(dot(basedX, vec), dot(basedY, vec), dot(basedZ, vec));
147
+ }
148
+
149
+ vec3 FrameTransform(vec3 projRay, vec3 frameRay, out vec3 worldX, out vec3 worldZ)
150
+ {
151
+ //TODO something might be wrong here
152
+ worldX = normalize(vec3(-frameRay.z, 0, frameRay.x));
153
+ worldZ = normalize(cross(worldX, frameRay));
154
+
155
+ projRay *= -1.0;
156
+
157
+ vec3 local = normalize(ITBasis(projRay, worldX, frameRay, worldZ));
158
+ return local;
159
+ }
160
+
161
+
162
+ vec4 ImposterBlendWeights(sampler2D tex, vec2 uv, vec2 frame0, vec2 frame1, vec2 frame2, vec4 weights, vec2 ddxy)
163
+ {
164
+ vec4 samp0 = tex2Dgrad(tex, frame0, ddxy.x, ddxy.y);
165
+ vec4 samp1 = tex2Dgrad(tex, frame1, ddxy.x, ddxy.y);
166
+ vec4 samp2 = tex2Dgrad(tex, frame2, ddxy.x, ddxy.y);
167
+
168
+ //vec4 samp0 = tex2Dlod( tex, float4(frame0,0,0) );
169
+ //vec4 samp1 = tex2Dlod( tex, float4(frame1,0,0) );
170
+ //vec4 samp2 = tex2Dlod( tex, float4(frame2,0,0) );
171
+
172
+ vec4 result = samp0*weights.x + samp1*weights.y + samp2*weights.z;
173
+
174
+ return result;
175
+ }
176
+
177
+ vec2 VirtualPlaneUV(vec3 planeNormal, vec3 planeX, vec3 planeZ, vec3 center, vec2 uvScale, Ray rayLocal){
178
+ float normalDotOrigin = dot(planeNormal, rayLocal.Origin);
179
+ float normalDotCenter = dot(planeNormal, center);
180
+ float normalDotRay = dot(planeNormal, rayLocal.Direction);
181
+
182
+ float planeDistance = normalDotOrigin-normalDotCenter;
183
+ planeDistance *= -1.0;
184
+
185
+ float intersect = planeDistance / normalDotRay;
186
+
187
+ vec3 intersection = ((rayLocal.Direction * intersect) + rayLocal.Origin) - center;
188
+
189
+ float dx = dot(planeX, intersection);
190
+ float dz = dot(planeZ, intersection);
191
+
192
+ vec2 uv = vec2(0, 0);
193
+
194
+ if (intersect > 0)
195
+ {
196
+ uv = vec2(dx, dz);
197
+ }
198
+ else
199
+ {
200
+ uv = vec2(0, 0);
201
+ }
202
+
203
+ uv /= uvScale;
204
+ uv += vec2(0.5, 0.5);
205
+ return uv;
206
+ }
@@ -0,0 +1,209 @@
1
+ vec2 VecToSphereOct(vec3 pivotToCamera)
2
+ {
3
+ vec3 octant = sign(pivotToCamera);
4
+
5
+ // |x| + |y| + |z| = 1
6
+ float sum = dot(pivotToCamera, octant);
7
+ vec3 octahedron = pivotToCamera / sum;
8
+
9
+ if (octahedron.y < 0f)
10
+ {
11
+ vec3 absolute = abs(octahedron);
12
+ octahedron.xz = octant.xz * vec2(1.0f - absolute.z, 1.0f - absolute.x);
13
+ }
14
+ return octahedron.xz;
15
+ }
16
+
17
+ vec2 VecToHemiSphereOct(vec3 pivotToCamera)
18
+ {
19
+ pivotToCamera.y = max(pivotToCamera.y, 0.001);
20
+ pivotToCamera = normalize(pivotToCamera);
21
+ vec3 octant = sign(pivotToCamera);
22
+
23
+ // |x| + |y| + |z| = 1
24
+ float sum = dot(pivotToCamera, octant);
25
+ vec3 octahedron = pivotToCamera / sum;
26
+
27
+ return vec2(
28
+ octahedron.x + octahedron.z,
29
+ octahedron.z - octahedron.x);
30
+ }
31
+
32
+ vec2 VectorToGrid(vec3 vec)
33
+ {
34
+ if (isFullSphere)
35
+ {
36
+ return VecToSphereOct(vec);
37
+ }
38
+ else
39
+ {
40
+ return VecToHemiSphereOct(vec);
41
+ }
42
+ }
43
+
44
+ //for sphere
45
+ vec3 OctaSphereEnc(vec2 coord)
46
+ {
47
+ coord = (coord - 0.5) * 2.0;
48
+ vec3 position = vec3(coord.x, 0f, coord.y);
49
+ vec2 absolute = abs(position.xz);
50
+ position.y = 1f - absolute.x - absolute.y;
51
+
52
+ if (position.y < 0f)
53
+ {
54
+ position.xz = sign(position.xz) * vec2(1.0f - absolute.y, 1.0f - absolute.x);
55
+ }
56
+
57
+ return position;
58
+ }
59
+
60
+ //for hemisphere
61
+ vec3 OctaHemiSphereEnc(vec2 coord)
62
+ {
63
+ //coord = (0, 0.27)
64
+ //pos = -0.27, 0, -0.63
65
+
66
+ vec3 position = vec3(coord.x - coord.y, 0f, -1.0 + coord.x + coord.y);
67
+ vec2 absolute = abs(position.xz);
68
+ position.y = 1f - absolute.x - absolute.y;
69
+ return position;
70
+ }
71
+
72
+ vec3 GridToVector(vec2 coord)
73
+ {
74
+ if (isFullSphere)
75
+ {
76
+ return OctaSphereEnc(coord);
77
+ }
78
+ else
79
+ {
80
+ return OctaHemiSphereEnc(coord);
81
+ }
82
+ }
83
+
84
+ vec3 FrameXYToRay(vec2 frame, vec2 frameCountMinusOne)
85
+ {
86
+ //divide frame x y by framecount minus one to get 0-1
87
+ vec2 f = (frame.xy/ frameCountMinusOne);
88
+ //bias and scale to -1 to 1
89
+
90
+ vec3 vec = GridToVector(f);
91
+ vec = normalize(vec);
92
+ return vec;
93
+ }
94
+
95
+ vec3 SpriteProjection(vec3 pivotToCameraRayLocal, vec2 size, vec2 loc_uv)
96
+ {
97
+ vec3 z = normalize(pivotToCameraRayLocal);
98
+ vec3 x, y;
99
+ vec3 up = vec3(0,1,0);
100
+ //cross product doesnt work if we look directly from bottom
101
+ if (abs(z.y) > 0.999f)
102
+ {
103
+ up = vec3(0,0,-1);
104
+ }
105
+ x = normalize(cross(up, z));
106
+ y = normalize(cross(x, z));
107
+
108
+ loc_uv -= vec2(0.5,0.5);
109
+ vec2 uv = (loc_uv) * 2.0; //-1 to 1
110
+
111
+ vec3 newX = x * uv.x;
112
+ vec3 newY = y * uv.y;
113
+
114
+ vec2 vecSize = size * 0.5;
115
+
116
+ newX *= vecSize.x;
117
+ newY *= vecSize.y;
118
+
119
+ return newX + newY;
120
+ }
121
+
122
+ vec4 quadBlendWieghts(vec2 coords)
123
+ {
124
+ vec4 res;
125
+ /* 0 0 0
126
+ 0 0 0
127
+ 1 0 0 */
128
+ res.x = min(1f - coords.x, 1f - coords.y);
129
+ /* 1 0 0
130
+ 0 0 0
131
+ 0 0 1 */
132
+ res.y = abs(coords.x - coords.y);
133
+ /* 0 0 1
134
+ 0 0 0
135
+ 0 0 0 */
136
+ res.z = min(coords.x, coords.y);
137
+ /* 0 0 0
138
+ 0 0 1
139
+ 0 1 1 */
140
+ res.w = ceil(coords.x - coords.y);
141
+ //res.xyz /= (res.x + res.y + res.z);
142
+ return res;
143
+ }
144
+
145
+
146
+ //this function works well in orthogonal projection. It works okeyish with further distances of perspective projection
147
+ vec2 virtualPlaneUV(vec3 plane_normal,vec3 plane_x, vec3 plane_y, vec3 pivotToCameraRay, vec3 vertexToCameraRay, float size)
148
+ {
149
+ plane_normal = normalize(plane_normal);
150
+ plane_x = normalize(plane_x);
151
+ plane_y = normalize(plane_y);
152
+
153
+ // plane_normal is normalized but pivotToCameraRay & vertexToCameraRay are NOT
154
+ // so what are we doing here ?
155
+ // We are calculating length of pivotToCameraRay projected onto plane_normal
156
+ // so pivotToCameraRay is vector to camera from CENTER OF object
157
+ // we are recalculting this distance taking into account new plane normal
158
+ float projectedNormalRayLength = dot(plane_normal, pivotToCameraRay);
159
+ // tihs is direction is almost the same as origin, but its to individual vertex
160
+ // not sure this is correct for perspective projection
161
+ float projectedVertexRayLength = dot(plane_normal, vertexToCameraRay);
162
+ // basically its length difference betwen center and vertex - "not precise"
163
+ // projectedVertexRayLength is bigger than projectedNormalRayLength when vertex is
164
+ // further than "main front facing billboard"
165
+ // so offsetLength is getting smaller, otherwise is getting bigger
166
+ float offsetLength = projectedNormalRayLength/projectedVertexRayLength;
167
+
168
+ // ok so offsetLength is just a length
169
+ // we want a vector so we multiply it by vertexToCameraRay to get this offset
170
+ // now what are we REALY doing is calculuating distance difference
171
+ // se are SUBSTRACTING pivotToCameraRay vector
172
+ // we would get difference between center of plane and vertex rotated
173
+ vec3 offsetVector = vertexToCameraRay * offsetLength - pivotToCameraRay;
174
+
175
+ // we got the offset of rotated vertex, but we need to offset it from correct plane axis
176
+ // so again we projecting length of intersection (offset of rotated vertex) onto plane_x
177
+ // and plane_y
178
+ vec2 duv = vec2(
179
+ dot(plane_x , offsetVector),
180
+ dot(plane_y, offsetVector)
181
+ );
182
+
183
+ //we are in space -1 to 1
184
+ duv /= 2.0 * size;
185
+ duv += 0.5;
186
+ return duv;
187
+ }
188
+
189
+ void calcuateXYbasis(vec3 plane_normal, out vec3 plane_x, out vec3 plane_y)
190
+ {
191
+ vec3 up = vec3(0,1,0);
192
+ //cross product doesnt work if we look directly from bottom
193
+ if (abs(plane_normal.y) > 0.999f)
194
+ {
195
+ up = vec3(0,0,1);
196
+ }
197
+ plane_x = normalize(cross(plane_normal, up));
198
+ plane_y = normalize(cross(plane_x, plane_normal));
199
+ }
200
+
201
+ vec3 projectOnPlaneBasis(vec3 ray, vec3 plane_normal, vec3 plane_x, vec3 plane_y)
202
+ {
203
+ //reproject plane normal onto planeXY basos
204
+ return normalize(vec3(
205
+ dot(plane_x,ray),
206
+ dot(plane_y,ray),
207
+ dot(plane_normal,ray)
208
+ ));
209
+ }
@@ -0,0 +1,80 @@
1
+ precision highp float;
2
+ precision highp int;
3
+
4
+ const float depth_scale = 1.0;
5
+
6
+ uniform float uFrames;
7
+ uniform sampler2D tBase;
8
+ uniform sampler2D tGeometry;
9
+
10
+ out vec4 color_out;
11
+
12
+ in vec2 uv_frame1;
13
+ in vec2 xy_frame1;
14
+ flat in vec2 frame1;
15
+ flat in vec3 frame1_normal;
16
+ in vec2 uv_frame2;
17
+ in vec2 xy_frame2;
18
+ flat in vec2 frame2;
19
+ flat in vec3 frame2_normal;
20
+ in vec2 uv_frame3;
21
+ in vec2 xy_frame3;
22
+ flat in vec2 frame3;
23
+ flat in vec3 frame3_normal;
24
+ in vec4 quad_blend_weights;
25
+
26
+ vec2 recalculateUV(vec2 uv_f, vec2 frame, vec2 xy_f, vec2 frame_size, float d_scale, sampler2D depthTexture)
27
+ {
28
+ //clamp for parallax sampling
29
+ uv_f = clamp(uv_f, 0.0, 1.0);
30
+ vec2 uv_quad = frame_size * (frame + uv_f);
31
+ //paralax
32
+ float n_depth = texture(depthTexture, uv_quad).a;
33
+ uv_f = xy_f * (0.5-n_depth) * d_scale + uv_f;
34
+ //clamp parallax offset
35
+ uv_f = clamp(uv_f, 0.0, 1.0);
36
+ uv_f = frame_size * (frame + uv_f);
37
+ //clamped full UV
38
+ return clamp(uv_f, 0.0, 1.0);
39
+ }
40
+
41
+ vec4 blenderColors(vec2 uv_1, vec2 uv_2, vec2 uv_3, vec4 grid_weights, sampler2D atlasTexture)
42
+ {
43
+ vec4 quad_a, quad_b, quad_c;
44
+
45
+ quad_a = texture(atlasTexture, uv_1);
46
+ quad_b = texture(atlasTexture, uv_2);
47
+ quad_c = texture(atlasTexture, uv_3);
48
+ return quad_a * grid_weights.x + quad_b * grid_weights.y + quad_c * grid_weights.z;
49
+ }
50
+
51
+ void main()
52
+ {
53
+ vec2 quad_size = vec2(1.0) / uFrames;
54
+ vec2 uv_f1 = recalculateUV(uv_frame1, frame1, xy_frame1, quad_size, depth_scale, tGeometry);
55
+ vec2 uv_f2 = recalculateUV(uv_frame2, frame2, xy_frame2, quad_size, depth_scale, tGeometry);
56
+ vec2 uv_f3 = recalculateUV(uv_frame3, frame3, xy_frame3, quad_size, depth_scale, tGeometry);
57
+
58
+ vec4 baseTex = blenderColors(uv_f1, uv_f2, uv_f3, quad_blend_weights, tBase);
59
+
60
+ // vec4 ormTex = blenderColors(uv_f1, uv_f2, uv_f3, quad_blend_weights, imposterTextureOrm);
61
+ //
62
+ // vec3 normalTex = blendedNormals(
63
+ // uv_f1, frame1_normal,
64
+ // uv_f2, frame2_normal,
65
+ // uv_f3, frame3_normal,
66
+ // TANGENT, BINORMAL,
67
+ // quad_blend_weights, imposterTextureNormal
68
+ // );
69
+ //
70
+ // ALBEDO = baseTex.rgb * albedo.rgb;
71
+ // NORMAL =normalTex.xyz;
72
+ //
73
+ // METALLIC = ormTex.b * metallic;
74
+ // SPECULAR = specular;
75
+ // ROUGHNESS = ormTex.g * roughness;
76
+
77
+
78
+ color_out = baseTex;
79
+ // color_out = vec4(1.0);
80
+ }