ris-framework 0.1.0 → 0.2.0-dev.12
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 +42 -1
- package/README.md +27 -4
- package/dist/Framework.d.ts +34 -10
- package/dist/Framework.d.ts.map +1 -1
- package/dist/api/IFramework.d.ts +50 -6
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/_export.d.ts +3 -1
- package/dist/api/_export.d.ts.map +1 -1
- package/dist/api/camera/CameraFactory.d.ts +3 -2
- package/dist/api/camera/CameraFactory.d.ts.map +1 -1
- package/dist/api/camera/ICamera.d.ts +5 -0
- package/dist/api/camera/ICamera.d.ts.map +1 -1
- package/dist/api/camera/ICameraFactory.d.ts +5 -6
- package/dist/api/camera/ICameraFactory.d.ts.map +1 -1
- package/dist/api/camera/OrthographicCamera.d.ts +7 -0
- package/dist/api/camera/OrthographicCamera.d.ts.map +1 -1
- package/dist/api/camera/PerspectiveCamera.d.ts +30 -6
- package/dist/api/camera/PerspectiveCamera.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +15 -2
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +35 -1
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/content/ShaderModuleContent.d.ts.map +1 -1
- package/dist/api/data/Color.d.ts +5 -0
- package/dist/api/data/Color.d.ts.map +1 -1
- package/dist/api/geometry/BaseGeometry.d.ts +9 -0
- package/dist/api/geometry/BaseGeometry.d.ts.map +1 -1
- package/dist/api/geometry/GeometryBuilder.d.ts +3 -1
- package/dist/api/geometry/GeometryBuilder.d.ts.map +1 -1
- package/dist/api/geometry/IGeometryBuilder.d.ts +24 -0
- package/dist/api/geometry/IGeometryBuilder.d.ts.map +1 -1
- package/dist/api/geometry/_export-geometry.d.ts +1 -0
- package/dist/api/geometry/_export-geometry.d.ts.map +1 -1
- package/dist/api/input/InputManager.d.ts +4 -0
- package/dist/api/input/InputManager.d.ts.map +1 -1
- package/dist/api/lights/AmbientLight.d.ts +35 -0
- package/dist/api/lights/AmbientLight.d.ts.map +1 -0
- package/dist/api/lights/DirectionalLight.d.ts +40 -0
- package/dist/api/lights/DirectionalLight.d.ts.map +1 -0
- package/dist/api/lights/LightFactory.d.ts +18 -0
- package/dist/api/lights/LightFactory.d.ts.map +1 -0
- package/dist/api/lights/LightId.d.ts +6 -0
- package/dist/api/lights/LightId.d.ts.map +1 -0
- package/dist/api/lights/LightsBuffer.d.ts +77 -0
- package/dist/api/lights/LightsBuffer.d.ts.map +1 -0
- package/dist/api/lights/PointLight.d.ts +59 -0
- package/dist/api/lights/PointLight.d.ts.map +1 -0
- package/dist/api/lights/_export.d.ts +6 -0
- package/dist/api/lights/_export.d.ts.map +1 -0
- package/dist/api/loaders/ObjGeometryMapper.d.ts +19 -0
- package/dist/api/loaders/ObjGeometryMapper.d.ts.map +1 -0
- package/dist/api/loaders/ObjLoader.d.ts +61 -0
- package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
- package/dist/api/loaders/_export.d.ts +2 -0
- package/dist/api/loaders/_export.d.ts.map +1 -1
- package/dist/api/loaders/obj/ObjParser.d.ts +44 -0
- package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts +119 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -0
- package/dist/api/loaders/obj/index.d.ts +3 -0
- package/dist/api/loaders/obj/index.d.ts.map +1 -0
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +138 -0
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -0
- package/dist/api/material/ICameraMaterial.d.ts +18 -0
- package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
- package/dist/api/material/ILightsMaterial.d.ts +26 -0
- package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
- package/dist/api/material/IMaterial.d.ts +13 -10
- package/dist/api/material/IMaterial.d.ts.map +1 -1
- package/dist/api/material/IMaterialFactory.d.ts +17 -2
- package/dist/api/material/IMaterialFactory.d.ts.map +1 -1
- package/dist/api/material/InspectTextureMipsMaterial.d.ts +18 -9
- package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
- package/dist/api/material/MaterialFactory.d.ts +6 -0
- package/dist/api/material/MaterialFactory.d.ts.map +1 -1
- package/dist/api/material/SpriteMaterial.d.ts +51 -0
- package/dist/api/material/SpriteMaterial.d.ts.map +1 -0
- package/dist/api/material/UnlitMaterial.d.ts +32 -13
- package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
- package/dist/api/material/_export.d.ts +4 -0
- package/dist/api/material/_export.d.ts.map +1 -1
- package/dist/api/meshes/IMesh.d.ts +31 -6
- package/dist/api/meshes/IMesh.d.ts.map +1 -1
- package/dist/api/meshes/IMeshFactory.d.ts +30 -4
- package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
- package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/Mesh.d.ts +14 -8
- package/dist/api/meshes/Mesh.d.ts.map +1 -1
- package/dist/api/meshes/MeshFactory.d.ts +10 -3
- package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/QuadMesh.d.ts +5 -3
- package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
- package/dist/api/meshes/RenderableMesh.d.ts +95 -0
- package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/_export.d.ts +2 -0
- package/dist/api/meshes/_export.d.ts.map +1 -1
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/api/rendering/IRenderer.d.ts +28 -1
- package/dist/api/rendering/IRenderer.d.ts.map +1 -1
- package/dist/api/rendering/enums.d.ts +7 -0
- package/dist/api/rendering/enums.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts +56 -0
- package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts.map +1 -0
- package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts +3 -0
- package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts +29 -0
- package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts +1 -0
- package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts.map +1 -1
- package/dist/api/rendering/renderer-interface.d.ts +1 -31
- package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
- package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
- package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
- package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
- package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
- package/dist/api/scene/Scene.d.ts +113 -0
- package/dist/api/scene/Scene.d.ts.map +1 -0
- package/dist/api/scene/SceneMesh.d.ts +27 -0
- package/dist/api/scene/SceneMesh.d.ts.map +1 -0
- package/dist/api/shader/IShaderModuleLoader.d.ts +4 -1
- package/dist/api/shader/IShaderModuleLoader.d.ts.map +1 -1
- package/dist/api/shader/{shader-loader.d.ts → ShaderLoader.d.ts} +1 -1
- package/dist/api/shader/ShaderLoader.d.ts.map +1 -0
- package/dist/api/sprites/SpriteBatchDrawable.d.ts +1 -1
- package/dist/api/sprites/SpriteBatchDrawable.d.ts.map +1 -1
- package/dist/api/sprites/SpriteBatchMesh.d.ts +14 -1
- package/dist/api/sprites/SpriteBatchMesh.d.ts.map +1 -1
- package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
- package/dist/api/utilities/GeometryUtilities.d.ts.map +1 -1
- package/dist/api/window/WindowManager.d.ts +4 -0
- package/dist/api/window/WindowManager.d.ts.map +1 -1
- package/dist/core/rendering/ARenderer.d.ts +5 -5
- package/dist/core/rendering/ARenderer.d.ts.map +1 -1
- package/dist/core/rendering/vertex-buffer-layout.d.ts +1 -0
- package/dist/core/rendering/vertex-buffer-layout.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9238 -4595
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/webgl/WebGlGraphicsDevice.d.ts.map +1 -1
- package/dist/webgl/WebGlRenderer.d.ts +1 -3
- package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
- package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts +17 -0
- package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts.map +1 -0
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts +59 -0
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -0
- package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +5 -0
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts +3 -1
- package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts +88 -0
- package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts.map +1 -0
- package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/shader/WebGlShaderModule.d.ts +4 -1
- package/dist/webgl/shader/WebGlShaderModule.d.ts.map +1 -1
- package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts +16 -5
- package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts.map +1 -1
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTexture2D.d.ts +8 -1
- package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
- package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
- package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
- package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
- package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts +0 -1
- package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts.map +1 -1
- package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
- package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
- package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
- package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
- package/dist/webgpu/WebGpuTypes.d.ts +355 -0
- package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
- package/package.json +4 -4
- package/shaders/glsl/forward_blinn_phong_material_fs.glsl +110 -0
- package/shaders/glsl/forward_blinn_phong_material_vs.glsl +32 -0
- package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
- package/shaders/glsl/sprite_fs.glsl +1 -1
- package/shaders/glsl/unlit_material_fs.glsl +1 -1
- package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
- package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
- package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
- package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
- package/shaders/wgsl/sprite.wgsl +40 -0
- package/shaders/wgsl/unlit_material.wgsl +49 -0
- package/src/Framework.ts +156 -48
- package/src/api/IFramework.ts +63 -6
- package/src/api/_export.ts +3 -1
- package/src/api/camera/CameraFactory.ts +6 -6
- package/src/api/camera/ICamera.ts +6 -0
- package/src/api/camera/ICameraFactory.ts +5 -10
- package/src/api/camera/OrthographicCamera.ts +23 -1
- package/src/api/camera/PerspectiveCamera.ts +60 -15
- package/src/api/content/ContentManager.ts +78 -16
- package/src/api/content/IContentManager.ts +37 -1
- package/src/api/content/ShaderModuleContent.ts +9 -0
- package/src/api/data/Color.ts +7 -1
- package/src/api/geometry/BaseGeometry.ts +23 -0
- package/src/api/geometry/GeometryBuilder.ts +14 -2
- package/src/api/geometry/IGeometryBuilder.ts +31 -1
- package/src/api/geometry/_export-geometry.ts +2 -1
- package/src/api/input/InputManager.ts +14 -5
- package/src/api/lights/AmbientLight.ts +53 -0
- package/src/api/lights/DirectionalLight.ts +60 -0
- package/src/api/lights/LightFactory.ts +21 -0
- package/src/api/lights/LightId.ts +9 -0
- package/src/api/lights/LightsBuffer.ts +94 -0
- package/src/api/lights/PointLight.ts +91 -0
- package/src/api/lights/_export.ts +5 -0
- package/src/api/loaders/ObjGeometryMapper.ts +28 -0
- package/src/api/loaders/ObjLoader.ts +126 -0
- package/src/api/loaders/_export.ts +3 -1
- package/src/api/loaders/obj/ObjParser.ts +301 -0
- package/src/api/loaders/obj/ObjTypes.ts +142 -0
- package/src/api/loaders/obj/index.ts +5 -0
- package/src/api/material/ForwardBlinnPhongMaterial.ts +328 -0
- package/src/api/material/ICameraMaterial.ts +22 -0
- package/src/api/material/ILightsMaterial.ts +32 -0
- package/src/api/material/IMaterial.ts +13 -10
- package/src/api/material/IMaterialFactory.ts +19 -2
- package/src/api/material/InspectTextureMipsMaterial.ts +65 -26
- package/src/api/material/MaterialFactory.ts +12 -0
- package/src/api/material/SpriteMaterial.ts +83 -0
- package/src/api/material/UnlitMaterial.ts +105 -32
- package/src/api/material/_export.ts +5 -1
- package/src/api/meshes/IMesh.ts +40 -6
- package/src/api/meshes/IMeshFactory.ts +33 -4
- package/src/api/meshes/IRenderableMesh.ts +58 -0
- package/src/api/meshes/Mesh.ts +50 -43
- package/src/api/meshes/MeshFactory.ts +37 -4
- package/src/api/meshes/QuadMesh.ts +6 -4
- package/src/api/meshes/RenderableMesh.ts +207 -0
- package/src/api/meshes/_export.ts +6 -4
- package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
- package/src/api/rendering/IRenderer.ts +34 -1
- package/src/api/rendering/enums.ts +10 -0
- package/src/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts +66 -0
- package/src/api/rendering/render-pipelines/IRenderPipeline.ts +4 -0
- package/src/api/rendering/render-pipelines/IRenderPipelineFactory.ts +39 -0
- package/src/api/rendering/render-pipelines/_export-render-pipelines.ts +2 -1
- package/src/api/rendering/renderer-interface.ts +1 -36
- package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
- package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
- package/src/api/rendering/texture/TextureFormat.ts +128 -14
- package/src/api/rendering/texture/TextureUtilities.ts +225 -10
- package/src/api/scene/Scene.ts +297 -0
- package/src/api/scene/SceneMesh.ts +61 -0
- package/src/api/shader/IShaderModuleLoader.ts +2 -1
- package/src/api/sprites/SpriteBatchDrawable.ts +12 -16
- package/src/api/sprites/SpriteBatchMesh.ts +22 -3
- package/src/api/utilities/AlignUtilities.ts +2 -1
- package/src/api/utilities/GeometryUtilities.ts +2 -0
- package/src/api/window/WindowManager.ts +23 -3
- package/src/core/rendering/ARenderer.ts +24 -15
- package/src/core/rendering/vertex-buffer-layout.ts +32 -1
- package/src/index.ts +0 -1
- package/src/main.ts +2 -4
- package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
- package/src/webgl/WebGlGpuInfo.ts +1 -1
- package/src/webgl/WebGlGraphicsDevice.ts +0 -1
- package/src/webgl/WebGlRenderer.ts +2 -5
- package/src/webgl/lights/WebGlAmbientLightFactory.ts +35 -0
- package/src/webgl/lights/WebGlLightsBuffer.ts +225 -0
- package/src/webgl/render-pipelines/AWebGlRenderPipeline.ts +7 -1
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +21 -1
- package/src/webgl/render-pipelines/WebGlRenderPipelineFactory.ts +24 -2
- package/src/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.ts +16 -6
- package/src/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.ts +300 -0
- package/src/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.ts +16 -6
- package/src/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.ts +11 -7
- package/src/webgl/shader/WebGlShaderModule.ts +11 -4
- package/src/webgl/shader/WebGlShaderModuleLoader.ts +29 -10
- package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
- package/src/webgl/texture/WebGlTexture2D.ts +19 -5
- package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
- package/src/webgl/utilities/WebGlConstants.ts +136 -0
- package/src/webgl/utilities/WebGlConverter.ts +91 -22
- package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
- package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
- package/src/webgl/utilities/WebGlUtilities.ts +4 -0
- package/src/webgl/utilities/webgl-filter-anisotropic-utilities.ts +9 -6
- package/src/webgpu/WebGpuGpuInfo.ts +61 -0
- package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
- package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
- package/src/webgpu/WebGpuRenderer.ts +49 -0
- package/src/webgpu/WebGpuTypes.ts +288 -0
- package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
- package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
- package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
- package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
- package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
- package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
- package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
- package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
- package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
- package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
- package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
- package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
- package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
- package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
- package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
- package/src/webgpu/shader/WgslShaderContent.ts +20 -0
- package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
- package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
- package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
- package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
- package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
- package/src/wgsl-raw.d.ts +4 -0
- package/dist/api/FrameworkConfiguration.d.ts +0 -23
- package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/IFrameworkConfiguration.d.ts +0 -25
- package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/shader/shader-loader.d.ts.map +0 -1
- package/src/api/FrameworkConfiguration.ts +0 -29
- package/src/api/IFrameworkConfiguration.ts +0 -30
- /package/src/api/shader/{shader-loader.ts → ShaderLoader.ts} +0 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
|
|
2
|
+
import type {ITexture2D} from "../rendering/texture/ITexture2D.ts";
|
|
3
|
+
import type {ISampler} from "../rendering/sampler/ISampler.ts";
|
|
4
|
+
import {GeometryFormat} from "../geometry/GeometryFormat.ts";
|
|
5
|
+
import type {IUniformBuffer} from "../rendering/buffers/IUniformBuffer.ts";
|
|
6
|
+
import type {IIndexBuffer} from "../rendering/buffers/IIndexBuffer.ts";
|
|
7
|
+
import type {IVertexBuffer} from "../rendering/buffers/IVertexBuffer.ts";
|
|
8
|
+
import type {IFramework} from "../IFramework.ts";
|
|
9
|
+
import {BufferUsage} from "../rendering/buffers/BufferUsage.ts";
|
|
10
|
+
import {Color} from "../data/Color.ts";
|
|
11
|
+
import type {IPrimitiveState} from "../rendering/primitive/IPrimitiveState.ts";
|
|
12
|
+
import type {ICamera} from "../camera/ICamera.ts";
|
|
13
|
+
import type {LightsBuffer} from "../lights/LightsBuffer.ts";
|
|
14
|
+
import type {AmbientLight} from "../lights/AmbientLight.ts";
|
|
15
|
+
import type {DirectionalLight} from "../lights/DirectionalLight.ts";
|
|
16
|
+
import type {PointLight} from "../lights/PointLight.ts";
|
|
17
|
+
import type {ICameraMaterial} from "./ICameraMaterial.ts";
|
|
18
|
+
import type {ILightsMaterial} from "./ILightsMaterial.ts";
|
|
19
|
+
import type {IForwardBlinnPhongRenderPipeline} from "../rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The additional material config options.
|
|
23
|
+
* @public
|
|
24
|
+
**/
|
|
25
|
+
export class ForwardBlinnPhongMaterialDescriptor {
|
|
26
|
+
|
|
27
|
+
/** The primitive state. */
|
|
28
|
+
public primitiveState?: IPrimitiveState;
|
|
29
|
+
|
|
30
|
+
/** The projection view buffer. */
|
|
31
|
+
public projectionViewBuffer!: IUniformBuffer;
|
|
32
|
+
|
|
33
|
+
/** The camera position buffer. */
|
|
34
|
+
public cameraPositionBuffer!: IUniformBuffer;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The Blinn-Phong material with forward calculated lighting.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export class ForwardBlinnPhongMaterial implements ICameraMaterial, ILightsMaterial {
|
|
43
|
+
|
|
44
|
+
/** The directional light slots of the material's lights buffer and shader. */
|
|
45
|
+
public static readonly MAX_DIRECTIONAL_LIGHTS = 3;
|
|
46
|
+
|
|
47
|
+
/** The point light slots of the material's lights buffer and shader. */
|
|
48
|
+
public static readonly MAX_POINT_LIGHTS = 5;
|
|
49
|
+
|
|
50
|
+
private readonly _framework: IFramework;
|
|
51
|
+
|
|
52
|
+
private readonly _lightsBuffer: LightsBuffer;
|
|
53
|
+
private _diffuseColorCache: Color;
|
|
54
|
+
private _ambientColorCache: Color;
|
|
55
|
+
private _specularColorCache: Color;
|
|
56
|
+
private _shininessCache: number;
|
|
57
|
+
|
|
58
|
+
// std140: each vec3 starts on a 16-byte boundary, so pad each colour to 4 floats.
|
|
59
|
+
private _materialData = [
|
|
60
|
+
0.1, 0.1, 0.1, 0, // Ambient
|
|
61
|
+
0.8, 0.8, 0.8, 0, // Diffuse
|
|
62
|
+
0.5, 0.5, 0.5, 32, // Specular, shininess (the float fills the vec3's padding)
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
/** Created when the model buffer is assigned (the pipeline requires one). */
|
|
66
|
+
private _pipeline?: IForwardBlinnPhongRenderPipeline;
|
|
67
|
+
private readonly _primitiveState?: IPrimitiveState;
|
|
68
|
+
/** Texture and sampler set before the pipeline exists; applied when it is created. */
|
|
69
|
+
private _pendingTexture?: ITexture2D;
|
|
70
|
+
private _pendingSampler?: ISampler;
|
|
71
|
+
private _samplerSet = false;
|
|
72
|
+
private _projectionViewBuffer: IUniformBuffer;
|
|
73
|
+
private _camera?: ICamera;
|
|
74
|
+
private _cameraPositionBuffer: IUniformBuffer;
|
|
75
|
+
private _materialBuffer: IUniformBuffer;
|
|
76
|
+
private _modelBuffer?: IUniformBuffer;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The constructor.
|
|
80
|
+
* @param framework The framework.
|
|
81
|
+
* @param descriptor The material descriptor. Its projection view and camera position buffers are shared and are not disposed by this material.
|
|
82
|
+
* @throws Error when `descriptor`, `descriptor.projectionViewBuffer` or `descriptor.cameraPositionBuffer` is missing.
|
|
83
|
+
*/
|
|
84
|
+
public constructor(framework: IFramework, descriptor: ForwardBlinnPhongMaterialDescriptor) {
|
|
85
|
+
|
|
86
|
+
// Runtime check: JavaScript callers can omit the required buffers.
|
|
87
|
+
const missing = [
|
|
88
|
+
descriptor?.projectionViewBuffer ? undefined : "descriptor.projectionViewBuffer",
|
|
89
|
+
descriptor?.cameraPositionBuffer ? undefined : "descriptor.cameraPositionBuffer",
|
|
90
|
+
].filter(x => x !== undefined);
|
|
91
|
+
if (missing.length > 0) {
|
|
92
|
+
throw new Error(`ForwardBlinnPhongMaterial: ${missing.join(" and ")} ${missing.length > 1 ? "are" : "is"} required (e.g. camera.projectionViewBuffer and camera.positionBuffer).`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this._framework = framework;
|
|
96
|
+
const usage = BufferUsage.UNIFORM | BufferUsage.COPY_DST;
|
|
97
|
+
this._diffuseColorCache = this.diffuseColor.copy();
|
|
98
|
+
this._ambientColorCache = this.ambientColor.copy();
|
|
99
|
+
this._specularColorCache = this.specularColor.copy();
|
|
100
|
+
this._shininessCache = this.shininess;
|
|
101
|
+
this._projectionViewBuffer = descriptor.projectionViewBuffer;
|
|
102
|
+
this._cameraPositionBuffer = descriptor.cameraPositionBuffer;
|
|
103
|
+
this._materialBuffer = framework.bufferFactory.createUniformBuffer(this._materialData, usage);
|
|
104
|
+
this._primitiveState = descriptor.primitiveState;
|
|
105
|
+
// Owned by the material, like C#: 3 directional + 5 point slots (88 floats), uploaded only when the lights changed.
|
|
106
|
+
this._lightsBuffer = framework.lightsFactory.__createLightsBuffer({
|
|
107
|
+
maxDirectionalLights: ForwardBlinnPhongMaterial.MAX_DIRECTIONAL_LIGHTS,
|
|
108
|
+
maxPointLights: ForwardBlinnPhongMaterial.MAX_POINT_LIGHTS,
|
|
109
|
+
});
|
|
110
|
+
// The pipeline is created once a model buffer is assigned (see modelBuffer).
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Creates the pipeline with the current bindings. */
|
|
114
|
+
private _createPipeline(modelBuffer: IUniformBuffer): IForwardBlinnPhongRenderPipeline {
|
|
115
|
+
const pipeline = this._framework.renderPipelineFactory.createForwardBlinnPhongRenderPipeline({
|
|
116
|
+
projectionViewBuffer: this._projectionViewBuffer,
|
|
117
|
+
modelBuffer,
|
|
118
|
+
materialBuffer: this._materialBuffer,
|
|
119
|
+
cameraPositionBuffer: this._cameraPositionBuffer,
|
|
120
|
+
lightsBuffer: this._lightsBuffer.buffer,
|
|
121
|
+
maxDirectionalLights: this._lightsBuffer.maxDirectionalLights,
|
|
122
|
+
maxPointLights: this._lightsBuffer.maxPointLights,
|
|
123
|
+
primitiveState: this._primitiveState,
|
|
124
|
+
});
|
|
125
|
+
if (this._pendingTexture) {
|
|
126
|
+
pipeline.diffuseTexture = this._pendingTexture;
|
|
127
|
+
}
|
|
128
|
+
if (this._samplerSet) {
|
|
129
|
+
pipeline.diffuseTextureSampler = this._pendingSampler;
|
|
130
|
+
}
|
|
131
|
+
this._pipeline = pipeline;
|
|
132
|
+
return pipeline;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The ambient color of this material.
|
|
137
|
+
* Alpha is ignored. By default, it is (0.1,0.1,0.1).
|
|
138
|
+
*/
|
|
139
|
+
public ambientColor: Color = new Color(0.1, 0.1, 0.1);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The diffuse color of this material.
|
|
143
|
+
* Alpha is ignored. By default, it is (0.8,0.8,0.8).
|
|
144
|
+
*/
|
|
145
|
+
public diffuseColor: Color = new Color(0.8, 0.8, 0.8);
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The specular color of this material (MTL `Ks`).
|
|
149
|
+
* Alpha is ignored. By default, it is (0.5,0.5,0.5).
|
|
150
|
+
*/
|
|
151
|
+
public specularColor: Color = new Color(0.5, 0.5, 0.5);
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The specular exponent (MTL `Ns`). Higher values give smaller, sharper highlights. By default, it is 32.
|
|
155
|
+
*/
|
|
156
|
+
public shininess = 32;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The camera. Setting it binds the camera's projection view and position buffers to the pipeline
|
|
160
|
+
* (used by the scene when its camera changes). Setting undefined keeps the last bound buffers.
|
|
161
|
+
* Undefined until set: the constructor only takes the buffers.
|
|
162
|
+
*/
|
|
163
|
+
public get camera(): ICamera | undefined {
|
|
164
|
+
return this._camera;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** @inheritDoc */
|
|
168
|
+
public set camera(camera: ICamera | undefined) {
|
|
169
|
+
if (camera === this._camera) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this._camera = camera;
|
|
173
|
+
if (!camera) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (this._projectionViewBuffer !== camera.projectionViewBuffer) {
|
|
177
|
+
this._projectionViewBuffer = camera.projectionViewBuffer;
|
|
178
|
+
if (this._pipeline) {
|
|
179
|
+
this._pipeline.projectionViewBuffer = this._projectionViewBuffer;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (this._cameraPositionBuffer !== camera.positionBuffer) {
|
|
183
|
+
this._cameraPositionBuffer = camera.positionBuffer;
|
|
184
|
+
if (this._pipeline) {
|
|
185
|
+
this._pipeline.cameraPositionBuffer = this._cameraPositionBuffer;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** @inheritDoc Defaults to a black ambient light; a `Scene` assigns its active ambient light. */
|
|
191
|
+
public get ambientLight(): AmbientLight {
|
|
192
|
+
return this._lightsBuffer.ambientLight;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public set ambientLight(value: AmbientLight) {
|
|
196
|
+
this._lightsBuffer.ambientLight = value;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** @inheritDoc Only the first 3 are used. A `Scene` assigns its own list. */
|
|
200
|
+
public get directionalLights(): DirectionalLight[] {
|
|
201
|
+
return this._lightsBuffer.directionalLights;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public set directionalLights(value: DirectionalLight[]) {
|
|
205
|
+
this._lightsBuffer.directionalLights = value;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** @inheritDoc Only the first 5 are used. A `Scene` assigns its own list. */
|
|
209
|
+
public get pointLights(): PointLight[] {
|
|
210
|
+
return this._lightsBuffer.pointLights;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public set pointLights(value: PointLight[]) {
|
|
214
|
+
this._lightsBuffer.pointLights = value;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The texture to inspect.
|
|
219
|
+
*/
|
|
220
|
+
public get diffuseTexture(): ITexture2D {
|
|
221
|
+
return this._pipeline?.diffuseTexture ?? this._pendingTexture!;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The texture to inspect.
|
|
226
|
+
*/
|
|
227
|
+
public set diffuseTexture(value: ITexture2D) {
|
|
228
|
+
this._pendingTexture = value;
|
|
229
|
+
if (this._pipeline) {
|
|
230
|
+
this._pipeline.diffuseTexture = value;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The texture sampler.
|
|
236
|
+
*/
|
|
237
|
+
public get diffuseTextureSampler(): ISampler | undefined {
|
|
238
|
+
return this._pipeline ? this._pipeline.diffuseTextureSampler : this._pendingSampler;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The texture sampler.
|
|
243
|
+
*/
|
|
244
|
+
public set diffuseTextureSampler(value: ISampler | undefined) {
|
|
245
|
+
this._pendingSampler = value;
|
|
246
|
+
this._samplerSet = true;
|
|
247
|
+
if (this._pipeline) {
|
|
248
|
+
this._pipeline.diffuseTextureSampler = value;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The model buffer (std140 `mat4`). Owned by the mesh, which assigns it before drawing; never disposed by this material.
|
|
254
|
+
* Undefined until assigned: rendering without one throws.
|
|
255
|
+
*/
|
|
256
|
+
public get modelBuffer(): IUniformBuffer | undefined {
|
|
257
|
+
return this._modelBuffer;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Binds the model buffer to the pipeline. */
|
|
261
|
+
public set modelBuffer(value: IUniformBuffer | undefined) {
|
|
262
|
+
if (value === this._modelBuffer) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this._modelBuffer = value;
|
|
266
|
+
if (!value) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (this._pipeline) {
|
|
270
|
+
this._pipeline.modelBuffer = value;
|
|
271
|
+
} else {
|
|
272
|
+
this._createPipeline(value);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The geometry format.
|
|
278
|
+
*/
|
|
279
|
+
public readonly geometryFormat = GeometryFormat.POS3_COLOR4_TEXTURECOORDS2_NORMAL3;
|
|
280
|
+
|
|
281
|
+
/** @inheritDoc */
|
|
282
|
+
public beforeRender(): void {
|
|
283
|
+
this._lightsBuffer.update();
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
if (!this._diffuseColorCache.equals(this.diffuseColor)
|
|
287
|
+
|| !this._ambientColorCache.equals(this.ambientColor)
|
|
288
|
+
|| !this._specularColorCache.equals(this.specularColor)
|
|
289
|
+
|| this._shininessCache !== this.shininess) {
|
|
290
|
+
this._ambientColorCache.set(this.ambientColor);
|
|
291
|
+
this._diffuseColorCache.set(this.diffuseColor);
|
|
292
|
+
this._specularColorCache.set(this.specularColor);
|
|
293
|
+
this._shininessCache = this.shininess;
|
|
294
|
+
this._materialData[0] = this._ambientColorCache.r;
|
|
295
|
+
this._materialData[1] = this._ambientColorCache.g;
|
|
296
|
+
this._materialData[2] = this._ambientColorCache.b;
|
|
297
|
+
this._materialData[4] = this._diffuseColorCache.r;
|
|
298
|
+
this._materialData[5] = this._diffuseColorCache.g;
|
|
299
|
+
this._materialData[6] = this._diffuseColorCache.b;
|
|
300
|
+
this._materialData[8] = this._specularColorCache.r;
|
|
301
|
+
this._materialData[9] = this._specularColorCache.g;
|
|
302
|
+
this._materialData[10] = this._specularColorCache.b;
|
|
303
|
+
this._materialData[11] = this._shininessCache;
|
|
304
|
+
this._materialBuffer.update(this._materialData);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** @inheritDoc */
|
|
309
|
+
public renderMesh(mesh: IRenderableMesh): void {
|
|
310
|
+
this.render(mesh.vertexBuffer!, mesh.indexBuffer!, mesh.indexCount ?? -1, mesh.indexStart ?? 0);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** @inheritDoc */
|
|
314
|
+
public render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer, indicesCount?: number, indicesOffset?: number): void {
|
|
315
|
+
if (!this._modelBuffer) {
|
|
316
|
+
throw new Error("ForwardBlinnPhongMaterial: no modelBuffer. Render it through a mesh (the mesh assigns its model buffer) or set material.modelBuffer.");
|
|
317
|
+
}
|
|
318
|
+
(this._pipeline ?? this._createPipeline(this._modelBuffer)).render(vertexBuffer, indexBuffer, indicesCount, indicesOffset);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** @inheritDoc */
|
|
322
|
+
public dispose(): void {
|
|
323
|
+
this._pipeline?.dispose();
|
|
324
|
+
this._pipeline = undefined;
|
|
325
|
+
this._materialBuffer.dispose();
|
|
326
|
+
this._lightsBuffer.dispose();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IMaterial } from "./IMaterial.ts";
|
|
2
|
+
import type { ICamera } from "../camera/ICamera.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A material that renders with a camera (unlit, Blinn-Phong, inspect mips).
|
|
6
|
+
* A `Scene` assigns its camera to these materials in `scene.update()`.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ICameraMaterial extends IMaterial {
|
|
10
|
+
|
|
11
|
+
/** The camera. Setting it binds the camera's buffers. */
|
|
12
|
+
camera?: ICamera;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether a material is an {@link ICameraMaterial}.
|
|
17
|
+
* @param material The material.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export function isCameraMaterial(material: IMaterial | undefined): material is ICameraMaterial {
|
|
21
|
+
return !!material && "camera" in material;
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IMaterial } from "./IMaterial.ts";
|
|
2
|
+
import type { AmbientLight } from "../lights/AmbientLight.ts";
|
|
3
|
+
import type { DirectionalLight } from "../lights/DirectionalLight.ts";
|
|
4
|
+
import type { PointLight } from "../lights/PointLight.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A material lit by an ambient light, directional lights and point lights (Blinn-Phong).
|
|
8
|
+
* The material owns its lights buffer and uploads it only when the lights changed.
|
|
9
|
+
* A `Scene` hands each lights material its active ambient light and its own light lists (the same arrays, not copies)
|
|
10
|
+
* in `scene.update()`, so lights added to the scene reach every lit material.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface ILightsMaterial extends IMaterial {
|
|
14
|
+
|
|
15
|
+
/** The ambient light. */
|
|
16
|
+
ambientLight: AmbientLight;
|
|
17
|
+
|
|
18
|
+
/** The directional lights. The list is used by reference and may be edited; extra lights beyond the slots are ignored. */
|
|
19
|
+
directionalLights: DirectionalLight[];
|
|
20
|
+
|
|
21
|
+
/** The point lights. The list is used by reference and may be edited; extra lights beyond the slots are ignored. */
|
|
22
|
+
pointLights: PointLight[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a material is an {@link ILightsMaterial}.
|
|
27
|
+
* @param material The material.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export function isLightsMaterial(material: IMaterial | undefined): material is ILightsMaterial {
|
|
31
|
+
return !!material && "directionalLights" in material && "pointLights" in material && "ambientLight" in material;
|
|
32
|
+
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import {mat4} from "gl-matrix";
|
|
2
1
|
import type { IDisposable } from "../core/IDisposable.ts";
|
|
3
2
|
import {GeometryFormat} from "../geometry/GeometryFormat.ts";
|
|
4
|
-
import type {
|
|
3
|
+
import type { IRenderableMesh } from "../meshes/IRenderableMesh.ts";
|
|
5
4
|
import type { IVertexBuffer } from "../rendering/buffers/IVertexBuffer.ts";
|
|
6
5
|
import type { IIndexBuffer } from "../rendering/buffers/IIndexBuffer.ts";
|
|
6
|
+
import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The material interface.
|
|
10
|
+
* @public
|
|
10
11
|
*/
|
|
11
12
|
export interface IMaterial extends IDisposable {
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
* The model
|
|
15
|
+
* The model buffer (std140 `mat4`) for materials that use one (unlit, Blinn-Phong, inspect mips).
|
|
16
|
+
* A mesh owns it and assigns it before drawing, like the scene assigns its camera; materials never dispose it.
|
|
17
|
+
* Materials without the property (e.g. the sprite material) are left alone.
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
modelBuffer?: IUniformBuffer;
|
|
17
20
|
|
|
18
|
-
/**
|
|
19
|
-
* The geometry format required by the material.
|
|
20
|
-
*/
|
|
21
|
+
/** The geometry format required by the material.*/
|
|
21
22
|
readonly geometryFormat: GeometryFormat;
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -26,16 +27,18 @@ export interface IMaterial extends IDisposable {
|
|
|
26
27
|
beforeRender(): void;
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
|
-
* Renders the material.
|
|
30
|
+
* Renders the mesh with this material, honouring the mesh's index range.
|
|
30
31
|
* @param mesh - The mesh.
|
|
31
32
|
*/
|
|
32
|
-
renderMesh(mesh:
|
|
33
|
+
renderMesh(mesh: IRenderableMesh): void;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Renders the material.
|
|
36
37
|
* @param vertexBuffer - The vertex buffer.
|
|
37
38
|
* @param indexBuffer - The index buffer.
|
|
39
|
+
* @param indicesCount - The number of indices to draw. -1 or undefined draws all.
|
|
40
|
+
* @param indicesOffset - The first index to draw. Defaults to 0.
|
|
38
41
|
*/
|
|
39
|
-
render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer): void;
|
|
42
|
+
render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer, indicesCount?: number, indicesOffset?: number): void;
|
|
40
43
|
|
|
41
44
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {InspectTextureMipsMaterial} from "./InspectTextureMipsMaterial.ts";
|
|
2
|
+
import type {SpriteMaterial, SpriteMaterialDescriptor} from "./SpriteMaterial.ts";
|
|
2
3
|
import {UnlitMaterial, UnlitMaterialDescriptor} from "./UnlitMaterial.ts";
|
|
4
|
+
import type {ForwardBlinnPhongMaterial, ForwardBlinnPhongMaterialDescriptor} from "./ForwardBlinnPhongMaterial.ts";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* The material factory.
|
|
@@ -14,8 +16,23 @@ export interface IMaterialFactory {
|
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Creates an unlit material.
|
|
17
|
-
* @param
|
|
19
|
+
* @param descriptor The optional additional configuration options for material, such as rendering options.
|
|
18
20
|
* @returns The Unlit Material.
|
|
19
21
|
*/
|
|
20
|
-
createUnlitMaterial(
|
|
22
|
+
createUnlitMaterial(descriptor?: UnlitMaterialDescriptor): UnlitMaterial;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates a sprite material.
|
|
26
|
+
* @param descriptor The sprite material descriptor with projection view buffer, texture and sampler.
|
|
27
|
+
* @returns The Sprite Material.
|
|
28
|
+
*/
|
|
29
|
+
createSpriteMaterial(descriptor: SpriteMaterialDescriptor): SpriteMaterial;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Blinn-Phong material with forward calculated lighting.
|
|
33
|
+
* @param descriptor The configuration: the required projection view and camera position buffers, plus optional lights buffer and primitive state.
|
|
34
|
+
* @throws Error when a required buffer is missing.
|
|
35
|
+
* @returns The Forward Blinn-Phong Material.
|
|
36
|
+
*/
|
|
37
|
+
createForwardBlinnPhongMaterial(descriptor: ForwardBlinnPhongMaterialDescriptor): ForwardBlinnPhongMaterial;
|
|
21
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {IRenderableMesh} from "../meshes/IRenderableMesh.ts";
|
|
2
2
|
import type { ITexture2D } from "../rendering/texture/ITexture2D.ts";
|
|
3
3
|
import type { IInspectTextureMipsRenderPipeline } from "../rendering/render-pipelines/IInspectTextureMipsRenderPipeline.ts";
|
|
4
4
|
import type { ISampler } from "../rendering/sampler/ISampler.ts";
|
|
@@ -17,24 +17,39 @@ export class InspectTextureMipsMaterial {
|
|
|
17
17
|
|
|
18
18
|
private readonly _framework: IFramework;
|
|
19
19
|
private _mipLevel = [0];
|
|
20
|
-
|
|
20
|
+
/** Created when the model buffer is assigned (the pipeline requires one). */
|
|
21
|
+
private _pipeline?: IInspectTextureMipsRenderPipeline;
|
|
22
|
+
/** Texture and sampler set before the pipeline exists; applied when it is created. */
|
|
23
|
+
private _pendingTexture?: ITexture2D;
|
|
24
|
+
private _pendingSampler?: ISampler;
|
|
25
|
+
private _samplerSet = false;
|
|
21
26
|
private _projectionViewBuffer: IUniformBuffer;
|
|
22
27
|
private _fragmentDataBuffer: IUniformBuffer;
|
|
23
|
-
private _modelBuffer
|
|
24
|
-
private _previousModelMatrix = mat4.create();
|
|
28
|
+
private _modelBuffer?: IUniformBuffer;
|
|
25
29
|
|
|
26
30
|
public constructor(framework: IFramework) {
|
|
27
31
|
this._framework = framework;
|
|
28
|
-
void this._framework;
|
|
29
32
|
const usage = BufferUsage.UNIFORM | BufferUsage.COPY_DST;
|
|
30
|
-
this._projectionViewBuffer = framework.bufferFactory.createUniformBuffer(
|
|
31
|
-
this._modelBuffer = framework.bufferFactory.createUniformBuffer(this._previousModelMatrix, usage);
|
|
33
|
+
this._projectionViewBuffer = framework.bufferFactory.createUniformBuffer(mat4.create(), usage);
|
|
32
34
|
this._fragmentDataBuffer = framework.bufferFactory.createUniformBuffer(this._mipLevel, usage);
|
|
33
|
-
|
|
35
|
+
// The pipeline is created once a model buffer is assigned (see modelBuffer).
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Creates the pipeline with the current bindings. */
|
|
39
|
+
private _createPipeline(modelBuffer: IUniformBuffer): IInspectTextureMipsRenderPipeline {
|
|
40
|
+
const pipeline = this._framework.renderPipelineFactory.createInspectTextureMipsRenderPipeline(
|
|
34
41
|
this._projectionViewBuffer,
|
|
35
|
-
|
|
42
|
+
modelBuffer,
|
|
36
43
|
this._fragmentDataBuffer,
|
|
37
44
|
);
|
|
45
|
+
if (this._pendingTexture) {
|
|
46
|
+
pipeline.spriteTexture = this._pendingTexture;
|
|
47
|
+
}
|
|
48
|
+
if (this._samplerSet) {
|
|
49
|
+
pipeline.textureSampler = this._pendingSampler;
|
|
50
|
+
}
|
|
51
|
+
this._pipeline = pipeline;
|
|
52
|
+
return pipeline;
|
|
38
53
|
}
|
|
39
54
|
|
|
40
55
|
/**
|
|
@@ -46,34 +61,60 @@ export class InspectTextureMipsMaterial {
|
|
|
46
61
|
* The texture to inspect.
|
|
47
62
|
*/
|
|
48
63
|
public get texture(): ITexture2D {
|
|
49
|
-
return this._pipeline.
|
|
64
|
+
return this._pipeline?.spriteTexture ?? this._pendingTexture!;
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
/**
|
|
53
68
|
* The texture to inspect.
|
|
54
69
|
*/
|
|
55
70
|
public set texture(value: ITexture2D) {
|
|
56
|
-
this.
|
|
71
|
+
this._pendingTexture = value;
|
|
72
|
+
if (this._pipeline) {
|
|
73
|
+
this._pipeline.spriteTexture = value;
|
|
74
|
+
}
|
|
57
75
|
}
|
|
58
76
|
|
|
59
77
|
/**
|
|
60
78
|
* The texture sampler.
|
|
61
79
|
*/
|
|
62
80
|
public get textureSampler(): ISampler | undefined {
|
|
63
|
-
return this._pipeline.textureSampler;
|
|
81
|
+
return this._pipeline ? this._pipeline.textureSampler : this._pendingSampler;
|
|
64
82
|
}
|
|
65
83
|
|
|
66
84
|
/**
|
|
67
85
|
* The texture sampler.
|
|
68
86
|
*/
|
|
69
87
|
public set textureSampler(value: ISampler | undefined) {
|
|
70
|
-
this.
|
|
88
|
+
this._pendingSampler = value;
|
|
89
|
+
this._samplerSet = true;
|
|
90
|
+
if (this._pipeline) {
|
|
91
|
+
this._pipeline.textureSampler = value;
|
|
92
|
+
}
|
|
71
93
|
}
|
|
72
94
|
|
|
73
95
|
/**
|
|
74
|
-
* The model
|
|
96
|
+
* The model buffer (std140 `mat4`). Owned by the mesh, which assigns it before drawing; never disposed by this material.
|
|
97
|
+
* Undefined until assigned: rendering without one throws.
|
|
75
98
|
*/
|
|
76
|
-
public
|
|
99
|
+
public get modelBuffer(): IUniformBuffer | undefined {
|
|
100
|
+
return this._modelBuffer;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Binds the model buffer to the pipeline. */
|
|
104
|
+
public set modelBuffer(value: IUniformBuffer | undefined) {
|
|
105
|
+
if (value === this._modelBuffer) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this._modelBuffer = value;
|
|
109
|
+
if (!value) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (this._pipeline) {
|
|
113
|
+
this._pipeline.modelBuffer = value;
|
|
114
|
+
} else {
|
|
115
|
+
this._createPipeline(value);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
77
118
|
|
|
78
119
|
/**
|
|
79
120
|
* The geometry format.
|
|
@@ -86,28 +127,26 @@ export class InspectTextureMipsMaterial {
|
|
|
86
127
|
this._mipLevel[0] = this.mipLevel;
|
|
87
128
|
this._fragmentDataBuffer.update(this._mipLevel);
|
|
88
129
|
}
|
|
89
|
-
|
|
90
|
-
if (!mat4.equals(this._previousModelMatrix, this.modelMatrix)) {
|
|
91
|
-
mat4.copy(this._previousModelMatrix, this.modelMatrix);
|
|
92
|
-
this._modelBuffer.update(this._previousModelMatrix);
|
|
93
|
-
}
|
|
94
130
|
}
|
|
95
131
|
|
|
96
132
|
/** @inheritDoc */
|
|
97
|
-
public renderMesh(mesh:
|
|
98
|
-
this.render(mesh.vertexBuffer!, mesh.indexBuffer
|
|
133
|
+
public renderMesh(mesh: IRenderableMesh): void {
|
|
134
|
+
this.render(mesh.vertexBuffer!, mesh.indexBuffer!, mesh.indexCount ?? -1, mesh.indexStart ?? 0);
|
|
99
135
|
}
|
|
100
136
|
|
|
101
137
|
/** @inheritDoc */
|
|
102
|
-
public render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer): void {
|
|
103
|
-
this.
|
|
138
|
+
public render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer, indicesCount?: number, indicesOffset?: number): void {
|
|
139
|
+
if (!this._modelBuffer) {
|
|
140
|
+
throw new Error("InspectTextureMipsMaterial: no modelBuffer. Render it through a mesh (the mesh assigns its model buffer) or set material.modelBuffer.");
|
|
141
|
+
}
|
|
142
|
+
(this._pipeline ?? this._createPipeline(this._modelBuffer)).render(vertexBuffer, indexBuffer, indicesCount, indicesOffset);
|
|
104
143
|
}
|
|
105
144
|
|
|
106
145
|
/** @inheritDoc */
|
|
107
146
|
public dispose(): void {
|
|
108
|
-
this._pipeline
|
|
147
|
+
this._pipeline?.dispose();
|
|
148
|
+
this._pipeline = undefined;
|
|
109
149
|
this._projectionViewBuffer.dispose();
|
|
110
|
-
this._modelBuffer.dispose();
|
|
111
150
|
this._fragmentDataBuffer.dispose();
|
|
112
151
|
}
|
|
113
152
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {InspectTextureMipsMaterial} from "./InspectTextureMipsMaterial.ts";
|
|
2
2
|
import type { IFramework } from "../IFramework.ts";
|
|
3
3
|
import type { IMaterialFactory } from "./IMaterialFactory.ts";
|
|
4
|
+
import {SpriteMaterial, type SpriteMaterialDescriptor} from "./SpriteMaterial.ts";
|
|
4
5
|
import {UnlitMaterial, UnlitMaterialDescriptor} from "./UnlitMaterial.ts";
|
|
6
|
+
import {ForwardBlinnPhongMaterial, type ForwardBlinnPhongMaterialDescriptor} from "./ForwardBlinnPhongMaterial.ts";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* The material factory.
|
|
@@ -24,4 +26,14 @@ export class MaterialFactory implements IMaterialFactory {
|
|
|
24
26
|
public createUnlitMaterial(descriptor? : UnlitMaterialDescriptor): UnlitMaterial {
|
|
25
27
|
return new UnlitMaterial(this._framework, descriptor );
|
|
26
28
|
}
|
|
29
|
+
|
|
30
|
+
/** @inheritDoc */
|
|
31
|
+
public createSpriteMaterial(descriptor: SpriteMaterialDescriptor): SpriteMaterial {
|
|
32
|
+
return new SpriteMaterial(this._framework, descriptor);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @inheritDoc */
|
|
36
|
+
public createForwardBlinnPhongMaterial(descriptor: ForwardBlinnPhongMaterialDescriptor): ForwardBlinnPhongMaterial {
|
|
37
|
+
return new ForwardBlinnPhongMaterial(this._framework, descriptor);
|
|
38
|
+
}
|
|
27
39
|
}
|