chorama 0.0.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.
- package/.configs/tsconfig.lib.json +43 -0
- package/.configs/tsconfig.website.json +34 -0
- package/.github/workflows/static.yml +88 -0
- package/.vscode/launch.json +29 -0
- package/.vscode/tasks.json +19 -0
- package/README.md +127 -0
- package/assets/images/disappointed.jpg +0 -0
- package/assets/images/skybox/grimmnight_back.png +0 -0
- package/assets/images/skybox/grimmnight_bottom.png +0 -0
- package/assets/images/skybox/grimmnight_front.png +0 -0
- package/assets/images/skybox/grimmnight_left.png +0 -0
- package/assets/images/skybox/grimmnight_right.png +0 -0
- package/assets/images/skybox/grimmnight_top.png +0 -0
- package/assets/images/skybox/miramar_back.png +0 -0
- package/assets/images/skybox/miramar_bottom.png +0 -0
- package/assets/images/skybox/miramar_front.png +0 -0
- package/assets/images/skybox/miramar_left.png +0 -0
- package/assets/images/skybox/miramar_right.png +0 -0
- package/assets/images/skybox/miramar_top.png +0 -0
- package/assets/images/uv.jpg +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
- package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
- package/assets/models/gltf/flight_helmet/index.bin +0 -0
- package/assets/models/gltf/flight_helmet/index.gltf +705 -0
- package/assets/models/gltf/object.gltf +23 -0
- package/assets/models/gltf/pirate_girl/index.bin +0 -0
- package/assets/models/gltf/pirate_girl/index.gltf +2082 -0
- package/assets/models/obj/pirate_girl/pirate_girl.obj +18459 -0
- package/assets/models/obj/pirate_girl/pirate_girl.png +0 -0
- package/astro.config.mjs +45 -0
- package/content/guide/api-map.md +89 -0
- package/content/guide/camera-and-controls.md +98 -0
- package/content/guide/first-scene.md +176 -0
- package/content/guide/index.md +72 -0
- package/content/guide/installation.md +179 -0
- package/content/guide/materials-and-lighting.md +138 -0
- package/content/guide/plugins-and-render-pipeline.md +124 -0
- package/content/guide/render-targets-and-views.md +147 -0
- package/content/guide/scene-graph-and-transforms.md +113 -0
- package/content/guide/textures-and-assets.md +120 -0
- package/content/guide/troubleshooting.md +49 -0
- package/env.d.ts +19 -0
- package/examples/addons/rendergraph_gui.js +580 -0
- package/examples/camera/orthographic.js +120 -0
- package/examples/camera/perspective.js +138 -0
- package/examples/lights/directional.js +397 -0
- package/examples/lights/multiple_spot_lights.js +304 -0
- package/examples/lights/point.js +337 -0
- package/examples/lights/spot.js +366 -0
- package/examples/loader/gltf_material.js +111 -0
- package/examples/loader/gltfloader.js +78 -0
- package/examples/loader/objloader.js +95 -0
- package/examples/material/cullface.js +111 -0
- package/examples/material/materials.js +126 -0
- package/examples/material/standard/basic.js +164 -0
- package/examples/mesh/circle.js +117 -0
- package/examples/mesh/cuboid.js +151 -0
- package/examples/mesh/cylinder.js +139 -0
- package/examples/mesh/geometries.js +108 -0
- package/examples/mesh/meshTopology.js +103 -0
- package/examples/mesh/plane.js +117 -0
- package/examples/mesh/skinning.js +136 -0
- package/examples/mesh/uvsphere.js +113 -0
- package/examples/other/rotatingCube.js +93 -0
- package/examples/other/rotatingSphere.js +96 -0
- package/examples/rendertarget/basic_canvas.js +130 -0
- package/examples/rendertarget/depth_texture.js +130 -0
- package/examples/rendertarget/image_target.js +140 -0
- package/examples/rendertarget/multiple_views.js +158 -0
- package/examples/rendertarget/render_masks.js +173 -0
- package/examples/rendertarget/split_screen.js +123 -0
- package/examples/rendertarget/split_view.js +137 -0
- package/examples/skybox/skybox.js +111 -0
- package/examples/texture/arrays.js +156 -0
- package/examples/texture/textureWrap.js +118 -0
- package/examples/transform/propagation.js +92 -0
- package/package.json +55 -0
- package/rollup.config.js +66 -0
- package/scripts/stage-chorama.mjs +29 -0
- package/src/caches/cache.js +420 -0
- package/src/caches/index.js +2 -0
- package/src/caches/uniformbuffers.js +104 -0
- package/src/cameracontrols/index.js +258 -0
- package/src/constants/index.js +3 -0
- package/src/constants/mesh.js +197 -0
- package/src/constants/others.js +218 -0
- package/src/constants/texture.js +183 -0
- package/src/core/constants.js +14 -0
- package/src/core/extensions.js +42 -0
- package/src/core/index.js +7 -0
- package/src/core/layouts/index.js +4 -0
- package/src/core/layouts/meshvertex.js +60 -0
- package/src/core/layouts/uniform.js +21 -0
- package/src/core/layouts/uniformbuffer.js +15 -0
- package/src/core/layouts/vertexbuffer.js +43 -0
- package/src/core/limits.js +247 -0
- package/src/core/resources/blendparams.js +89 -0
- package/src/core/resources/framebuffer.js +127 -0
- package/src/core/resources/gpubuffer.js +32 -0
- package/src/core/resources/gpumesh.js +43 -0
- package/src/core/resources/gputexture.js +73 -0
- package/src/core/resources/index.js +5 -0
- package/src/core/shader.js +62 -0
- package/src/core/webgl/bindgroup.js +89 -0
- package/src/core/webgl/descriptors.js +104 -0
- package/src/core/webgl/index.js +5 -0
- package/src/core/webgl/renderpassencoder.js +96 -0
- package/src/core/webgl/renderpipeline.js +54 -0
- package/src/core/webgl/utils.js +371 -0
- package/src/core/webgl/webglrenderdevice.js +235 -0
- package/src/function.js +358 -0
- package/src/index.js +15 -0
- package/src/loader/gltf.js +2172 -0
- package/src/loader/index.js +3 -0
- package/src/loader/loader.js +174 -0
- package/src/loader/obj.js +188 -0
- package/src/loader/texture.js +85 -0
- package/src/loader/utils.js +16 -0
- package/src/material/basic.js +75 -0
- package/src/material/depth.js +73 -0
- package/src/material/index.js +8 -0
- package/src/material/lambert.js +73 -0
- package/src/material/material.js +106 -0
- package/src/material/normal.js +30 -0
- package/src/material/phong.js +86 -0
- package/src/material/raw.js +52 -0
- package/src/material/standard.js +221 -0
- package/src/math/index.js +3 -0
- package/src/math/transform.js +38 -0
- package/src/mesh/attribute/attribute.js +79 -0
- package/src/mesh/attribute/index.js +1 -0
- package/src/mesh/attributedata/index.js +1 -0
- package/src/mesh/attributedata/separate.js +180 -0
- package/src/mesh/builders/base.js +41 -0
- package/src/mesh/builders/circle.js +63 -0
- package/src/mesh/builders/cuboid.js +135 -0
- package/src/mesh/builders/cylinder.js +131 -0
- package/src/mesh/builders/index.js +7 -0
- package/src/mesh/builders/plane.js +73 -0
- package/src/mesh/builders/utils.js +20 -0
- package/src/mesh/builders/uvsphere.js +80 -0
- package/src/mesh/builders/wireframe.js +62 -0
- package/src/mesh/index.js +4 -0
- package/src/mesh/mesh.js +149 -0
- package/src/objects/bone.js +17 -0
- package/src/objects/camera/camera.js +56 -0
- package/src/objects/camera/index.js +2 -0
- package/src/objects/camera/projection.js +203 -0
- package/src/objects/debug/index.js +1 -0
- package/src/objects/debug/skeleton.js +28 -0
- package/src/objects/index.js +7 -0
- package/src/objects/light/ambient.js +20 -0
- package/src/objects/light/directional.js +29 -0
- package/src/objects/light/index.js +5 -0
- package/src/objects/light/point.js +32 -0
- package/src/objects/light/shadow/index.js +1 -0
- package/src/objects/light/shadow/shadow.js +67 -0
- package/src/objects/light/spot.js +56 -0
- package/src/objects/mesh.js +141 -0
- package/src/objects/object3d.js +167 -0
- package/src/objects/skybox.js +38 -0
- package/src/plugins/camera/camera.js +19 -0
- package/src/plugins/camera/index.js +2 -0
- package/src/plugins/camera/nodes/cameraview.js +46 -0
- package/src/plugins/camera/nodes/index.js +2 -0
- package/src/plugins/camera/nodes/opaquepass.js +79 -0
- package/src/plugins/index.js +6 -0
- package/src/plugins/light/index.js +2 -0
- package/src/plugins/light/light.js +23 -0
- package/src/plugins/light/nodes/index.js +1 -0
- package/src/plugins/light/nodes/light.js +127 -0
- package/src/plugins/meshmaterial/index.js +3 -0
- package/src/plugins/meshmaterial/meshmaterial.js +381 -0
- package/src/plugins/meshmaterial/nodes/index.js +1 -0
- package/src/plugins/meshmaterial/nodes/meshmaterial.js +50 -0
- package/src/plugins/meshmaterial/resources/index.js +1 -0
- package/src/plugins/meshmaterial/resources/meshmaterialpipelines.js +50 -0
- package/src/plugins/shadow/index.js +3 -0
- package/src/plugins/shadow/nodes/index.js +3 -0
- package/src/plugins/shadow/nodes/shadow.js +272 -0
- package/src/plugins/shadow/nodes/shadowOccluder.js +112 -0
- package/src/plugins/shadow/nodes/shadowOpaquePass.js +73 -0
- package/src/plugins/shadow/resources/ShadowMap.js +99 -0
- package/src/plugins/shadow/resources/index.js +2 -0
- package/src/plugins/shadow/resources/shadowpipelines.js +25 -0
- package/src/plugins/shadow/shadow.js +31 -0
- package/src/plugins/skeletonhelper/index.js +1 -0
- package/src/plugins/skeletonhelper/skeletonhelper.js +160 -0
- package/src/plugins/skybox/index.js +3 -0
- package/src/plugins/skybox/nodes/index.js +1 -0
- package/src/plugins/skybox/nodes/skybox.js +143 -0
- package/src/plugins/skybox/resources/index.js +2 -0
- package/src/plugins/skybox/resources/skyboxmesh.js +14 -0
- package/src/plugins/skybox/resources/skyboxpipeline.js +6 -0
- package/src/plugins/skybox/skybox.js +137 -0
- package/src/renderer/core/index.js +179 -0
- package/src/renderer/graph/index.js +3 -0
- package/src/renderer/graph/nodes.js +34 -0
- package/src/renderer/graph/rendergraph.js +182 -0
- package/src/renderer/index.js +5 -0
- package/src/renderer/plugin.js +36 -0
- package/src/renderer/renderer.js +179 -0
- package/src/renderer/views.js +28 -0
- package/src/rendertarget/canvastarget.js +30 -0
- package/src/rendertarget/image.js +132 -0
- package/src/rendertarget/index.js +3 -0
- package/src/rendertarget/rendertarget.js +89 -0
- package/src/shader/basicFragment.glsl +30 -0
- package/src/shader/basicVertex.glsl +87 -0
- package/src/shader/common/color.glsl +7 -0
- package/src/shader/common/common.glsl +25 -0
- package/src/shader/common/index.js +4 -0
- package/src/shader/common/light.glsl +437 -0
- package/src/shader/common/math.glsl +12 -0
- package/src/shader/debug/index.js +2 -0
- package/src/shader/debug/skeletonFragment.glsl +8 -0
- package/src/shader/debug/skeletonVertex.glsl +27 -0
- package/src/shader/depthFragment.glsl +37 -0
- package/src/shader/index.js +11 -0
- package/src/shader/lambertFragment.glsl +126 -0
- package/src/shader/normalFragment.glsl +25 -0
- package/src/shader/phongFragment.glsl +140 -0
- package/src/shader/skyboxFragment.glsl +16 -0
- package/src/shader/skyboxVertex.glsl +20 -0
- package/src/shader/standardFragment.glsl +274 -0
- package/src/texture/index.js +2 -0
- package/src/texture/sampler.js +111 -0
- package/src/texture/texture.js +234 -0
- package/src/utils/index.js +115 -0
- package/tsconfig.json +11 -0
- package/website/config/index.ts +1 -0
- package/website/config/navigation.ts +53 -0
- package/website/content.config.ts +92 -0
- package/website/layouts/DocLayout.astro +501 -0
- package/website/layouts/Example.astro +91 -0
- package/website/pages/examples/[...slug].astro +77 -0
- package/website/pages/examples/index.astro +98 -0
- package/website/pages/examples/samples/[...slug].astro +17 -0
- package/website/pages/guide/[slug].astro +30 -0
- package/website/pages/guide/index.astro +21 -0
- package/website/pages/index.astro +9 -0
- package/website/plugins/remark-link-base.js +23 -0
- package/website/utils/url.ts +30 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Graph, kahnTopologySort } from "vifaa"
|
|
2
|
+
import { assert } from "../../utils/index.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef RenderGraphNode
|
|
6
|
+
* @property {(context: RenderGraphContext) => void} execute
|
|
7
|
+
* @property {() => RenderGraph | undefined} subgraph
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef RenderGraphContext
|
|
12
|
+
* @property {import("../renderer.js").WebGLRenderer} renderer
|
|
13
|
+
* @property {import("../../objects/index.js").Object3D[]} objects
|
|
14
|
+
* @property {import("../../core/index.js").WebGLRenderDevice} renderDevice
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export class RenderGraph {
|
|
18
|
+
/**
|
|
19
|
+
* @private
|
|
20
|
+
* @type {Graph<RenderGraphNode, undefined>}
|
|
21
|
+
*/
|
|
22
|
+
graph = new Graph(true)
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
* @type {Map<string, number>}
|
|
27
|
+
*/
|
|
28
|
+
nodes = new Map()
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @type {[string,string][]}
|
|
32
|
+
*/
|
|
33
|
+
queuedEdges = []
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} name
|
|
37
|
+
* @param {RenderGraphNode} node
|
|
38
|
+
* @returns {number}
|
|
39
|
+
*/
|
|
40
|
+
addNode(name, node) {
|
|
41
|
+
const current = this.nodes.get(name)
|
|
42
|
+
|
|
43
|
+
if (current !== undefined) {
|
|
44
|
+
throw new Error(`Render graph node "${name}" already exists`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const id = this.graph.addNode(node)
|
|
48
|
+
|
|
49
|
+
this.nodes.set(name, id)
|
|
50
|
+
return id
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
addDependencies() {
|
|
57
|
+
for (let i = this.queuedEdges.length - 1; i >= 0; i--) {
|
|
58
|
+
const [from, to] = /** @type {[string, string]} */ (this.queuedEdges[i])
|
|
59
|
+
|
|
60
|
+
const fromId = this.nodes.get(from)
|
|
61
|
+
const toId = this.nodes.get(to)
|
|
62
|
+
|
|
63
|
+
assert(fromId, `Render graph node "${from}" is missing`)
|
|
64
|
+
assert(toId, `Render graph node "${to}" is missing`)
|
|
65
|
+
|
|
66
|
+
this.graph.addEdge(fromId, toId, undefined)
|
|
67
|
+
}
|
|
68
|
+
this.queuedEdges = []
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} from
|
|
73
|
+
* @param {string} to
|
|
74
|
+
*/
|
|
75
|
+
addDependency(from, to) {
|
|
76
|
+
this.queuedEdges.push([from, to])
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {RenderGraphContext} context
|
|
81
|
+
*/
|
|
82
|
+
execute(context) {
|
|
83
|
+
this.addDependencies()
|
|
84
|
+
/** @type {number[] | undefined} */
|
|
85
|
+
const order = kahnTopologySort(this.graph)
|
|
86
|
+
|
|
87
|
+
assert(order, "Cycle detected in render graph")
|
|
88
|
+
|
|
89
|
+
for (let i = 0; i < order.length; i++) {
|
|
90
|
+
const nodeId = /** @type {number | undefined} */ (order[i])
|
|
91
|
+
assert(nodeId, "Invalid render graph topology output")
|
|
92
|
+
const node = this.graph.getNodeWeight(nodeId)
|
|
93
|
+
|
|
94
|
+
assert(node, `Render graph node with id "${nodeId}" is missing`)
|
|
95
|
+
node.execute(context)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns a serializable snapshot of the render graph for tooling/debug UIs.
|
|
101
|
+
*/
|
|
102
|
+
inspect() {
|
|
103
|
+
this.addDependencies()
|
|
104
|
+
|
|
105
|
+
const typedGraph = /** @type {{ getNodes: () => any[]; getEdges: () => any[] }} */ (
|
|
106
|
+
/** @type {unknown} */ (this.graph)
|
|
107
|
+
)
|
|
108
|
+
const nodes = typedGraph.getNodes()
|
|
109
|
+
const edges = typedGraph.getEdges()
|
|
110
|
+
const namesById = new Map()
|
|
111
|
+
|
|
112
|
+
for (const [name, id] of this.nodes.entries()) {
|
|
113
|
+
namesById.set(id, name)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** @type {{ id: number; name: string; node: RenderGraphNode; subgraph: RenderGraph | undefined; incoming: number[]; outgoing: number[] }[]} */
|
|
117
|
+
const resultNodes = []
|
|
118
|
+
|
|
119
|
+
for (let id = 0; id < nodes.length; id++) {
|
|
120
|
+
const node = nodes[id]
|
|
121
|
+
if (!node) continue
|
|
122
|
+
|
|
123
|
+
/** @type {number[]} */
|
|
124
|
+
const incoming = []
|
|
125
|
+
/** @type {number[]} */
|
|
126
|
+
const outgoing = []
|
|
127
|
+
|
|
128
|
+
for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
|
|
129
|
+
const edge = edges[edgeIndex]
|
|
130
|
+
if (!edge) continue
|
|
131
|
+
|
|
132
|
+
if (edge.to === id) incoming.push(edge.from)
|
|
133
|
+
if (edge.from === id) outgoing.push(edge.to)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const subgraph = typeof node.weight.subgraph === "function" ?
|
|
137
|
+
node.weight.subgraph() :
|
|
138
|
+
undefined
|
|
139
|
+
|
|
140
|
+
resultNodes.push({
|
|
141
|
+
id,
|
|
142
|
+
name: namesById.get(id) ?? `Node_${id}`,
|
|
143
|
+
node: node.weight,
|
|
144
|
+
subgraph,
|
|
145
|
+
incoming,
|
|
146
|
+
outgoing
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @type {{ from: number; to: number }[]} */
|
|
151
|
+
const resultEdges = []
|
|
152
|
+
for (let i = 0; i < edges.length; i++) {
|
|
153
|
+
const edge = edges[i]
|
|
154
|
+
if (!edge) continue
|
|
155
|
+
resultEdges.push({
|
|
156
|
+
from: edge.from,
|
|
157
|
+
to: edge.to
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** @type {number[]} */
|
|
162
|
+
const executionOrderIds = []
|
|
163
|
+
/** @type {string[]} */
|
|
164
|
+
const executionOrder = []
|
|
165
|
+
const sorted = kahnTopologySort(this.graph)
|
|
166
|
+
if (sorted) {
|
|
167
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
168
|
+
const id = sorted[i]
|
|
169
|
+
if (id === undefined) continue
|
|
170
|
+
executionOrderIds.push(id)
|
|
171
|
+
executionOrder.push(namesById.get(id) ?? `Node_${id}`)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
nodes: resultNodes,
|
|
177
|
+
edges: resultEdges,
|
|
178
|
+
executionOrderIds,
|
|
179
|
+
executionOrder
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** @import { WebGLRenderer } from "./renderer.js" */
|
|
2
|
+
import { WebGLRenderDevice } from "../core/index.js";
|
|
3
|
+
import { Object3D } from "../objects/object3d.js";
|
|
4
|
+
import { abstractClass } from "../utils/index.js";
|
|
5
|
+
import { RenderItem } from "./core/index.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @abstract
|
|
9
|
+
*/
|
|
10
|
+
export class Plugin {
|
|
11
|
+
constructor() {
|
|
12
|
+
abstractClass(this, Plugin)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {WebGLRenderer} _renderer
|
|
17
|
+
*/
|
|
18
|
+
init( _renderer){}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {Object3D[]} _objects
|
|
22
|
+
* @param {WebGLRenderDevice} _device
|
|
23
|
+
* @param {WebGLRenderer} _renderer
|
|
24
|
+
*/
|
|
25
|
+
preprocess(_objects, _device, _renderer) {}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Object3D} _object
|
|
29
|
+
* @param {WebGLRenderDevice} _device
|
|
30
|
+
* @param {WebGLRenderer} _renderer
|
|
31
|
+
* @returns {RenderItem | undefined}
|
|
32
|
+
*/
|
|
33
|
+
getRenderItem(_object, _device, _renderer){
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/** @import { UniformBinder } from "./core/index.js" */
|
|
2
|
+
import { WebGLDeviceLimits, WebGLRenderDevice } from "../core/index.js"
|
|
3
|
+
import { Object3D } from "../objects/index.js"
|
|
4
|
+
import { colorShaderLib, commonShaderLib, lightShaderLib, mathShaderLib } from "../shader/index.js"
|
|
5
|
+
import { Sampler, Texture } from "../texture/index.js"
|
|
6
|
+
import { assert } from '../utils/index.js'
|
|
7
|
+
import { Caches } from "../caches/index.js"
|
|
8
|
+
import { Attribute } from "../mesh/index.js"
|
|
9
|
+
import { Plugin } from "./plugin.js"
|
|
10
|
+
import { RenderGraph, SortViewsNode } from "./graph/index.js"
|
|
11
|
+
import { Views } from "./views.js"
|
|
12
|
+
|
|
13
|
+
export class WebGLRenderer {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {Map<string, unknown>}
|
|
17
|
+
*/
|
|
18
|
+
resources = new Map()
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @readonly
|
|
22
|
+
* @type {WebGLDeviceLimits}
|
|
23
|
+
*/
|
|
24
|
+
limits
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @readonly
|
|
28
|
+
* @type {Caches}
|
|
29
|
+
*/
|
|
30
|
+
caches = new Caches()
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @readonly
|
|
34
|
+
*/
|
|
35
|
+
defaults = new Defaults()
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @readonly
|
|
39
|
+
* @type {ReadonlyMap<string,Attribute>}
|
|
40
|
+
*/
|
|
41
|
+
attributes
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @readonly
|
|
45
|
+
* @type {Map<string, string>}
|
|
46
|
+
*/
|
|
47
|
+
includes = new Map()
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @readonly
|
|
51
|
+
* @type {Map<string, string>}
|
|
52
|
+
*/
|
|
53
|
+
defines = new Map()
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @readonly
|
|
57
|
+
* @type {readonly Plugin[]}
|
|
58
|
+
*/
|
|
59
|
+
plugins
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @type {Map<string, UniformBinder>}
|
|
63
|
+
*/
|
|
64
|
+
uniformBinders = new Map()
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @readonly
|
|
68
|
+
* @type {RenderGraph}
|
|
69
|
+
*/
|
|
70
|
+
renderGraph
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {WebGLRendererOptions} options
|
|
74
|
+
*/
|
|
75
|
+
constructor({ plugins = [] } = {}) {
|
|
76
|
+
const dummy = new OffscreenCanvas(100, 100)
|
|
77
|
+
const context = dummy.getContext('webgl2')
|
|
78
|
+
|
|
79
|
+
assert(context, "Webgl context creation failed")
|
|
80
|
+
this.plugins = plugins
|
|
81
|
+
this.limits = new WebGLDeviceLimits(context)
|
|
82
|
+
this.attributes = new Map()
|
|
83
|
+
.set(Attribute.Position.name, Attribute.Position)
|
|
84
|
+
.set(Attribute.UV.name, Attribute.UV)
|
|
85
|
+
.set(Attribute.UVB.name, Attribute.UVB)
|
|
86
|
+
.set(Attribute.Normal.name, Attribute.Normal)
|
|
87
|
+
.set(Attribute.Tangent.name, Attribute.Tangent)
|
|
88
|
+
.set(Attribute.Color.name, Attribute.Color)
|
|
89
|
+
.set(Attribute.JointIndex.name, Attribute.JointIndex)
|
|
90
|
+
.set(Attribute.JointWeight.name, Attribute.JointWeight)
|
|
91
|
+
this.setResource(new Views())
|
|
92
|
+
|
|
93
|
+
this.renderGraph = new RenderGraph()
|
|
94
|
+
this.renderGraph.addNode(SortViewsNode.name, new SortViewsNode())
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
97
|
+
const plugin = /**@type {Plugin} */ (plugins[i]);
|
|
98
|
+
|
|
99
|
+
plugin.init(this)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.includes
|
|
103
|
+
.set("common", commonShaderLib)
|
|
104
|
+
.set("color", colorShaderLib)
|
|
105
|
+
.set("light", lightShaderLib)
|
|
106
|
+
.set("math", mathShaderLib)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @template {object} T
|
|
111
|
+
* @param {T} item
|
|
112
|
+
*/
|
|
113
|
+
setResource(item) {
|
|
114
|
+
this.resources.set(item.constructor.name, item)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @template T
|
|
119
|
+
* @param {import("../loader/loader.js").Constructor<T>} item
|
|
120
|
+
* @returns {T | undefined}
|
|
121
|
+
*/
|
|
122
|
+
getResource(item) {
|
|
123
|
+
return /**@type {T} */ (this.resources.get(item.name))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @param {{name: any;data: any;}} dataForm
|
|
128
|
+
* @param {WebGL2RenderingContext} context
|
|
129
|
+
*/
|
|
130
|
+
updateUBO(context, dataForm) {
|
|
131
|
+
const { data, name } = dataForm
|
|
132
|
+
const ubo = this.caches.uniformBuffers.get(name)
|
|
133
|
+
|
|
134
|
+
if (!ubo) return
|
|
135
|
+
|
|
136
|
+
ubo.update(context, data)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {Object3D[]} objects
|
|
141
|
+
* @param {WebGLRenderDevice} renderDevice
|
|
142
|
+
*/
|
|
143
|
+
render(objects, renderDevice) {
|
|
144
|
+
const views = this.getResource(Views)
|
|
145
|
+
|
|
146
|
+
assert(views, "Views resource missing")
|
|
147
|
+
views.clear()
|
|
148
|
+
|
|
149
|
+
for (let i = 0; i < objects.length; i++) {
|
|
150
|
+
const object = /**@type {Object3D} */ (objects[i])
|
|
151
|
+
|
|
152
|
+
object.traverseDFS((object) => {
|
|
153
|
+
object.update()
|
|
154
|
+
return true
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for (let i = 0; i < this.plugins.length; i++) {
|
|
159
|
+
const plugin = /**@type {Plugin} */ (this.plugins[i]);
|
|
160
|
+
|
|
161
|
+
plugin.preprocess(objects, renderDevice, this)
|
|
162
|
+
}
|
|
163
|
+
this.renderGraph.execute({
|
|
164
|
+
renderer: this,
|
|
165
|
+
objects,
|
|
166
|
+
renderDevice
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @typedef WebGLRendererOptions
|
|
173
|
+
* @property {Plugin[]} [plugins]
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
export class Defaults {
|
|
177
|
+
texture2D = Texture.default()
|
|
178
|
+
textureSampler = Sampler.default()
|
|
179
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** @import { View } from "./core/index.js" */
|
|
2
|
+
|
|
3
|
+
export class Views {
|
|
4
|
+
/**
|
|
5
|
+
* @private
|
|
6
|
+
* @type {View[]}
|
|
7
|
+
*/
|
|
8
|
+
inner = []
|
|
9
|
+
|
|
10
|
+
clear() {
|
|
11
|
+
this.inner.length = 0
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {...View} views
|
|
16
|
+
*/
|
|
17
|
+
push(...views) {
|
|
18
|
+
this.inner.push(...views)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @returns {View[]}
|
|
23
|
+
*/
|
|
24
|
+
items() {
|
|
25
|
+
return this.inner
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RenderTarget } from "./rendertarget.js";
|
|
2
|
+
|
|
3
|
+
export class CanvasTarget extends RenderTarget {
|
|
4
|
+
/**
|
|
5
|
+
* @readonly
|
|
6
|
+
* @type {HTMLCanvasElement}
|
|
7
|
+
*/
|
|
8
|
+
canvas
|
|
9
|
+
/**
|
|
10
|
+
* @param {HTMLCanvasElement} canvas
|
|
11
|
+
*/
|
|
12
|
+
constructor(canvas) {
|
|
13
|
+
super(canvas.width, canvas.height, 1)
|
|
14
|
+
this.canvas = canvas
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @override
|
|
19
|
+
*/
|
|
20
|
+
changed() {
|
|
21
|
+
const resized = this.canvas.width !== this.width ||
|
|
22
|
+
this.canvas.height !== this.height
|
|
23
|
+
|
|
24
|
+
if (resized) {
|
|
25
|
+
this.width = this.canvas.width
|
|
26
|
+
this.height = this.canvas.height
|
|
27
|
+
}
|
|
28
|
+
return super.changed()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { TextureFormat } from "../constants/index.js";
|
|
2
|
+
import { Texture } from "../texture/index.js"
|
|
3
|
+
import { RenderTarget } from "./rendertarget.js";
|
|
4
|
+
|
|
5
|
+
export class ImageRenderTarget extends RenderTarget {
|
|
6
|
+
/**
|
|
7
|
+
* @type {Texture[]}
|
|
8
|
+
*/
|
|
9
|
+
color
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {Texture | undefined}
|
|
13
|
+
*/
|
|
14
|
+
depthTexture
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @type {TextureFormat | undefined}
|
|
18
|
+
*/
|
|
19
|
+
internalDepthStencil
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
24
|
+
layer
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {ImageRenderTargetOptions} options
|
|
28
|
+
*/
|
|
29
|
+
constructor({
|
|
30
|
+
color = [],
|
|
31
|
+
depthTexture,
|
|
32
|
+
width,
|
|
33
|
+
height,
|
|
34
|
+
depth = 1,
|
|
35
|
+
layer = 0,
|
|
36
|
+
internalDepthStencil
|
|
37
|
+
}) {
|
|
38
|
+
super(width, height, depth)
|
|
39
|
+
this.layer = layer
|
|
40
|
+
this.color = color
|
|
41
|
+
this.depthTexture = depthTexture
|
|
42
|
+
this.internalDepthStencil = internalDepthStencil
|
|
43
|
+
|
|
44
|
+
for (const color of this.color) {
|
|
45
|
+
color.data = undefined
|
|
46
|
+
color.width = width
|
|
47
|
+
color.height = height
|
|
48
|
+
color.depth = depth
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (this.depthTexture) {
|
|
52
|
+
this.depthTexture.data = undefined
|
|
53
|
+
this.depthTexture.width = width
|
|
54
|
+
this.depthTexture.height = height
|
|
55
|
+
this.depthTexture.depth = depth
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @override
|
|
61
|
+
*/
|
|
62
|
+
get width() {
|
|
63
|
+
return super.width
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @override
|
|
68
|
+
* @param {number} value
|
|
69
|
+
*/
|
|
70
|
+
set width(value) {
|
|
71
|
+
super.width = value
|
|
72
|
+
this.color.forEach((attachment) => {
|
|
73
|
+
attachment.width = value
|
|
74
|
+
})
|
|
75
|
+
if (this.depthTexture) {
|
|
76
|
+
this.depthTexture.width = value
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @override
|
|
82
|
+
*/
|
|
83
|
+
get height() {
|
|
84
|
+
return super.height
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @override
|
|
89
|
+
* @param {number} value
|
|
90
|
+
*/
|
|
91
|
+
set height(value) {
|
|
92
|
+
super.height = value
|
|
93
|
+
this.color.forEach((attachment) => {
|
|
94
|
+
attachment.height = value
|
|
95
|
+
})
|
|
96
|
+
if (this.depthTexture) {
|
|
97
|
+
this.depthTexture.height = value
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @override
|
|
103
|
+
*/
|
|
104
|
+
get depth() {
|
|
105
|
+
return super.depth
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @override
|
|
110
|
+
* @param {number} value
|
|
111
|
+
*/
|
|
112
|
+
set depth(value) {
|
|
113
|
+
super.depth = value
|
|
114
|
+
this.color.forEach((attachment) => {
|
|
115
|
+
attachment.depth = value
|
|
116
|
+
})
|
|
117
|
+
if (this.depthTexture) {
|
|
118
|
+
this.depthTexture.depth = value
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @typedef ImageRenderTargetOptions
|
|
125
|
+
* @property {Texture[]} [color]
|
|
126
|
+
* @property {Texture} [depthTexture]
|
|
127
|
+
* @property {TextureFormat} [internalDepthStencil]
|
|
128
|
+
* @property {number} width
|
|
129
|
+
* @property {number} height
|
|
130
|
+
* @property {number} [depth]
|
|
131
|
+
* @property {number} [layer]
|
|
132
|
+
*/
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Color } from "../math/index.js";
|
|
2
|
+
import { ViewRectangle, Range } from "../utils/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @abstract
|
|
6
|
+
*/
|
|
7
|
+
export class RenderTarget {
|
|
8
|
+
/**
|
|
9
|
+
* @protected
|
|
10
|
+
* @type {boolean}
|
|
11
|
+
*/
|
|
12
|
+
_change = false
|
|
13
|
+
/**
|
|
14
|
+
* @type {number}
|
|
15
|
+
*/
|
|
16
|
+
#width = 0
|
|
17
|
+
/**
|
|
18
|
+
* @type {number}
|
|
19
|
+
*/
|
|
20
|
+
#height = 0
|
|
21
|
+
/**
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
24
|
+
#depth = 0
|
|
25
|
+
/**
|
|
26
|
+
* @type {Color | undefined}
|
|
27
|
+
*/
|
|
28
|
+
clearColor = new Color(0, 0, 0, 1)
|
|
29
|
+
/**
|
|
30
|
+
* @type {number | undefined}
|
|
31
|
+
*/
|
|
32
|
+
clearDepth = 1
|
|
33
|
+
/**
|
|
34
|
+
* @type {number | undefined}
|
|
35
|
+
*/
|
|
36
|
+
clearStencil = 0
|
|
37
|
+
/**
|
|
38
|
+
* @type {ViewRectangle}
|
|
39
|
+
*/
|
|
40
|
+
viewport = new ViewRectangle()
|
|
41
|
+
/**
|
|
42
|
+
* @type {ViewRectangle | undefined}
|
|
43
|
+
*/
|
|
44
|
+
scissor
|
|
45
|
+
/**
|
|
46
|
+
* @type {Range | undefined}
|
|
47
|
+
*/
|
|
48
|
+
depthRange
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {number} width
|
|
52
|
+
* @param {number} height
|
|
53
|
+
* @param {number} depth
|
|
54
|
+
*/
|
|
55
|
+
constructor(width, height, depth) {
|
|
56
|
+
this.#width = width
|
|
57
|
+
this.#height = height
|
|
58
|
+
this.#depth = depth
|
|
59
|
+
}
|
|
60
|
+
get width() {
|
|
61
|
+
return this.#width
|
|
62
|
+
}
|
|
63
|
+
set width(value) {
|
|
64
|
+
this.#width = value
|
|
65
|
+
this._change = true
|
|
66
|
+
}
|
|
67
|
+
get height() {
|
|
68
|
+
return this.#height
|
|
69
|
+
}
|
|
70
|
+
set height(value) {
|
|
71
|
+
this.#height = value
|
|
72
|
+
this._change = true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get depth() {
|
|
76
|
+
return this.#depth
|
|
77
|
+
}
|
|
78
|
+
set depth(value) {
|
|
79
|
+
this.#depth = value
|
|
80
|
+
this._change = true
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
changed() {
|
|
84
|
+
const prev = this._change
|
|
85
|
+
this._change = false
|
|
86
|
+
|
|
87
|
+
return prev
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
precision mediump float;
|
|
2
|
+
precision mediump sampler2DArray;
|
|
3
|
+
|
|
4
|
+
#include <common>
|
|
5
|
+
|
|
6
|
+
struct BasicMaterial {
|
|
7
|
+
vec4 color;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
#ifdef VERTEX_UVS
|
|
11
|
+
in vec2 v_uv;
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
out vec4 fragment_color;
|
|
15
|
+
|
|
16
|
+
uniform MaterialBlock {
|
|
17
|
+
BasicMaterial material;
|
|
18
|
+
};
|
|
19
|
+
uniform sampler2D mainTexture;
|
|
20
|
+
|
|
21
|
+
void main(){
|
|
22
|
+
vec3 base_color = material.color.rgb.rgb;
|
|
23
|
+
float opacity = material.color.a;
|
|
24
|
+
|
|
25
|
+
#ifdef VERTEX_UVS
|
|
26
|
+
vec4 sample_color = texture(mainTexture, v_uv);
|
|
27
|
+
base_color *= sample_color.rgb;
|
|
28
|
+
#endif
|
|
29
|
+
fragment_color = vec4(base_color, opacity);
|
|
30
|
+
}
|