ris-framework 0.2.0-dev.13 → 0.2.0-dev.16
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/CHANGELOG.md +43 -2
- package/README.md +13 -5
- package/dist/api/IFramework.d.ts +3 -3
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/_export.d.ts +3 -0
- package/dist/api/_export.d.ts.map +1 -1
- package/dist/api/camera/CameraTransformUtilities.d.ts +65 -0
- package/dist/api/camera/CameraTransformUtilities.d.ts.map +1 -0
- package/dist/api/camera/ICamera.d.ts +36 -2
- package/dist/api/camera/ICamera.d.ts.map +1 -1
- package/dist/api/camera/OrbitCamera.d.ts +22 -14
- package/dist/api/camera/OrbitCamera.d.ts.map +1 -1
- package/dist/api/camera/OrthographicCamera.d.ts +33 -11
- package/dist/api/camera/OrthographicCamera.d.ts.map +1 -1
- package/dist/api/camera/PerspectiveCamera.d.ts +32 -18
- package/dist/api/camera/PerspectiveCamera.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +2 -2
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +2 -2
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/lights/AmbientLight.d.ts +7 -2
- package/dist/api/lights/AmbientLight.d.ts.map +1 -1
- package/dist/api/lights/DirectionalLight.d.ts +18 -4
- package/dist/api/lights/DirectionalLight.d.ts.map +1 -1
- package/dist/api/lights/ILight.d.ts +18 -0
- package/dist/api/lights/ILight.d.ts.map +1 -0
- package/dist/api/lights/PointLight.d.ts +17 -4
- package/dist/api/lights/PointLight.d.ts.map +1 -1
- package/dist/api/lights/_export.d.ts +1 -0
- package/dist/api/lights/_export.d.ts.map +1 -1
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +2 -2
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -1
- package/dist/api/material/IMaterial.d.ts +7 -0
- package/dist/api/material/IMaterial.d.ts.map +1 -1
- package/dist/api/material/IMaterialFactory.d.ts +3 -2
- package/dist/api/material/IMaterialFactory.d.ts.map +1 -1
- package/dist/api/material/IUnlitMaterialDescriptor.d.ts +16 -0
- package/dist/api/material/IUnlitMaterialDescriptor.d.ts.map +1 -0
- package/dist/api/material/MaterialFactory.d.ts +3 -2
- package/dist/api/material/MaterialFactory.d.ts.map +1 -1
- package/dist/api/material/SpriteMaterial.d.ts +3 -0
- package/dist/api/material/SpriteMaterial.d.ts.map +1 -1
- package/dist/api/material/UnlitMaterial.d.ts +5 -12
- package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
- package/dist/api/material/_export.d.ts +1 -1
- package/dist/api/material/_export.d.ts.map +1 -1
- package/dist/api/meshes/IRenderableMesh.d.ts +3 -14
- package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -1
- package/dist/api/meshes/RenderableMesh.d.ts +5 -20
- package/dist/api/meshes/RenderableMesh.d.ts.map +1 -1
- package/dist/api/rendering/IGraphicsDevice.d.ts +2 -2
- package/dist/api/rendering/IGraphicsDevice.d.ts.map +1 -1
- package/dist/api/rendering/IRenderer.d.ts +13 -6
- package/dist/api/rendering/IRenderer.d.ts.map +1 -1
- package/dist/api/rendering/_export-rendering.d.ts +1 -0
- package/dist/api/rendering/_export-rendering.d.ts.map +1 -1
- package/dist/api/rendering/enums.d.ts +5 -5
- package/dist/api/rendering/enums.d.ts.map +1 -1
- package/dist/api/rendering/primitive/IPrimitiveStateDescriptor.d.ts +24 -0
- package/dist/api/rendering/primitive/IPrimitiveStateDescriptor.d.ts.map +1 -0
- package/dist/api/rendering/primitive/_export.d.ts +1 -1
- package/dist/api/rendering/primitive/_export.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/IMainRenderTargetRenderPipeline.d.ts +5 -0
- package/dist/api/rendering/render-pipelines/IMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/api/rendering/texture/ITextureDescriptor.d.ts +53 -0
- package/dist/api/rendering/texture/ITextureDescriptor.d.ts.map +1 -0
- package/dist/api/rendering/texture/ITextureFactory.d.ts +5 -3
- package/dist/api/rendering/texture/ITextureFactory.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureUtilities.d.ts +29 -21
- package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
- package/dist/api/rendering/texture/_export-texture.d.ts +1 -1
- package/dist/api/rendering/texture/_export-texture.d.ts.map +1 -1
- package/dist/api/scene/ISceneObject.d.ts +12 -0
- package/dist/api/scene/ISceneObject.d.ts.map +1 -0
- package/dist/api/scene/Scene.d.ts +17 -6
- package/dist/api/scene/Scene.d.ts.map +1 -1
- package/dist/api/scene/node/Node.d.ts +26 -0
- package/dist/api/scene/node/Node.d.ts.map +1 -0
- package/dist/api/scene/node/TransformNode.d.ts +46 -0
- package/dist/api/scene/node/TransformNode.d.ts.map +1 -0
- package/dist/core/material/UnlitMaterialDescriptorUtilities.d.ts +17 -0
- package/dist/core/material/UnlitMaterialDescriptorUtilities.d.ts.map +1 -0
- package/dist/core/rendering/AGraphicsDevice.d.ts +2 -2
- package/dist/core/rendering/AGraphicsDevice.d.ts.map +1 -1
- package/dist/core/rendering/ARenderer.d.ts +7 -1
- package/dist/core/rendering/ARenderer.d.ts.map +1 -1
- package/dist/core/rendering/primitive/PrimitiveStateDescriptorUtilities.d.ts +15 -0
- package/dist/core/rendering/primitive/PrimitiveStateDescriptorUtilities.d.ts.map +1 -0
- package/dist/core/rendering/texture/TextureDescriptorUtilities.d.ts +14 -0
- package/dist/core/rendering/texture/TextureDescriptorUtilities.d.ts.map +1 -0
- package/dist/core/rendering/texture/texture.d.ts +3 -2
- package/dist/core/rendering/texture/texture.d.ts.map +1 -1
- package/dist/index.js +959 -540
- package/dist/webgl/WebGlGraphicsDevice.d.ts +2 -2
- package/dist/webgl/WebGlGraphicsDevice.d.ts.map +1 -1
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -1
- package/dist/webgl/primitive/WebGlPrimitiveState.d.ts +3 -3
- package/dist/webgl/primitive/WebGlPrimitiveState.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +8 -0
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTexture2D.d.ts +3 -2
- package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTextureFactory.d.ts +2 -9
- package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts +2 -2
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -1
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +2 -2
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -1
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +5 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts +3 -2
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -1
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +2 -2
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Framework.ts +2 -2
- package/src/api/IFramework.ts +3 -3
- package/src/api/_export.ts +3 -0
- package/src/api/camera/CameraTransformUtilities.ts +182 -0
- package/src/api/camera/ICamera.ts +42 -2
- package/src/api/camera/OrbitCamera.ts +71 -38
- package/src/api/camera/OrthographicCamera.ts +71 -28
- package/src/api/camera/PerspectiveCamera.ts +69 -33
- package/src/api/content/ContentManager.ts +18 -12
- package/src/api/content/IContentManager.ts +2 -2
- package/src/api/lights/AmbientLight.ts +8 -2
- package/src/api/lights/DirectionalLight.ts +30 -5
- package/src/api/lights/ILight.ts +22 -0
- package/src/api/lights/PointLight.ts +26 -5
- package/src/api/lights/_export.ts +1 -0
- package/src/api/material/ForwardBlinnPhongMaterial.ts +2 -2
- package/src/api/material/IMaterial.ts +8 -0
- package/src/api/material/IMaterialFactory.ts +3 -2
- package/src/api/material/IUnlitMaterialDescriptor.ts +18 -0
- package/src/api/material/MaterialFactory.ts +4 -3
- package/src/api/material/SpriteMaterial.ts +4 -0
- package/src/api/material/UnlitMaterial.ts +11 -18
- package/src/api/material/_export.ts +1 -1
- package/src/api/meshes/IRenderableMesh.ts +3 -18
- package/src/api/meshes/RenderableMesh.ts +15 -45
- package/src/api/rendering/IGraphicsDevice.ts +2 -2
- package/src/api/rendering/IRenderer.ts +14 -6
- package/src/api/rendering/_export-rendering.ts +2 -1
- package/src/api/rendering/enums.ts +5 -5
- package/src/api/rendering/primitive/IPrimitiveStateDescriptor.ts +27 -0
- package/src/api/rendering/primitive/_export.ts +1 -1
- package/src/api/rendering/render-pipelines/IMainRenderTargetRenderPipeline.ts +6 -0
- package/src/api/rendering/texture/ITextureDescriptor.ts +62 -0
- package/src/api/rendering/texture/ITextureFactory.ts +5 -3
- package/src/api/rendering/texture/TextureUtilities.ts +59 -61
- package/src/api/rendering/texture/_export-texture.ts +1 -1
- package/src/api/scene/ISceneObject.ts +13 -0
- package/src/api/scene/Scene.ts +52 -11
- package/src/api/scene/node/Node.ts +54 -0
- package/src/api/scene/node/TransformNode.ts +88 -0
- package/src/core/material/UnlitMaterialDescriptorUtilities.ts +21 -0
- package/src/core/rendering/AGraphicsDevice.ts +2 -2
- package/src/core/rendering/ARenderer.ts +26 -4
- package/src/core/rendering/primitive/PrimitiveStateDescriptorUtilities.ts +22 -0
- package/src/core/rendering/texture/TextureDescriptorUtilities.ts +28 -0
- package/src/core/rendering/texture/texture.ts +2 -2
- package/src/main.ts +5 -4
- package/src/webgl/WebGlGraphicsDevice.ts +2 -3
- package/src/webgl/lights/WebGlLightsBuffer.ts +21 -8
- package/src/webgl/primitive/WebGlPrimitiveState.ts +8 -6
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +14 -0
- package/src/webgl/texture/WebGlTexture2D.ts +9 -8
- package/src/webgl/texture/WebGlTextureFactory.ts +62 -65
- package/src/webgl/utilities/WebGlErrorUtilities.ts +3 -2
- package/src/webgl/utilities/WebGlTextureUtilities.ts +10 -4
- package/src/webgpu/WebGpuGraphicsDevice.ts +3 -3
- package/src/webgpu/primitive/WebGpuPrimitiveState.ts +7 -5
- package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +6 -0
- package/src/webgpu/texture/WebGpuTexture2D.ts +10 -9
- package/src/webgpu/texture/WebGpuTextureFactory.ts +20 -17
- package/dist/api/material/ICameraMaterial.d.ts +0 -18
- package/dist/api/material/ICameraMaterial.d.ts.map +0 -1
- package/dist/api/rendering/primitive/PrimitiveStateDescriptor.d.ts +0 -24
- package/dist/api/rendering/primitive/PrimitiveStateDescriptor.d.ts.map +0 -1
- package/dist/api/rendering/texture/TextureDescriptor.d.ts +0 -42
- package/dist/api/rendering/texture/TextureDescriptor.d.ts.map +0 -1
- package/src/api/material/ICameraMaterial.ts +0 -22
- package/src/api/rendering/primitive/PrimitiveStateDescriptor.ts +0 -27
- package/src/api/rendering/texture/TextureDescriptor.ts +0 -52
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {Color} from "../data/Color.ts";
|
|
2
2
|
import {createLightId} from "./LightId.ts";
|
|
3
3
|
import type {Scene} from "../scene/Scene.ts";
|
|
4
|
+
import type {ILight} from "./ILight.ts";
|
|
5
|
+
import {TransformNode} from "../scene/node/TransformNode.ts";
|
|
4
6
|
|
|
5
7
|
/** The descriptor for an ambient light. All fields are optional. */
|
|
6
8
|
export interface AmbientLightDescriptor {
|
|
@@ -18,11 +20,12 @@ export interface AmbientLightDescriptor {
|
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
|
-
* The ambient light. Plain data: it has no GPU resources.
|
|
23
|
+
* The ambient light. Plain data: it has no GPU resources. It has a {@link transform} (so it can live in `scene.nodes`),
|
|
24
|
+
* but the transform has no effect on the lighting.
|
|
22
25
|
* Put it into a {@link LightsBuffer} to use it in shaders.
|
|
23
26
|
* @public
|
|
24
27
|
*/
|
|
25
|
-
export class AmbientLight {
|
|
28
|
+
export class AmbientLight implements ILight {
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* The constructor.
|
|
@@ -39,6 +42,9 @@ export class AmbientLight {
|
|
|
39
42
|
scene?.add(this);
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
/** The transform. It has no effect on an ambient light. */
|
|
46
|
+
public transform: TransformNode = new TransformNode();
|
|
47
|
+
|
|
42
48
|
/** The unique id of this light. */
|
|
43
49
|
public readonly id: number;
|
|
44
50
|
|
|
@@ -2,6 +2,11 @@ import {vec3} from "gl-matrix";
|
|
|
2
2
|
import {Color} from "../data/Color.ts";
|
|
3
3
|
import {createLightId} from "./LightId.ts";
|
|
4
4
|
import type {Scene} from "../scene/Scene.ts";
|
|
5
|
+
import type {ILight} from "./ILight.ts";
|
|
6
|
+
import {TransformNode} from "../scene/node/TransformNode.ts";
|
|
7
|
+
import {CameraTransformUtilities} from "../camera/CameraTransformUtilities.ts";
|
|
8
|
+
|
|
9
|
+
const _target = vec3.create();
|
|
5
10
|
|
|
6
11
|
/** The descriptor for a directional light. All fields are optional. */
|
|
7
12
|
export interface DirectionalLightDescriptor {
|
|
@@ -17,15 +22,16 @@ export interface DirectionalLightDescriptor {
|
|
|
17
22
|
/** Multiplies the colour. Defaults to 1. */
|
|
18
23
|
intensity?: number;
|
|
19
24
|
|
|
20
|
-
/** The direction in which the light travels. Defaults to straight down, (0, -1, 0). */
|
|
25
|
+
/** The initial world direction in which the light travels (see {@link DirectionalLight.setDirection}). Defaults to straight down, (0, -1, 0). */
|
|
21
26
|
direction?: vec3;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
30
|
* The directional light. Plain data: it has no GPU resources.
|
|
31
|
+
* The light travels along its transform's forward axis (local -Z), in world space; position and scale are ignored.
|
|
26
32
|
* @public
|
|
27
33
|
*/
|
|
28
|
-
export class DirectionalLight {
|
|
34
|
+
export class DirectionalLight implements ILight {
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
37
|
* The constructor.
|
|
@@ -38,7 +44,7 @@ export class DirectionalLight {
|
|
|
38
44
|
this.name = descriptor?.name;
|
|
39
45
|
this.color = descriptor?.color?.copy() ?? Color.white();
|
|
40
46
|
this.intensity = descriptor?.intensity ?? 1;
|
|
41
|
-
this.
|
|
47
|
+
this.setDirection(descriptor?.direction ?? [0, -1, 0]);
|
|
42
48
|
|
|
43
49
|
scene?.add(this);
|
|
44
50
|
}
|
|
@@ -55,6 +61,25 @@ export class DirectionalLight {
|
|
|
55
61
|
/** Multiplies {@link color} when written to the lights buffer. */
|
|
56
62
|
public intensity: number;
|
|
57
63
|
|
|
58
|
-
/** The
|
|
59
|
-
public
|
|
64
|
+
/** The transform. Its world rotation sets the direction (forward is -Z). */
|
|
65
|
+
public transform: TransformNode = new TransformNode();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Rotates the transform so the light travels along a world-space direction (converted into the parent's space
|
|
69
|
+
* when parented). A zero vector leaves the rotation unchanged.
|
|
70
|
+
* @param direction The world direction; it does not need to be normalized.
|
|
71
|
+
*/
|
|
72
|
+
public setDirection(direction: vec3): void {
|
|
73
|
+
const m = this.transform.modelMatrix;
|
|
74
|
+
vec3.set(_target, m[12] + direction[0], m[13] + direction[1], m[14] + direction[2]);
|
|
75
|
+
CameraTransformUtilities.aimTransform(this.transform, _target, [0, 1, 0]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Gets the world-space direction in which the light travels (unit length), derived from the transform.
|
|
80
|
+
* @param out The optional output vector.
|
|
81
|
+
*/
|
|
82
|
+
public getDirection(out: vec3 = vec3.create()): vec3 {
|
|
83
|
+
return CameraTransformUtilities.forwardFromWorld(out, this.transform.modelMatrix);
|
|
84
|
+
}
|
|
60
85
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {Color} from "../data/Color.ts";
|
|
2
|
+
import type {ISceneObject} from "../scene/ISceneObject.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The common interface of all lights. A light is a scene object: its `transform` is the single source of truth
|
|
6
|
+
* for where it is (point lights) or where it points (directional lights). The ambient light ignores its transform.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ILight extends ISceneObject {
|
|
10
|
+
|
|
11
|
+
/** The unique id of this light. */
|
|
12
|
+
readonly id: number;
|
|
13
|
+
|
|
14
|
+
/** The optional name for a light. */
|
|
15
|
+
name?: string;
|
|
16
|
+
|
|
17
|
+
/** The light colour. Alpha is ignored. */
|
|
18
|
+
color: Color;
|
|
19
|
+
|
|
20
|
+
/** Multiplies {@link color} when written to the lights buffer. */
|
|
21
|
+
intensity: number;
|
|
22
|
+
}
|
|
@@ -2,6 +2,9 @@ import {vec3} from "gl-matrix";
|
|
|
2
2
|
import {Color} from "../data/Color.ts";
|
|
3
3
|
import {createLightId} from "./LightId.ts";
|
|
4
4
|
import type {Scene} from "../scene/Scene.ts";
|
|
5
|
+
import type {ILight} from "./ILight.ts";
|
|
6
|
+
import {TransformNode} from "../scene/node/TransformNode.ts";
|
|
7
|
+
import {CameraTransformUtilities} from "../camera/CameraTransformUtilities.ts";
|
|
5
8
|
|
|
6
9
|
/** The descriptor for a point light. All fields are optional. */
|
|
7
10
|
export interface PointLightDescriptor {
|
|
@@ -17,7 +20,7 @@ export interface PointLightDescriptor {
|
|
|
17
20
|
/** Multiplies the colour. Defaults to 1. */
|
|
18
21
|
intensity?: number;
|
|
19
22
|
|
|
20
|
-
/**
|
|
23
|
+
/** The initial world position (see {@link PointLight.setPosition}). Defaults to the origin. */
|
|
21
24
|
position?: vec3;
|
|
22
25
|
|
|
23
26
|
/** Constant attenuation term. Defaults to 1. */
|
|
@@ -32,10 +35,11 @@ export interface PointLightDescriptor {
|
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* The point light. Plain data: it has no GPU resources.
|
|
38
|
+
* Its position is the world position of its {@link transform}.
|
|
35
39
|
* Attenuation is `1 / (constant + linear * d + quadratic * d²)` for distance `d`.
|
|
36
40
|
* @public
|
|
37
41
|
*/
|
|
38
|
-
export class PointLight {
|
|
42
|
+
export class PointLight implements ILight {
|
|
39
43
|
|
|
40
44
|
/** The default constant attenuation. */
|
|
41
45
|
public static readonly DEFAULT_CONSTANT = 1;
|
|
@@ -57,7 +61,7 @@ export class PointLight {
|
|
|
57
61
|
this.name = descriptor?.name;
|
|
58
62
|
this.color = descriptor?.color?.copy() ?? Color.white();
|
|
59
63
|
this.intensity = descriptor?.intensity ?? 1;
|
|
60
|
-
this.position
|
|
64
|
+
vec3.copy(this.transform.position, descriptor?.position ?? [0, 0, 0]);
|
|
61
65
|
this.constant = descriptor?.constant ?? PointLight.DEFAULT_CONSTANT;
|
|
62
66
|
this.linear = descriptor?.linear ?? PointLight.DEFAULT_LINEAR;
|
|
63
67
|
this.quadratic = descriptor?.quadratic ?? PointLight.DEFAULT_QUADRATIC;
|
|
@@ -77,8 +81,25 @@ export class PointLight {
|
|
|
77
81
|
/** Multiplies {@link color} when written to the lights buffer. */
|
|
78
82
|
public intensity: number;
|
|
79
83
|
|
|
80
|
-
/**
|
|
81
|
-
public
|
|
84
|
+
/** The transform. Its world position is the light position. */
|
|
85
|
+
public transform: TransformNode = new TransformNode();
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Moves the light to a world position (converted into the parent's space when parented).
|
|
89
|
+
* @param position The world position.
|
|
90
|
+
*/
|
|
91
|
+
public setPosition(position: vec3): void {
|
|
92
|
+
CameraTransformUtilities.setWorldPosition(this.transform, position);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets the world position of the light, read from the transform.
|
|
97
|
+
* @param out The optional output vector.
|
|
98
|
+
*/
|
|
99
|
+
public getPosition(out: vec3 = vec3.create()): vec3 {
|
|
100
|
+
const m = this.transform.modelMatrix;
|
|
101
|
+
return vec3.set(out, m[12], m[13], m[14]);
|
|
102
|
+
}
|
|
82
103
|
|
|
83
104
|
/** Constant attenuation term. */
|
|
84
105
|
public constant: number;
|
|
@@ -14,7 +14,7 @@ import type {LightsBuffer} from "../lights/LightsBuffer.ts";
|
|
|
14
14
|
import type {AmbientLight} from "../lights/AmbientLight.ts";
|
|
15
15
|
import type {DirectionalLight} from "../lights/DirectionalLight.ts";
|
|
16
16
|
import type {PointLight} from "../lights/PointLight.ts";
|
|
17
|
-
import type {
|
|
17
|
+
import type {IMaterial} from "./IMaterial.ts";
|
|
18
18
|
import type {ILightsMaterial} from "./ILightsMaterial.ts";
|
|
19
19
|
import type {IForwardBlinnPhongRenderPipeline} from "../rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts";
|
|
20
20
|
|
|
@@ -39,7 +39,7 @@ export class ForwardBlinnPhongMaterialDescriptor {
|
|
|
39
39
|
* The Blinn-Phong material with forward calculated lighting.
|
|
40
40
|
* @public
|
|
41
41
|
*/
|
|
42
|
-
export class ForwardBlinnPhongMaterial implements
|
|
42
|
+
export class ForwardBlinnPhongMaterial implements IMaterial, ILightsMaterial {
|
|
43
43
|
|
|
44
44
|
/** The directional light slots of the material's lights buffer and shader. */
|
|
45
45
|
public static readonly MAX_DIRECTIONAL_LIGHTS = 3;
|
|
@@ -4,6 +4,7 @@ import type { IRenderableMesh } from "../meshes/IRenderableMesh.ts";
|
|
|
4
4
|
import type { IVertexBuffer } from "../rendering/buffers/IVertexBuffer.ts";
|
|
5
5
|
import type { IIndexBuffer } from "../rendering/buffers/IIndexBuffer.ts";
|
|
6
6
|
import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
7
|
+
import type {ICamera} from "../camera/ICamera.ts";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* The material interface.
|
|
@@ -21,6 +22,13 @@ export interface IMaterial extends IDisposable {
|
|
|
21
22
|
/** The geometry format required by the material.*/
|
|
22
23
|
readonly geometryFormat: GeometryFormat;
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* The camera.
|
|
27
|
+
* Setting it binds the camera's buffers, if material uses them.
|
|
28
|
+
* For some materials, setting camera plays no role as they might not use camera.
|
|
29
|
+
*/
|
|
30
|
+
camera?: ICamera;
|
|
31
|
+
|
|
24
32
|
/**
|
|
25
33
|
* Called before rendering.
|
|
26
34
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {InspectTextureMipsMaterial} from "./InspectTextureMipsMaterial.ts";
|
|
2
2
|
import type {SpriteMaterial, SpriteMaterialDescriptor} from "./SpriteMaterial.ts";
|
|
3
|
-
import {UnlitMaterial
|
|
3
|
+
import {UnlitMaterial} from "./UnlitMaterial.ts";
|
|
4
|
+
import type {IUnlitMaterialDescriptor} from "./IUnlitMaterialDescriptor.ts";
|
|
4
5
|
import type {ForwardBlinnPhongMaterial, ForwardBlinnPhongMaterialDescriptor} from "./ForwardBlinnPhongMaterial.ts";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -19,7 +20,7 @@ export interface IMaterialFactory {
|
|
|
19
20
|
* @param descriptor The optional additional configuration options for material, such as rendering options.
|
|
20
21
|
* @returns The Unlit Material.
|
|
21
22
|
*/
|
|
22
|
-
createUnlitMaterial(descriptor?:
|
|
23
|
+
createUnlitMaterial(descriptor?: IUnlitMaterialDescriptor): UnlitMaterial;
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Creates a sprite material.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type {IPrimitiveState} from "../rendering/primitive/IPrimitiveState.ts";
|
|
2
|
+
import type {ICamera} from "../camera/ICamera.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The descriptor for an unlit material. All fields are optional.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface IUnlitMaterialDescriptor {
|
|
9
|
+
|
|
10
|
+
/** The primitive state. By default, the render pipeline's default (back-face culled, counter-clockwise triangles). */
|
|
11
|
+
primitiveState?: IPrimitiveState;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The camera used to render this material. By default, none: a zero projection view buffer is bound
|
|
15
|
+
* until a camera is assigned (a scene assigns its camera).
|
|
16
|
+
*/
|
|
17
|
+
camera?: ICamera;
|
|
18
|
+
}
|
|
@@ -2,7 +2,8 @@ import {InspectTextureMipsMaterial} from "./InspectTextureMipsMaterial.ts";
|
|
|
2
2
|
import type { IFramework } from "../IFramework.ts";
|
|
3
3
|
import type { IMaterialFactory } from "./IMaterialFactory.ts";
|
|
4
4
|
import {SpriteMaterial, type SpriteMaterialDescriptor} from "./SpriteMaterial.ts";
|
|
5
|
-
import {UnlitMaterial
|
|
5
|
+
import {UnlitMaterial} from "./UnlitMaterial.ts";
|
|
6
|
+
import type {IUnlitMaterialDescriptor} from "./IUnlitMaterialDescriptor.ts";
|
|
6
7
|
import {ForwardBlinnPhongMaterial, type ForwardBlinnPhongMaterialDescriptor} from "./ForwardBlinnPhongMaterial.ts";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -23,8 +24,8 @@ export class MaterialFactory implements IMaterialFactory {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/** @inheritDoc */
|
|
26
|
-
public createUnlitMaterial(descriptor
|
|
27
|
-
return new UnlitMaterial(this._framework, descriptor
|
|
27
|
+
public createUnlitMaterial(descriptor?: IUnlitMaterialDescriptor): UnlitMaterial {
|
|
28
|
+
return new UnlitMaterial(this._framework, descriptor);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/** @inheritDoc */
|
|
@@ -8,6 +8,7 @@ import type { IFramework } from "../IFramework.ts";
|
|
|
8
8
|
import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
9
9
|
import type { ISpriteRenderPipeline } from "../rendering/render-pipelines/ISpriteRenderPipeline.ts";
|
|
10
10
|
import type { IMaterial } from "./IMaterial.ts";
|
|
11
|
+
import type { ICamera } from "../camera/ICamera.ts";
|
|
11
12
|
|
|
12
13
|
/** The sprite material descriptor. */
|
|
13
14
|
export interface SpriteMaterialDescriptor {
|
|
@@ -27,6 +28,9 @@ export interface SpriteMaterialDescriptor {
|
|
|
27
28
|
*/
|
|
28
29
|
export class SpriteMaterial implements IMaterial {
|
|
29
30
|
|
|
31
|
+
/** The camera. Stored only: sprites render in screen space and use no camera buffers. */
|
|
32
|
+
public camera?: ICamera;
|
|
33
|
+
|
|
30
34
|
private readonly _renderPipeline: ISpriteRenderPipeline;
|
|
31
35
|
|
|
32
36
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {IMaterial} from "./IMaterial.ts";
|
|
2
2
|
|
|
3
3
|
import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
|
|
4
4
|
import type { ITexture2D } from "../rendering/texture/ITexture2D.ts";
|
|
@@ -14,22 +14,14 @@ import {Color} from "../data/Color.ts";
|
|
|
14
14
|
import type { IUnlitRenderPipeline } from "../rendering/render-pipelines/IUnlitRenderPipeline.ts";
|
|
15
15
|
import type { IPrimitiveState } from "../rendering/primitive/IPrimitiveState.ts";
|
|
16
16
|
import type {ICamera} from "../camera/ICamera.ts";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export class UnlitMaterialDescriptor {
|
|
20
|
-
|
|
21
|
-
/** The primitive state. */
|
|
22
|
-
public primitiveState?: IPrimitiveState;
|
|
23
|
-
|
|
24
|
-
/** The camera used to render this material. */
|
|
25
|
-
public camera?: ICamera;
|
|
26
|
-
}
|
|
17
|
+
import type {IUnlitMaterialDescriptor} from "./IUnlitMaterialDescriptor.ts";
|
|
18
|
+
import {resolveUnlitMaterialDescriptor} from "../../core/material/UnlitMaterialDescriptorUtilities.ts";
|
|
27
19
|
|
|
28
20
|
|
|
29
21
|
/**
|
|
30
22
|
* Unlit material.
|
|
31
23
|
*/
|
|
32
|
-
export class UnlitMaterial implements
|
|
24
|
+
export class UnlitMaterial implements IMaterial {
|
|
33
25
|
|
|
34
26
|
private readonly _framework: IFramework;
|
|
35
27
|
private _color = Color.white();
|
|
@@ -51,17 +43,18 @@ export class UnlitMaterial implements ICameraMaterial {
|
|
|
51
43
|
/**
|
|
52
44
|
* The constructor.
|
|
53
45
|
* @param framework The framework.
|
|
54
|
-
* @param
|
|
46
|
+
* @param descriptor The optional material descriptor. A projection view buffer passed here is shared and is not disposed by this material.
|
|
55
47
|
*/
|
|
56
|
-
public constructor(framework: IFramework,
|
|
48
|
+
public constructor(framework: IFramework, descriptor?: IUnlitMaterialDescriptor) {
|
|
49
|
+
const config = resolveUnlitMaterialDescriptor(descriptor);
|
|
57
50
|
this._framework = framework;
|
|
58
51
|
const usage = BufferUsage.UNIFORM | BufferUsage.COPY_DST;
|
|
59
|
-
this._camera = config
|
|
52
|
+
this._camera = config.camera;
|
|
60
53
|
// Without a camera an own zero buffer is bound, so rendering before the scene assigns one does not crash.
|
|
61
|
-
this._ownsProjectionViewBuffer = !config
|
|
62
|
-
this._projectionViewBuffer = config
|
|
54
|
+
this._ownsProjectionViewBuffer = !config.camera?.projectionViewBuffer;
|
|
55
|
+
this._projectionViewBuffer = config.camera?.projectionViewBuffer ?? framework.bufferFactory.createUniformBuffer(mat4.create(), usage);
|
|
63
56
|
this._materialBuffer = framework.bufferFactory.createUniformBuffer(this._materialData, usage);
|
|
64
|
-
this._primitiveState = config
|
|
57
|
+
this._primitiveState = config.primitiveState;
|
|
65
58
|
// The pipeline is created once a model buffer is assigned (see modelBuffer).
|
|
66
59
|
}
|
|
67
60
|
|
|
@@ -4,6 +4,6 @@ export * from "./InspectTextureMipsMaterial.ts"
|
|
|
4
4
|
export * from "./MaterialFactory.ts"
|
|
5
5
|
export * from "./SpriteMaterial.ts"
|
|
6
6
|
export * from "./UnlitMaterial.ts"
|
|
7
|
+
export * from "./IUnlitMaterialDescriptor.ts";
|
|
7
8
|
export * from "./ForwardBlinnPhongMaterial.ts"
|
|
8
|
-
export * from "./ICameraMaterial.ts"
|
|
9
9
|
export * from "./ILightsMaterial.ts"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { mat4, vec3 } from "gl-matrix";
|
|
2
1
|
import type { IMesh } from "./IMesh.ts";
|
|
3
2
|
import type { IMaterial } from "../material/IMaterial.ts";
|
|
4
3
|
import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
4
|
+
import type {ISceneObject} from "../scene/ISceneObject.ts";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A mesh that can be drawn: a mesh plus an optional material, an index range and sub meshes.
|
|
@@ -15,7 +15,7 @@ import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
|
15
15
|
* (a `SceneMesh` does that).
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
|
-
export interface IRenderableMesh extends IMesh {
|
|
18
|
+
export interface IRenderableMesh extends IMesh, ISceneObject {
|
|
19
19
|
|
|
20
20
|
/** The material, if any. A root mesh made only of sub meshes has none. */
|
|
21
21
|
material?: IMaterial;
|
|
@@ -32,23 +32,8 @@ export interface IRenderableMesh extends IMesh {
|
|
|
32
32
|
/** Number of indices to draw; -1 (the default) draws all indices. */
|
|
33
33
|
readonly indexCount: number;
|
|
34
34
|
|
|
35
|
-
/** World position. Defaults to the origin. In-place edits are detected. A sub mesh uses the root's. */
|
|
36
|
-
position: vec3;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Euler rotation in radians, applied in Y, X, Z order (yaw, pitch, roll): `R = Ry * Rx * Rz`.
|
|
40
|
-
* Defaults to (0, 0, 0). In-place edits are detected. A sub mesh uses the root's.
|
|
41
|
-
*/
|
|
42
|
-
rotation: vec3;
|
|
43
|
-
|
|
44
|
-
/** Scale. Defaults to (1, 1, 1). In-place edits are detected. A sub mesh uses the root's. */
|
|
45
|
-
scale: vec3;
|
|
46
|
-
|
|
47
|
-
/** The model matrix `T * R * S`, recomputed only when position, rotation or scale changed. */
|
|
48
|
-
readonly modelMatrix: mat4;
|
|
49
|
-
|
|
50
35
|
/**
|
|
51
|
-
* The model buffer (std140 `mat4`) holding
|
|
36
|
+
* The model buffer (std140 `mat4`) holding the root's `transform.modelMatrix`. Owned by the root mesh (sub meshes share it),
|
|
52
37
|
* uploaded when the transform changed and assigned to the material(s) before drawing. Created on first use.
|
|
53
38
|
*/
|
|
54
39
|
readonly modelBuffer: IUniformBuffer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {mat4
|
|
1
|
+
import {mat4} from "gl-matrix";
|
|
2
2
|
import {Mesh} from "./Mesh.ts";
|
|
3
3
|
import type {IRenderableMesh} from "./IRenderableMesh.ts";
|
|
4
4
|
import type {IFramework} from "../IFramework.ts";
|
|
@@ -8,6 +8,7 @@ import type {IVertexBuffer} from "../rendering/buffers/IVertexBuffer.ts";
|
|
|
8
8
|
import type {IIndexBuffer} from "../rendering/buffers/IIndexBuffer.ts";
|
|
9
9
|
import type {GeometryFormat} from "../geometry/GeometryFormat.ts";
|
|
10
10
|
import {BufferUsage} from "../rendering/buffers/BufferUsage.ts";
|
|
11
|
+
import {TransformNode} from "../scene/node/TransformNode.ts";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* A mesh that can be drawn (C# `RenderableMesh`). See {@link IRenderableMesh}.
|
|
@@ -22,16 +23,6 @@ export class RenderableMesh extends Mesh implements IRenderableMesh {
|
|
|
22
23
|
private readonly _subMeshes: RenderableMesh[] = [];
|
|
23
24
|
private readonly _parent?: RenderableMesh;
|
|
24
25
|
|
|
25
|
-
// Transform; only used on the root.
|
|
26
|
-
private _position: vec3 = vec3.create();
|
|
27
|
-
private _rotation: vec3 = vec3.create();
|
|
28
|
-
private _scale: vec3 = vec3.fromValues(1, 1, 1);
|
|
29
|
-
private readonly _modelMatrix = mat4.create();
|
|
30
|
-
private readonly _rotationQuat = quat.create();
|
|
31
|
-
// Cached copies to detect in-place edits; NaN forces the first computation.
|
|
32
|
-
private readonly _lastPosition = vec3.fromValues(NaN, NaN, NaN);
|
|
33
|
-
private readonly _lastRotation = vec3.create();
|
|
34
|
-
private readonly _lastScale = vec3.create();
|
|
35
26
|
private _modelBuffer?: IUniformBuffer;
|
|
36
27
|
/** The matrix last uploaded to the model buffer. */
|
|
37
28
|
private readonly _uploadedMatrix = mat4.create();
|
|
@@ -45,6 +36,17 @@ export class RenderableMesh extends Mesh implements IRenderableMesh {
|
|
|
45
36
|
/** @inheritDoc */
|
|
46
37
|
public readonly indexCount: number;
|
|
47
38
|
|
|
39
|
+
private _transform = new TransformNode();
|
|
40
|
+
|
|
41
|
+
/** @inheritDoc A sub mesh returns (and sets) the root's transform. */
|
|
42
|
+
public get transform(): TransformNode {
|
|
43
|
+
return this._root._transform;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public set transform(value: TransformNode) {
|
|
47
|
+
this._root._transform = value;
|
|
48
|
+
}
|
|
49
|
+
|
|
48
50
|
/**
|
|
49
51
|
* The constructor.
|
|
50
52
|
* @param framework The framework.
|
|
@@ -103,38 +105,6 @@ export class RenderableMesh extends Mesh implements IRenderableMesh {
|
|
|
103
105
|
return this.material?.geometryFormat;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
/** @inheritDoc */
|
|
107
|
-
public get position(): vec3 { return this._root._position; }
|
|
108
|
-
public set position(value: vec3) { this._root._position = value; }
|
|
109
|
-
|
|
110
|
-
/** @inheritDoc */
|
|
111
|
-
public get rotation(): vec3 { return this._root._rotation; }
|
|
112
|
-
public set rotation(value: vec3) { this._root._rotation = value; }
|
|
113
|
-
|
|
114
|
-
/** @inheritDoc */
|
|
115
|
-
public get scale(): vec3 { return this._root._scale; }
|
|
116
|
-
public set scale(value: vec3) { this._root._scale = value; }
|
|
117
|
-
|
|
118
|
-
/** @inheritDoc */
|
|
119
|
-
public get modelMatrix(): mat4 {
|
|
120
|
-
const root = this._root;
|
|
121
|
-
if (root !== this) {
|
|
122
|
-
return root.modelMatrix;
|
|
123
|
-
}
|
|
124
|
-
if (!vec3.exactEquals(this._lastPosition, this._position)
|
|
125
|
-
|| !vec3.exactEquals(this._lastRotation, this._rotation)
|
|
126
|
-
|| !vec3.exactEquals(this._lastScale, this._scale)) {
|
|
127
|
-
vec3.copy(this._lastPosition, this._position);
|
|
128
|
-
vec3.copy(this._lastRotation, this._rotation);
|
|
129
|
-
vec3.copy(this._lastScale, this._scale);
|
|
130
|
-
const q = quat.identity(this._rotationQuat);
|
|
131
|
-
quat.rotateY(q, q, this._rotation[1]);
|
|
132
|
-
quat.rotateX(q, q, this._rotation[0]);
|
|
133
|
-
quat.rotateZ(q, q, this._rotation[2]);
|
|
134
|
-
mat4.fromRotationTranslationScale(this._modelMatrix, q, this._position, this._scale);
|
|
135
|
-
}
|
|
136
|
-
return this._modelMatrix;
|
|
137
|
-
}
|
|
138
108
|
|
|
139
109
|
/** @inheritDoc Created on first access and disposed with the root mesh. */
|
|
140
110
|
public get modelBuffer(): IUniformBuffer {
|
|
@@ -143,7 +113,7 @@ export class RenderableMesh extends Mesh implements IRenderableMesh {
|
|
|
143
113
|
return root.modelBuffer;
|
|
144
114
|
}
|
|
145
115
|
if (!this._modelBuffer) {
|
|
146
|
-
mat4.copy(this._uploadedMatrix, this.modelMatrix);
|
|
116
|
+
mat4.copy(this._uploadedMatrix, this.transform.modelMatrix);
|
|
147
117
|
this._modelBuffer = this._framework.bufferFactory.createUniformBuffer(
|
|
148
118
|
this._uploadedMatrix, BufferUsage.UNIFORM | BufferUsage.COPY_DST, "RenderableMesh.modelBuffer");
|
|
149
119
|
}
|
|
@@ -154,7 +124,7 @@ export class RenderableMesh extends Mesh implements IRenderableMesh {
|
|
|
154
124
|
private _updateModelBuffer(): IUniformBuffer {
|
|
155
125
|
const root = this._root;
|
|
156
126
|
const buffer = root.modelBuffer;
|
|
157
|
-
const matrix = root.modelMatrix;
|
|
127
|
+
const matrix = root.transform.modelMatrix;
|
|
158
128
|
if (!mat4.exactEquals(root._uploadedMatrix, matrix)) {
|
|
159
129
|
mat4.copy(root._uploadedMatrix, matrix);
|
|
160
130
|
buffer.update(root._uploadedMatrix);
|
|
@@ -9,7 +9,7 @@ import type { IRenderPass } from "./renderpass/IRenderPass.ts";
|
|
|
9
9
|
import {SwapChainDescriptor} from "./swapchain/SwapChainDescriptor.ts";
|
|
10
10
|
import type { ISwapChain } from "./swapchain/ISwapChain.ts";
|
|
11
11
|
import {SamplerDescriptor} from "./sampler/SamplerDescriptor.ts";
|
|
12
|
-
import {
|
|
12
|
+
import type {IPrimitiveStateDescriptor} from "./primitive/IPrimitiveStateDescriptor.ts";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The interface for a graphics device.
|
|
@@ -71,7 +71,7 @@ export interface IGraphicsDevice extends IDisposable {
|
|
|
71
71
|
* @param descriptor - The primitive state descriptor.
|
|
72
72
|
* @returns The created primitive state.
|
|
73
73
|
*/
|
|
74
|
-
createPrimitiveState(descriptor
|
|
74
|
+
createPrimitiveState(descriptor?: IPrimitiveStateDescriptor): IPrimitiveState;
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* Creates a render pass for the graphics device.
|
|
@@ -5,7 +5,7 @@ import {RenderingBackend} from "./RenderingBackend.ts";
|
|
|
5
5
|
import {vec2} from "gl-matrix";
|
|
6
6
|
import type {PowerPreferenceType} from "./PowerPreference.ts";
|
|
7
7
|
import type {TextureSamplerFilteringPreset} from "../../core/rendering/enums.ts";
|
|
8
|
-
import type {
|
|
8
|
+
import type {ColorSpace} from "./enums.ts";
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -31,7 +31,7 @@ export interface IRendererConfiguration {
|
|
|
31
31
|
textureFiltering: TextureSamplerFilteringPreset;
|
|
32
32
|
|
|
33
33
|
/** The desired texture color space. */
|
|
34
|
-
textureColorSpace:
|
|
34
|
+
textureColorSpace: ColorSpace;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -46,13 +46,21 @@ export interface IRenderer {
|
|
|
46
46
|
readonly graphicsDevice: IGraphicsDevice;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* The preferred texture format.
|
|
50
|
-
*
|
|
51
|
-
* - {@link TextureFormat.}
|
|
52
|
-
* - {@link TextureFormat.}
|
|
49
|
+
* The preferred texture format, derived from the current {@link IRenderer.colorSpace}.
|
|
50
|
+
* Textures that do not specify a texture format are created with it:
|
|
51
|
+
* - {@link TextureFormat.RGBA_8_UNORM_SRGB} when the color space is {@link ColorSpace.SRGB} (the default).
|
|
52
|
+
* - {@link TextureFormat.RGBA_8_UNORM} when the color space is {@link ColorSpace.LINEAR}.
|
|
53
53
|
*/
|
|
54
54
|
readonly preferredTextureFormat: TextureFormat;
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* The color space. Defaults to the framework configuration's `textureColorSpace`.
|
|
58
|
+
* Can be switched at runtime, e.g. `framework.renderer.colorSpace = ColorSpace.SRGB`.
|
|
59
|
+
* Changing it affects textures created afterwards and the main render target's output conversion;
|
|
60
|
+
* already-created textures are not converted.
|
|
61
|
+
*/
|
|
62
|
+
colorSpace: ColorSpace;
|
|
63
|
+
|
|
56
64
|
/**
|
|
57
65
|
* The preferred depth stencil format.
|
|
58
66
|
*/
|
|
@@ -19,12 +19,12 @@ export enum Culling {
|
|
|
19
19
|
Front
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
export enum
|
|
22
|
+
/** The color space. */
|
|
23
|
+
export enum ColorSpace
|
|
24
24
|
{
|
|
25
|
-
/**
|
|
25
|
+
/** The linear color space. */
|
|
26
26
|
LINEAR = "LINEAR",
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
SRGB = "
|
|
28
|
+
/** The sRGB color space. */
|
|
29
|
+
SRGB = "SRGB",
|
|
30
30
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {PrimitiveTopology} from "./PrimitiveTopology.ts";
|
|
2
|
+
import type {CullMode} from "./CullMode.ts";
|
|
3
|
+
import type {FrontFace} from "./FrontFace.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Describes the state of a primitive. All fields are optional; the graphics device fills in the defaults.
|
|
7
|
+
*/
|
|
8
|
+
export interface IPrimitiveStateDescriptor {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The topology of the primitive.
|
|
12
|
+
* By default, it is set to TRIANGLE_LIST.
|
|
13
|
+
*/
|
|
14
|
+
topology?: PrimitiveTopology;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The culling mode.
|
|
18
|
+
* By default, it is set to BACK.
|
|
19
|
+
*/
|
|
20
|
+
cullFace?: CullMode;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The front face.
|
|
24
|
+
* By default, it is set to CCW (counter clockwise).
|
|
25
|
+
*/
|
|
26
|
+
frontFace?: FrontFace;
|
|
27
|
+
}
|