@woosh/meep-engine 2.42.2 → 2.42.4
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.
- package/engine/graphics/ecs/decal/v2/prototypeDecalEditor.js +138 -0
- package/engine/graphics/material/manager/ManagedMaterial.js +10 -0
- package/engine/graphics/material/manager/MaterialManager.js +28 -5
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +85 -81
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +54 -50
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +33 -27
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../../EngineHarness.js";
|
|
2
|
+
import EntityBuilder from "../../../../ecs/EntityBuilder.js";
|
|
3
|
+
import { SGMesh } from "../../mesh-v2/aggregate/SGMesh.js";
|
|
4
|
+
import { Transform } from "../../../../ecs/transform/Transform.js";
|
|
5
|
+
import { GLTFAssetLoader } from "../../../../asset/loaders/GLTFAssetLoader.js";
|
|
6
|
+
import { GameAssetType } from "../../../../asset/GameAssetType.js";
|
|
7
|
+
import { FPDecalSystem } from "./FPDecalSystem.js";
|
|
8
|
+
import { BehaviorSystem } from "../../../../intelligence/behavior/ecs/BehaviorSystem.js";
|
|
9
|
+
import { SGMeshSystem } from "../../mesh-v2/aggregate/SGMeshSystem.js";
|
|
10
|
+
import { ShadedGeometrySystem } from "../../mesh-v2/ShadedGeometrySystem.js";
|
|
11
|
+
import { TransformAttachmentSystem } from "../../../../ecs/transform-attachment/TransformAttachmentSystem.js";
|
|
12
|
+
import ListView from "../../../../../view/common/ListView.js";
|
|
13
|
+
import List from "../../../../../core/collection/list/List.js";
|
|
14
|
+
import ImageView from "../../../../../view/elements/image/ImageView.js";
|
|
15
|
+
import GUIElement from "../../../../ecs/gui/GUIElement.js";
|
|
16
|
+
import GUIElementSystem from "../../../../ecs/gui/GUIElementSystem.js";
|
|
17
|
+
import ObservedInteger from "../../../../../core/model/ObservedInteger.js";
|
|
18
|
+
import ObservedString from "../../../../../core/model/ObservedString.js";
|
|
19
|
+
import { MouseEvents } from "../../../../input/devices/events/MouseEvents.js";
|
|
20
|
+
|
|
21
|
+
class EditorState {
|
|
22
|
+
selected_entity = new ObservedInteger(-1)
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param {Engine} engine
|
|
29
|
+
* @param {ObservedString} selected
|
|
30
|
+
* @returns {ImageView|ListView}
|
|
31
|
+
*/
|
|
32
|
+
function makeDecalSelector({ engine, selected }) {
|
|
33
|
+
const decal_uris = new List(
|
|
34
|
+
`data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_03_t.png
|
|
35
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_04_t.png
|
|
36
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_05_t.png
|
|
37
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_06_t.png
|
|
38
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_07_t.png
|
|
39
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_08_t.png
|
|
40
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_09_t.png
|
|
41
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_10_t.png
|
|
42
|
+
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_11_t.png`
|
|
43
|
+
.trim()
|
|
44
|
+
.split('\n')
|
|
45
|
+
.map(s => s.trim())
|
|
46
|
+
.filter(s => s.length > 0)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const listView = new ListView(decal_uris, {
|
|
50
|
+
elementFactory(el) {
|
|
51
|
+
const element_view = new ImageView(el);
|
|
52
|
+
|
|
53
|
+
element_view.css({
|
|
54
|
+
pointerEvents: 'auto',
|
|
55
|
+
boxSizing: 'border-box',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
element_view.size.setScalar(64);
|
|
59
|
+
|
|
60
|
+
const process_selection = (e) => {
|
|
61
|
+
const is_selected = e === el;
|
|
62
|
+
|
|
63
|
+
element_view.css({
|
|
64
|
+
border: is_selected ? `2px solid red` : 'none'
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
element_view.bindSignal(selected.onChanged, process_selection);
|
|
69
|
+
process_selection(selected.getValue());
|
|
70
|
+
|
|
71
|
+
element_view.el.addEventListener(MouseEvents.Click, () => {
|
|
72
|
+
selected.set(el);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return element_view;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
listView.css({
|
|
80
|
+
backgroundImage:
|
|
81
|
+
`url(../data/textures/utility/checkers_white_grey_256x256.png)`,
|
|
82
|
+
backgroundSize: "24px 24px", /* Must be a square */
|
|
83
|
+
backgroundPosition: "0 0, 12px 0, 12px -12px, 0px 12px"
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
listView.size.set(600, 128);
|
|
87
|
+
|
|
88
|
+
return listView;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* @param {Engine} engine
|
|
94
|
+
*/
|
|
95
|
+
async function main(engine) {
|
|
96
|
+
|
|
97
|
+
await EngineHarness.buildBasics({
|
|
98
|
+
engine,
|
|
99
|
+
enableWater: false,
|
|
100
|
+
cameraFarDistance: 300
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const ecd = engine.entityManager.dataset;
|
|
104
|
+
|
|
105
|
+
new EntityBuilder()
|
|
106
|
+
.add(SGMesh.fromURL("moicon/gnutti_not_optimized/model.gltf"))
|
|
107
|
+
.add(Transform.fromJSON({
|
|
108
|
+
position: { x: 10, y: 3, z: 10 },
|
|
109
|
+
scale: 1.5
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
// decal selector
|
|
113
|
+
|
|
114
|
+
const selected_decal_uri = new ObservedString('');
|
|
115
|
+
|
|
116
|
+
new EntityBuilder()
|
|
117
|
+
.add(GUIElement.fromView(makeDecalSelector({ engine, selected: selected_decal_uri })))
|
|
118
|
+
.build(ecd);
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
new EngineHarness()
|
|
123
|
+
.initialize({
|
|
124
|
+
configuration(config, engine) {
|
|
125
|
+
const gltfAssetLoader = new GLTFAssetLoader();
|
|
126
|
+
|
|
127
|
+
config.addLoader(GameAssetType.ModelGLTF_JSON, gltfAssetLoader);
|
|
128
|
+
config.addLoader(GameAssetType.ModelGLTF, gltfAssetLoader);
|
|
129
|
+
|
|
130
|
+
config.addSystem(new FPDecalSystem(engine));
|
|
131
|
+
config.addSystem(new BehaviorSystem(engine))
|
|
132
|
+
config.addSystem(new SGMeshSystem(engine));
|
|
133
|
+
config.addSystem(new ShadedGeometrySystem(engine));
|
|
134
|
+
config.addSystem(new TransformAttachmentSystem(engine));
|
|
135
|
+
|
|
136
|
+
config.addSystem(new GUIElementSystem(engine.gui.view, engine));
|
|
137
|
+
}
|
|
138
|
+
}).then(main);
|
|
@@ -8,6 +8,12 @@ export class ManagedMaterial {
|
|
|
8
8
|
* @param {Material} m
|
|
9
9
|
*/
|
|
10
10
|
constructor(m) {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {Material|null}
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
this.__source = null;
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
*
|
|
@@ -30,6 +36,10 @@ export class ManagedMaterial {
|
|
|
30
36
|
this.onLastReleased = new Signal();
|
|
31
37
|
}
|
|
32
38
|
|
|
39
|
+
getSource() {
|
|
40
|
+
return this.__source;
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
/**
|
|
34
44
|
*
|
|
35
45
|
* @returns {Material}
|
|
@@ -8,7 +8,7 @@ export class MaterialManager {
|
|
|
8
8
|
constructor() {
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Stores links from uncompiled (source) materials to managed containers
|
|
12
12
|
* @type {HashMap<Material, ManagedMaterial>}
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
@@ -29,6 +29,17 @@ export class MaterialManager {
|
|
|
29
29
|
maxWeight: 100
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Stores links from compiled materials back to the container
|
|
34
|
+
* @type {HashMap<Material, ManagedMaterial>}
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
this.__reverse_library = new HashMap({
|
|
38
|
+
keyHashFunction: computeMaterialHash,
|
|
39
|
+
keyEqualityFunction: computeMaterialEquality,
|
|
40
|
+
capacity: 1024
|
|
41
|
+
});
|
|
42
|
+
|
|
32
43
|
this.__cache.onEvicted.add(this.__dispose_material, this);
|
|
33
44
|
|
|
34
45
|
/**
|
|
@@ -55,13 +66,15 @@ export class MaterialManager {
|
|
|
55
66
|
* @private
|
|
56
67
|
*/
|
|
57
68
|
__handle_last_reference_removed(material) {
|
|
58
|
-
const
|
|
69
|
+
const compiled_material = material.getMaterial();
|
|
59
70
|
|
|
60
71
|
// remove from library
|
|
61
|
-
|
|
72
|
+
const source = material.getSource();
|
|
73
|
+
this.__library.delete(source);
|
|
74
|
+
this.__reverse_library.delete(compiled_material);
|
|
62
75
|
|
|
63
76
|
// put material into cache
|
|
64
|
-
this.__cache.put(
|
|
77
|
+
this.__cache.put(source, material);
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
/**
|
|
@@ -118,7 +131,16 @@ export class MaterialManager {
|
|
|
118
131
|
* @returns {Reference<Material>}
|
|
119
132
|
*/
|
|
120
133
|
obtain(source) {
|
|
121
|
-
|
|
134
|
+
// reverse check to see if this is actually an already compiled/managed material
|
|
135
|
+
let material = this.__reverse_library.get(source);
|
|
136
|
+
|
|
137
|
+
if (material !== undefined) {
|
|
138
|
+
// already compiled material
|
|
139
|
+
return material.getRef();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// forward check
|
|
143
|
+
material = this.__library.get(source);
|
|
122
144
|
|
|
123
145
|
if (material === undefined) {
|
|
124
146
|
// not found in library, check cache
|
|
@@ -138,6 +160,7 @@ export class MaterialManager {
|
|
|
138
160
|
material.onLastReleased.addOne(this.__handle_last_reference_removed, this);
|
|
139
161
|
|
|
140
162
|
this.__library.set(source, material);
|
|
163
|
+
this.__reverse_library.set(material.getMaterial(), material);
|
|
141
164
|
}
|
|
142
165
|
|
|
143
166
|
return material.getRef();
|
|
@@ -1,89 +1,93 @@
|
|
|
1
1
|
export const FP_SHADER_CHUNK_ACCUMULATION = `
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// read light data
|
|
8
|
-
for(uint i=0u; i < cluster_metadata.y; i++){
|
|
9
|
-
uint lookup_index = cluster_metadata.x + i;
|
|
2
|
+
#ifndef FP_SHADER_CHUNK_ACCUMULATION
|
|
3
|
+
#define FP_SHADER_CHUNK_ACCUMULATION
|
|
4
|
+
|
|
5
|
+
ivec3 v3_cluster_resolution = textureSize(fp_t_light_tiles, 0);
|
|
6
|
+
ivec3 v3_cluster_position = ivec3( clip_v.x * float(v3_cluster_resolution.x), clip_v.y*float(v3_cluster_resolution.y), (clip_v.z)*float(v3_cluster_resolution.z) );
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
uvec3 cluster_metadata = texelFetch(fp_t_light_tiles, v3_cluster_position , 0).rgb;
|
|
9
|
+
|
|
10
|
+
// read light data
|
|
11
|
+
for(uint i=0u; i < cluster_metadata.y; i++){
|
|
12
|
+
uint lookup_index = cluster_metadata.x + i;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
uint light_address = light_descriptor >> 2;
|
|
15
|
-
|
|
14
|
+
uint light_descriptor = texelFetch(fp_t_light_lookup, address_to_data_texture_coordinates(lookup_index), 0 ).r;
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
|
|
21
|
-
vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
|
|
22
|
-
|
|
23
|
-
vec3 light_position = light_data_0.xyz;
|
|
24
|
-
float light_radius = light_data_0.w;
|
|
25
|
-
|
|
26
|
-
vec3 light_color = light_data_1.xyz;
|
|
27
|
-
float light_intensity = light_data_1.w;
|
|
28
|
-
|
|
29
|
-
PointLight pointlight;
|
|
30
|
-
|
|
31
|
-
pointlight.position = light_position;
|
|
32
|
-
pointlight.distance = light_radius;
|
|
33
|
-
pointlight.color = light_color*light_intensity;
|
|
34
|
-
pointlight.decay = 1.0;
|
|
35
|
-
|
|
36
|
-
fp_getPointDirectLightIrradiance( pointlight, directLight, vViewPosition );
|
|
37
|
-
RE_Direct( directLight, geometry, material, reflectedLight );
|
|
38
|
-
|
|
39
|
-
}else if(type == 3u){
|
|
40
|
-
// decal
|
|
41
|
-
vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
|
|
42
|
-
vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
|
|
43
|
-
vec4 light_data_2 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+2u), 0);
|
|
44
|
-
vec4 light_data_3 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+3u), 0);
|
|
45
|
-
|
|
46
|
-
mat4 decal_transform_matrix = mat4(
|
|
47
|
-
light_data_0,
|
|
48
|
-
light_data_1,
|
|
49
|
-
light_data_2,
|
|
50
|
-
light_data_3
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
vec4 local_position = decal_transform_matrix*vec4(v_world_position, 1.0);
|
|
54
|
-
|
|
55
|
-
if(max3(abs(local_position.xyz)) < 0.5){
|
|
56
|
-
|
|
57
|
-
// we're inside decal volume
|
|
58
|
-
vec4 light_data_4 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+4u), 0);
|
|
16
|
+
uint type = (light_descriptor) & 0x3u;
|
|
17
|
+
uint light_address = light_descriptor >> 2;
|
|
59
18
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
19
|
+
|
|
20
|
+
if(type == 0u){
|
|
21
|
+
// point light
|
|
22
|
+
|
|
23
|
+
vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
|
|
24
|
+
vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
|
|
25
|
+
|
|
26
|
+
vec3 light_position = light_data_0.xyz;
|
|
27
|
+
float light_radius = light_data_0.w;
|
|
28
|
+
|
|
29
|
+
vec3 light_color = light_data_1.xyz;
|
|
30
|
+
float light_intensity = light_data_1.w;
|
|
31
|
+
|
|
32
|
+
PointLight pointlight;
|
|
33
|
+
|
|
34
|
+
pointlight.position = light_position;
|
|
35
|
+
pointlight.distance = light_radius;
|
|
36
|
+
pointlight.color = light_color*light_intensity;
|
|
37
|
+
pointlight.decay = 1.0;
|
|
38
|
+
|
|
39
|
+
fp_getPointDirectLightIrradiance( pointlight, directLight, vViewPosition );
|
|
40
|
+
RE_Direct( directLight, geometry, material, reflectedLight );
|
|
63
41
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
42
|
+
}else if(type == 3u){
|
|
43
|
+
// decal
|
|
44
|
+
vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
|
|
45
|
+
vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
|
|
46
|
+
vec4 light_data_2 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+2u), 0);
|
|
47
|
+
vec4 light_data_3 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+3u), 0);
|
|
48
|
+
|
|
49
|
+
mat4 decal_transform_matrix = mat4(
|
|
50
|
+
light_data_0,
|
|
51
|
+
light_data_1,
|
|
52
|
+
light_data_2,
|
|
53
|
+
light_data_3
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
vec4 local_position = decal_transform_matrix*vec4(v_world_position, 1.0);
|
|
57
|
+
|
|
58
|
+
if(max3(abs(local_position.xyz)) < 0.5){
|
|
59
|
+
|
|
60
|
+
// we're inside decal volume
|
|
61
|
+
vec4 light_data_4 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+4u), 0);
|
|
62
|
+
|
|
63
|
+
// compute normal of the decal
|
|
64
|
+
vec4 decal_normal = normalize( viewMatrix*decal_transform_matrix*vec4(0.0, 0.0, 1.0, 0.0) );
|
|
65
|
+
float decal_surface_dot = dot(decal_normal.xyz, geometry.normal);
|
|
66
|
+
|
|
67
|
+
// we fade out decals when the projection angle to the surface gets too steep
|
|
68
|
+
// 0.7 is cos(45deg) and 0.5 is cos(60deg), dot returns cos of angle between two normals
|
|
69
|
+
float decal_surface_angle_fade = smoothstep(-0.5,-0.7,decal_surface_dot);
|
|
70
|
+
|
|
71
|
+
if(decal_surface_angle_fade <= 0.0){
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
vec2 decal_local_uv = (local_position.xy + 0.5);
|
|
76
|
+
vec2 decal_uv = decal_local_uv*light_data_4.zw + light_data_4.xy;
|
|
77
|
+
|
|
78
|
+
vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);
|
|
79
|
+
|
|
80
|
+
// compute decal alpha
|
|
81
|
+
float decal_alpha = decal_color.a * decal_surface_angle_fade;
|
|
82
|
+
|
|
83
|
+
if(decal_alpha < 0.003){
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;
|
|
88
|
+
}
|
|
89
|
+
|
|
88
90
|
}
|
|
91
|
+
}
|
|
92
|
+
#endif
|
|
89
93
|
`;
|
|
@@ -1,51 +1,55 @@
|
|
|
1
1
|
export const FP_SHADER_CHUNK_DECODE_PARS = `
|
|
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
|
-
|
|
2
|
+
#ifndef FP_SHADER_CHUNK_DECODE_PARS
|
|
3
|
+
#define FP_SHADER_CHUNK_DECODE_PARS
|
|
4
|
+
|
|
5
|
+
// don't rely on three.js light number define to ensure that point light calculations are available
|
|
6
|
+
#if NUM_POINT_LIGHTS < 1
|
|
7
|
+
struct PointLight {
|
|
8
|
+
vec3 position;
|
|
9
|
+
vec3 color;
|
|
10
|
+
float distance;
|
|
11
|
+
float decay;
|
|
12
|
+
};
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
// directLight is an out parameter as having it as a return value caused compiler errors on some devices
|
|
16
|
+
void fp_getPointDirectLightIrradiance( const in PointLight pointLight, out IncidentLight directLight, vec3 viewPosition ) {
|
|
17
|
+
|
|
18
|
+
// TODO consider moving light position transformation to view-space over to CPU
|
|
19
|
+
vec3 lVector = (viewMatrix*vec4(pointLight.position,1.0)).xyz + viewPosition;
|
|
20
|
+
|
|
21
|
+
directLight.direction = normalize( lVector );
|
|
22
|
+
|
|
23
|
+
float lightDistance = length( lVector );
|
|
24
|
+
|
|
25
|
+
directLight.color = pointLight.color;
|
|
26
|
+
directLight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
|
|
27
|
+
directLight.visible = ( directLight.color != vec3( 0.0 ) );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
float convert_depth_to_linear(in float d){
|
|
31
|
+
float d_n = 2.0*d - 1.0;
|
|
32
|
+
|
|
33
|
+
float f = fp_f_camera_far;
|
|
34
|
+
float n = fp_f_camera_near;
|
|
35
|
+
|
|
36
|
+
float fn = f*n;
|
|
37
|
+
|
|
38
|
+
float z_diff = f - n;
|
|
39
|
+
|
|
40
|
+
float denominator = (f + n - d_n * z_diff );
|
|
41
|
+
|
|
42
|
+
float z_view = (2.0*fn) / denominator;
|
|
43
|
+
|
|
44
|
+
return (z_view - n) / z_diff;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ivec2 address_to_data_texture_coordinates(uint address){
|
|
48
|
+
// Lookup texture has 128 width
|
|
49
|
+
uint lookup_index_x = address % 128u;
|
|
50
|
+
uint lookup_index_y = address >> 7;
|
|
51
|
+
|
|
52
|
+
return ivec2(int(lookup_index_x),int(lookup_index_y));
|
|
53
|
+
}
|
|
54
|
+
#endif
|
|
55
|
+
`;
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
export const FP_SHADER_CHUNK_PREAMBLE = `
|
|
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
|
-
|
|
1
|
+
export const FP_SHADER_CHUNK_PREAMBLE = `
|
|
2
|
+
#ifndef FP_SHADER_CHUNK_PREAMBLE
|
|
3
|
+
#define FP_SHADER_CHUNK_PREAMBLE
|
|
4
|
+
|
|
5
|
+
precision mediump usampler3D;
|
|
6
|
+
precision mediump usampler2D;
|
|
7
|
+
|
|
8
|
+
uniform usampler3D fp_t_light_tiles;
|
|
9
|
+
|
|
10
|
+
uniform usampler2D fp_t_light_lookup;
|
|
11
|
+
uniform sampler2D fp_t_light_data;
|
|
12
|
+
uniform sampler2D fp_t_decal_atlas;
|
|
13
|
+
uniform vec2 fp_t_decal_atlas_resolution;
|
|
14
|
+
|
|
15
|
+
uniform vec3 fp_v3_light_cluster_resolution;
|
|
16
|
+
|
|
17
|
+
uniform float fp_f_camera_near;
|
|
18
|
+
uniform float fp_f_camera_far;
|
|
19
|
+
|
|
20
|
+
#define gl_FragDepthEXT gl_FragDepth
|
|
21
|
+
#define texture2D texture
|
|
22
|
+
#define textureCube texture
|
|
23
|
+
#define texture2DProj textureProj
|
|
24
|
+
#define texture2DLodEXT textureLod
|
|
25
|
+
#define texture2DProjLodEXT textureProjLod
|
|
26
|
+
#define textureCubeLodEXT textureLod
|
|
27
|
+
#define texture2DGradEXT textureGrad
|
|
28
|
+
#define texture2DProjGradEXT textureProjGrad
|
|
29
|
+
#define textureCubeGradEXT textureGrad
|
|
30
|
+
|
|
31
|
+
uniform vec2 fp_resolution;
|
|
32
|
+
|
|
33
|
+
#endif
|
|
28
34
|
`;
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.42.
|
|
8
|
+
"version": "2.42.4",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|