├── .gitignore ├── ROADMAP.md ├── deps ├── include │ ├── CL │ │ ├── .clang-format │ │ ├── README.md │ │ ├── cl_gl_ext.h │ │ ├── cl_ext_intel.h │ │ ├── cl_dx9_media_sharing_intel.h │ │ ├── opencl.h │ │ ├── cl_layer.h │ │ ├── cl_version.h │ │ ├── cl_d3d11.h │ │ ├── cl_d3d10.h │ │ ├── cl_egl.h │ │ ├── cl_va_api_media_sharing_intel.h │ │ ├── cl_gl.h │ │ └── cl_dx9_media_sharing.h │ ├── EGL │ │ ├── .clang-format │ │ └── eglplatform.h │ ├── KHR │ │ └── .clang-format │ ├── WGL │ │ └── .clang-format │ ├── GLES │ │ ├── .clang-format │ │ ├── egl.h │ │ ├── glplatform.h │ │ ├── glext_angle.h │ │ └── README.md │ ├── GLES2 │ │ ├── .clang-format │ │ └── gl2platform.h │ ├── GLES3 │ │ ├── .clang-format │ │ └── gl3platform.h │ ├── platform │ │ ├── Platform.h │ │ ├── FrontendFeatures.h │ │ ├── Feature.h │ │ └── FeaturesMtl.h │ ├── angle_gl.h │ ├── vulkan │ │ └── vulkan_fuchsia_ext.h │ ├── export.h │ ├── angle_windowsstore.h │ └── angle_cl.h └── cmake │ └── modules │ ├── FindEGL.cmake │ ├── FindOpenGLES3.cmake │ └── FindANGLE.cmake ├── screenshots └── sponza.png ├── doc ├── API_REFERENCE.md ├── BUILDING.md ├── BUILDING_WINDOWS.md ├── BUILDING_LINUX.md ├── BUILDING_WEB.md ├── BUILDING_MACOS.md ├── API_REFERENCE_GLSL.md ├── API_REFERENCE_JS.md └── API_REFERENCE_CPP.md ├── examples ├── native │ ├── hello_triangle │ │ ├── kernels │ │ │ ├── screen_fill.vs.glsl │ │ │ └── hello.fs.glsl │ │ └── CMakeLists.txt │ └── CMakeLists.txt └── web │ ├── kernels │ ├── screen_fill.vs.glsl │ ├── post_process.glsl │ ├── reflection.inc.glsl │ ├── accumulate.glsl │ ├── light.inc.glsl │ ├── common.inc.glsl │ ├── generate.glsl │ ├── util.inc.glsl │ ├── bxdf.inc.glsl │ └── intersection.glsl │ ├── css │ └── examples.css │ ├── example1_hello_world.html │ ├── example1_hello_world_ar.html │ ├── example1_hello_world_vr.html │ ├── example2_cube.html │ ├── example3_lighting.html │ ├── example4_pt.html │ └── js │ ├── common │ ├── webrays_utils.js │ └── webgl_viewer.js │ └── example1_hello_world.js ├── CHANGELOG.md ├── package.json ├── CMakeLists.txt ├── src ├── webrays_tlas.h ├── webrays_queue.cpp ├── webrays_cpu.h ├── webrays_queue.h ├── webrays_shader_engine.cpp ├── webrays_context.h ├── webrays_cpu.cpp ├── webrays_gl_shaders.h ├── CMakeLists.txt └── webrays_ads.h ├── README.md └── .clang-format /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | dist 3 | build 4 | TODO.txt -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | # Roadmap 2 | 3 | - Test suite 4 | - WebGPU backend -------------------------------------------------------------------------------- /deps/include/CL/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /deps/include/EGL/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /deps/include/KHR/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /deps/include/WGL/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /deps/include/GLES/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /deps/include/GLES2/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /deps/include/GLES3/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /screenshots/sponza.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phasmatic3d/webrays/HEAD/screenshots/sponza.png -------------------------------------------------------------------------------- /doc/API_REFERENCE.md: -------------------------------------------------------------------------------- 1 | ## API Reference 2 | 3 | [JavaScript](API_REFERENCE_JS.md) 4 | 5 | [C++](API_REFERENCE_CPP.md) 6 | 7 | [GLSL](API_REFERENCE_GLSL.md) -------------------------------------------------------------------------------- /examples/native/hello_triangle/kernels/screen_fill.vs.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | layout(location = 0) in vec3 position_IN; 4 | 5 | void main(){ 6 | gl_Position = vec4(position_IN, 1.0f); 7 | } -------------------------------------------------------------------------------- /examples/web/kernels/screen_fill.vs.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision highp float; 3 | 4 | layout(location = 0) in vec3 vertex_position; 5 | 6 | void main() 7 | { 8 | gl_Position = vec4(vertex_position, 1.0f); 9 | } -------------------------------------------------------------------------------- /examples/native/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | cmake_policy(SET CMP0048 NEW) 3 | 4 | find_package(SDL2) 5 | 6 | add_subdirectory (hello_triangle) 7 | 8 | set_target_properties(hello_triangle PROPERTIES FOLDER "examples") -------------------------------------------------------------------------------- /examples/web/css/examples.css: -------------------------------------------------------------------------------- 1 | #webrays-main { 2 | text-align:center; 3 | } 4 | 5 | #webrays-main-canvas { 6 | border: 2px solid black; 7 | max-width: 1024px; 8 | max-height: 768px; 9 | width: 80vw; 10 | height: 80vw; 11 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to the WebRays project will be documented in this file. 3 | 4 | ## [0.8.0] - 2021-08-04 5 | ### Added 6 | 7 | - CMake scripts. 8 | - Building instructions. 9 | - Initial project structure. 10 | 11 | ### Changed 12 | 13 | ### Removed 14 | 15 | -------------------------------------------------------------------------------- /examples/web/kernels/post_process.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision highp float; 3 | precision highp int; 4 | 5 | layout(location = 0) out vec4 pixel_color_OUT; 6 | 7 | uniform sampler2D accumulated_texture; 8 | 9 | void main() { 10 | vec4 pixel_color = texelFetch(accumulated_texture, ivec2(gl_FragCoord.xy), 0); 11 | pixel_color_OUT = pow(pixel_color, vec4(1.0 / 2.2)); 12 | } 13 | -------------------------------------------------------------------------------- /deps/include/platform/Platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // Platform.h: Simple forwarding header to PlatformMethods.h. 7 | // Ideally we can remove this file at some point since "Platform.h" is overloaded. 8 | // 9 | 10 | #include "PlatformMethods.h" 11 | -------------------------------------------------------------------------------- /examples/web/kernels/reflection.inc.glsl: -------------------------------------------------------------------------------- 1 | // BSDF Inline Functions 2 | float CosTheta(in vec3 w) { return w.z; } 3 | float Cos2Theta(in vec3 w) { return w.z * w.z; } 4 | float AbsCosTheta(in vec3 w) { return abs(w.z); } 5 | bool hemisphere_same(vec3 a, vec3 b, vec3 n); 6 | bool SameHemisphere(vec3 a, vec3 b) { return a.z * b.z > 0.0; } 7 | 8 | bool hemisphere_same(vec3 a, vec3 b, vec3 n) { 9 | return (dot(a, n) * dot(b, n) > 0.0); 10 | } -------------------------------------------------------------------------------- /doc/BUILDING.md: -------------------------------------------------------------------------------- 1 | ## Building 2 | 3 | The prerequisites for developing using WebRays are 4 | 5 | * Emscripten SDK (web) 6 | * C++ compiler with at least C++14 support (native) 7 | * CMake 3+ 8 | 9 | For the native targets you will also need 10 | * ANGLE 11 | * SDL2 (examples) 12 | 13 | Building instructions are currently provided for the following platforms: 14 | 15 | [Web](BUILDING_WEB.md) 16 | 17 | [Linux](BUILDING_LINUX.md) 18 | 19 | [Windows](BUILDING_WINDOWS.md) 20 | 21 | [Mac OS](BUILDING_MACOS.md) -------------------------------------------------------------------------------- /examples/web/kernels/accumulate.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision highp sampler2D; 3 | precision highp float; 4 | precision highp int; 5 | 6 | layout(location = 0) out vec4 accumulation_OUT; 7 | 8 | uniform float blend_factor; 9 | uniform sampler2D accumulation_texture; 10 | 11 | void main() { 12 | vec3 current_color = texelFetch(accumulation_texture, ivec2(gl_FragCoord.xy), 0).rgb; 13 | 14 | current_color = clamp(current_color, vec3(0.0),vec3(30.0)); 15 | 16 | accumulation_OUT = vec4(current_color, blend_factor); 17 | } 18 | -------------------------------------------------------------------------------- /deps/cmake/modules/FindEGL.cmake: -------------------------------------------------------------------------------- 1 | find_library(EGL_LIBRARY NAMES 2 | EGL 3 | 4 | # ANGLE (CMake doesn't search for lib prefix on Windows) 5 | libEGL 6 | 7 | # On iOS a part of OpenGLES 8 | OpenGLES) 9 | 10 | # Include dir 11 | find_path(EGL_INCLUDE_DIR NAMES 12 | EGL/egl.h 13 | 14 | # iOS 15 | EAGL.h) 16 | 17 | include(FindPackageHandleStandardArgs) 18 | find_package_handle_standard_args(EGL DEFAULT_MSG 19 | EGL_LIBRARY 20 | EGL_INCLUDE_DIR) 21 | 22 | #mark_as_advanced(EGL_LIBRARY EGL_INCLUDE_DIR) -------------------------------------------------------------------------------- /deps/cmake/modules/FindOpenGLES3.cmake: -------------------------------------------------------------------------------- 1 | 2 | find_library(OPENGLES3_LIBRARY NAMES 3 | GLESv3 4 | 5 | # On some platforms (e.g. desktop emulation with Mesa or NVidia) ES3 6 | # support is provided in ES2 lib 7 | GLESv2 8 | 9 | # ANGLE (CMake doesn't search for lib prefix on Windows) 10 | libGLESv2 11 | 12 | # iOS 13 | OpenGLES) 14 | 15 | include(FindPackageHandleStandardArgs) 16 | find_package_handle_standard_args("OpenGLES3" DEFAULT_MSG 17 | OPENGLES3_LIBRARY) 18 | set(GLES_LIBRARY "${OPENGLES3_LIBRARY}") 19 | 20 | mark_as_advanced(OPENGLES3_LIBRARY) -------------------------------------------------------------------------------- /deps/include/CL/README.md: -------------------------------------------------------------------------------- 1 | # ANGLE OpenCL Headers 2 | 3 | The OpenCL headers ANGLE uses are the original headers from Khronos. 4 | 5 | ### Updating headers 6 | 7 | 1. Clone [https://github.com/KhronosGroup/OpenCL-Headers.git](https://github.com/KhronosGroup/OpenCL-Headers.git). 8 | 1. Inspect the differences between all headers from `OpenCL-Headers/CL/` and this folder. 9 | * Changes of supported enums have to be updated in `src/common/packed_cl_enums.json`. 10 | * Changes of supported entry points have to be updated in `src/libGLESv2/cl_stubs.cpp`. 11 | 1. Copy all headers from `OpenCL-Headers/CL/` over to this folder. 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webrays", 3 | "version": "0.8.0", 4 | "description": "ray tracing on the Web", 5 | "main": "dist/webrays.js", 6 | "homepage": "https://github.com/phasmatic3d/webrays", 7 | "directories": { 8 | "doc": "doc", 9 | "example": "examples" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/phasmatic3d/webrays.git" 14 | }, 15 | "files": [ 16 | "doc", 17 | "dist/*.js", 18 | "dist/*.wasm" 19 | ], 20 | "scripts": { 21 | "test": "echo \"Error: no test specified\" && exit 1" 22 | }, 23 | "keywords": [ 24 | "ray-tracing", 25 | "web", 26 | "ray-intersection", 27 | "ray-casting" 28 | ], 29 | "author": "Phasmatic", 30 | "license": "Apache-2.0" 31 | } 32 | -------------------------------------------------------------------------------- /deps/include/GLES2/gl2platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl2platform_h_ 2 | #define __gl2platform_h_ 3 | 4 | /* 5 | ** Copyright 2017-2020 The Khronos Group Inc. 6 | ** SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h 10 | * 11 | * Adopters may modify khrplatform.h and this file to suit their platform. 12 | * Please contribute modifications back to Khronos as pull requests on the 13 | * public github repository: 14 | * https://github.com/KhronosGroup/OpenGL-Registry 15 | */ 16 | 17 | #include 18 | 19 | #ifndef GL_APICALL 20 | #define GL_APICALL KHRONOS_APICALL 21 | #endif 22 | 23 | #ifndef GL_APIENTRY 24 | #define GL_APIENTRY KHRONOS_APIENTRY 25 | #endif 26 | 27 | #endif /* __gl2platform_h_ */ 28 | -------------------------------------------------------------------------------- /deps/include/GLES3/gl3platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl3platform_h_ 2 | #define __gl3platform_h_ 3 | 4 | /* 5 | ** Copyright 2017-2020 The Khronos Group Inc. 6 | ** SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /* Platform-specific types and definitions for OpenGL ES 3.X gl3.h 10 | * 11 | * Adopters may modify khrplatform.h and this file to suit their platform. 12 | * Please contribute modifications back to Khronos as pull requests on the 13 | * public github repository: 14 | * https://github.com/KhronosGroup/OpenGL-Registry 15 | */ 16 | 17 | #include 18 | 19 | #ifndef GL_APICALL 20 | #define GL_APICALL KHRONOS_APICALL 21 | #endif 22 | 23 | #ifndef GL_APIENTRY 24 | #define GL_APIENTRY KHRONOS_APIENTRY 25 | #endif 26 | 27 | #endif /* __gl3platform_h_ */ 28 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | cmake_policy(SET CMP0048 NEW) 3 | project(webrays VERSION 0.8.0) 4 | 5 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 6 | set(BUILD_EXAMPLES false CACHE BOOL "Should the examples be built") 7 | set(SINGLE_FILE false CACHE BOOL "Embed WASM binary into emscripten's JS glue code") 8 | set(PREPARE_FOR_PUBLISH false CACHE BOOL "Should the library be packaged for publishing") 9 | mark_as_advanced(PREPARE_FOR_PUBLISH) 10 | 11 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/deps/cmake/modules/" ${CMAKE_MODULE_PATH}) 12 | 13 | if (NOT EMSCRIPTEN) 14 | find_package(ANGLE REQUIRED) 15 | endif() 16 | 17 | add_subdirectory (src) 18 | if (NOT EMSCRIPTEN AND BUILD_EXAMPLES) 19 | add_subdirectory (examples/native) 20 | add_dependencies(hello_triangle webrays) 21 | endif() 22 | -------------------------------------------------------------------------------- /deps/include/angle_gl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // angle_gl.h: 7 | // Includes all necessary GL headers and definitions for ANGLE. 8 | // 9 | 10 | #ifndef ANGLEGL_H_ 11 | #define ANGLEGL_H_ 12 | 13 | #include "GLES/gl.h" 14 | #include "GLES/glext.h" 15 | #include "GLES2/gl2.h" 16 | #include "GLES2/gl2ext.h" 17 | #include "GLES3/gl3.h" 18 | #include "GLES3/gl31.h" 19 | #include "GLES3/gl32.h" 20 | 21 | // TODO(http://anglebug.com/3730): Autogenerate these enums from gl.xml 22 | // HACK: Defines for queries that are not in GLES 23 | #define GL_CONTEXT_PROFILE_MASK 0x9126 24 | #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 25 | #define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 26 | 27 | #endif // ANGLEGL_H_ 28 | -------------------------------------------------------------------------------- /examples/web/example1_hello_world.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | WebRays Example l: Hello World 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |

WebRays Example l: Hello World

19 | 20 |

21 |
22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/web/example1_hello_world_ar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | WebRays Example 1 + WebXR: Hello World AR 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |

WebRays Example 1 + WebXR: Hello World AR

19 | 20 |
21 | 22 |
23 |
24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/web/example1_hello_world_vr.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | WebRays Example 1 + WebXR: Hello World VR 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |

WebRays Example 1 + WebXR: Hello World VR

19 | 20 |
21 | 22 |
23 |
24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /deps/include/CL/cl_gl_ext.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2021 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #pragma message("All OpenGL-related extensions have been moved into cl_gl.h. Please include cl_gl.h directly.") 19 | -------------------------------------------------------------------------------- /deps/include/CL/cl_ext_intel.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | ******************************************************************************/ 17 | 18 | #include 19 | #pragma message("The Intel extensions have been moved into cl_ext.h. Please include cl_ext.h directly.") 20 | -------------------------------------------------------------------------------- /examples/web/example2_cube.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | WebRays Example 2: Antialized Cube 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |

WebRays Example 2: Antialized Cube

19 | 20 |

Orbit camera around object is available with mouse movement. Scroll wheel is used to zoom in and out.

21 |

22 |
23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /deps/include/GLES/egl.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (c) 2008-2017 The Khronos Group Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | /* 18 | * Skeleton egl.h to provide compatibility for early GLES 1.0 19 | * applications. Several early implementations included gl.h 20 | * in egl.h leading applications to include only egl.h 21 | */ 22 | 23 | #ifndef __legacy_egl_h_ 24 | #define __legacy_egl_h_ 25 | 26 | #include 27 | #include 28 | 29 | #endif /* __legacy_egl_h_ */ 30 | -------------------------------------------------------------------------------- /deps/include/CL/cl_dx9_media_sharing_intel.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #pragma message("The Intel DX9 media sharing extensions have been moved into cl_dx9_media_sharing.h. Please include cl_dx9_media_sharing.h directly.") 19 | -------------------------------------------------------------------------------- /examples/web/example3_lighting.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | WebRays Example 3: Lighting & Shadows 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |

WebRays Example 3: Lighting & Shadows

19 | 20 |

Orbit camera around object is available with mouse movement. Scroll wheel is used to zoom in and out.

21 |

22 |
23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/web/example4_pt.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | WebRays Example 4: Path Tracing 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |

WebRays Viewer

20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /deps/include/CL/opencl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2021 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __OPENCL_H 18 | #define __OPENCL_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* __OPENCL_H */ 33 | -------------------------------------------------------------------------------- /src/webrays_tlas.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _WRAYS_TOP_LEVEL_ACCELERATION_DATA_STRUCTURE_H_ 17 | #define _WRAYS_TOP_LEVEL_ACCELERATION_DATA_STRUCTURE_H_ 18 | 19 | #include 20 | 21 | struct Instance 22 | { 23 | float transform[12]; 24 | int blas_offset; 25 | int pad0; 26 | int pad1; 27 | int pad2; 28 | }; 29 | 30 | class TLAS 31 | { 32 | public: 33 | std::vector m_instances; 34 | 35 | protected: 36 | }; 37 | 38 | #endif /* _WRAYS_TOP_LEVEL_ACCELERATION_DATA_STRUCTURE_H_ */ 39 | -------------------------------------------------------------------------------- /deps/include/vulkan/vulkan_fuchsia_ext.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2019 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // vulkan_fuchsia_ext: 7 | // Defines Fuchsia-specific Vulkan extensions when compiling on other 8 | // platforms. 9 | // 10 | 11 | #ifndef COMMON_VULKAN_FUCHSIA_EXT_H_ 12 | #define COMMON_VULKAN_FUCHSIA_EXT_H_ 13 | 14 | #if !defined(VK_NO_PROTOTYPES) 15 | # define VK_NO_PROTOTYPES 16 | #endif 17 | 18 | #include 19 | 20 | // If this is not Fuchsia then define Fuchsia-specific types explicitly and include 21 | // vulkan_fuchsia.h to make it possible to compile the code on other platforms. 22 | // 23 | // TODO(https://anglebug.com/6040): Update all code to avoid dependencies on 24 | // Fuchsia-specific types when compiling on other platforms. Then remove this header. 25 | #if !defined(ANGLE_PLATFORM_FUCHSIA) 26 | typedef uint32_t zx_handle_t; 27 | # define ZX_HANDLE_INVALID ((zx_handle_t)0) 28 | # include 29 | #endif 30 | 31 | #endif // COMMON_VULKAN_FUCHSIA_EXT_H_ 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebRays - Ray Tracing on the Web 2 | 3 | ![version](https://img.shields.io/badge/version-0.8.0-blue) 4 | 5 | The goal of WebRays is to offer a flexible and easy-to-use programming interface for robust and high-performance ray intersection tests on modern browsers. The core library is developed in C++ and compiled to WebAssembly. Although the main target of webrays is the Web, it can also be compiled and used as a native library on desktop platforms. 6 | 7 | ## Sources 8 | 9 | All required files to build and use WebRays can be cloned with 10 | 11 | ``` 12 | git clone https://github.com/phasmatic3d/webrays.git 13 | ``` 14 | 15 | ## Building 16 | 17 | View the [building instructions](doc/BUILDING.md). 18 | 19 | ## Examples 20 | 21 | Examples for both native and web versions of the library can be found under the `examples` folder 22 | 23 | ## API Reference 24 | 25 | A quick reference for the Web, Native and GLSL APIs can be found [here](doc/API_REFERENCE.md) 26 | 27 | ## Contributing 28 | 29 | We'd love to accept your patches and contributions to the WebRays project. 30 | 31 | * Try out WebRays in one of your projects and report any issues and bugs. 32 | * If you use WebRays in your own project, we'd love to hear about it! -------------------------------------------------------------------------------- /deps/include/GLES/glplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __glplatform_h_ 2 | #define __glplatform_h_ 3 | 4 | /* 5 | ** Copyright (c) 2017 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* Platform-specific types and definitions for OpenGL ES 1.X gl.h 21 | * 22 | * Adopters may modify khrplatform.h and this file to suit their platform. 23 | * Please contribute modifications back to Khronos as pull requests on the 24 | * public github repository: 25 | * https://github.com/KhronosGroup/OpenGL-Registry 26 | */ 27 | 28 | #include 29 | 30 | #ifndef GL_API 31 | #define GL_API KHRONOS_APICALL 32 | #endif 33 | 34 | #ifndef GL_APIENTRY 35 | #define GL_APIENTRY KHRONOS_APIENTRY 36 | #endif 37 | 38 | #endif /* __glplatform_h_ */ 39 | -------------------------------------------------------------------------------- /src/webrays_queue.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "webrays_queue.h" 17 | 18 | #include 19 | 20 | void 21 | wrays_queue_expand(void** address, wr_size capacity) 22 | { 23 | if (0 == capacity) 24 | return; 25 | 26 | wr_queue* queue; 27 | void* address_deref = *address; 28 | if (address_deref == WR_NULL) { 29 | queue = (wr_queue*)malloc(WR_FIELD_OFFSET(wr_queue, data) + capacity); 30 | queue->size = 0; 31 | } else { 32 | queue = (wr_queue*)realloc( 33 | ((unsigned char*)address_deref - WR_FIELD_OFFSET(wr_queue, data)), 34 | WR_FIELD_OFFSET(wr_queue, data) + capacity); 35 | } 36 | 37 | queue->capacity = capacity; 38 | queue = (wr_queue*)((unsigned char*)queue + WR_FIELD_OFFSET(wr_queue, data)); 39 | 40 | *address = queue; 41 | } -------------------------------------------------------------------------------- /deps/include/GLES/glext_angle.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2018 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // glext_angle.h: ANGLE modifications to the glext.h header file. 7 | // Currently we don't include this file directly, we patch glext.h 8 | // to include it implicitly so it is visible throughout our code. 9 | 10 | #ifndef INCLUDE_GLES_GLEXT_ANGLE_H_ 11 | #define INCLUDE_GLES_GLEXT_ANGLE_H_ 12 | 13 | // clang-format off 14 | 15 | // clang-format on 16 | 17 | #ifndef GL_ANGLE_yuv_internal_format 18 | #define GL_ANGLE_yuv_internal_format 19 | 20 | // YUV formats introduced by GL_ANGLE_yuv_internal_format 21 | // 8-bit YUV formats 22 | #define GL_G8_B8R8_2PLANE_420_UNORM_ANGLE 0x96B1 23 | #define GL_G8_B8_R8_3PLANE_420_UNORM_ANGLE 0x96B2 24 | 25 | // 10-bit YUV formats 26 | #define GL_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_ANGLE 0x96B3 27 | #define GL_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_ANGLE 0x96B4 28 | 29 | // 12-bit YUV formats 30 | #define GL_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_ANGLE 0x96B5 31 | #define GL_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_ANGLE 0x96B6 32 | 33 | // 16-bit YUV formats 34 | #define GL_G16_B16R16_2PLANE_420_UNORM_ANGLE 0x96B7 35 | #define GL_G16_B16_R16_3PLANE_420_UNORM_ANGLE 0x96B8 36 | 37 | #endif /* GL_ANGLE_yuv_internal_format */ 38 | 39 | #endif // INCLUDE_GLES_GLEXT_ANGLE_H_ 40 | -------------------------------------------------------------------------------- /deps/include/GLES/README.md: -------------------------------------------------------------------------------- 1 | # ANGLE GLES 1.0 Headers 2 | 3 | The GLES 1.0 headers ANGLE uses are generated using the Khronos tools but modified to include function pointer types and function prototype guards. 4 | 5 | ### Regenerating gl.h 6 | 7 | 1. Install **Python 3** (not 2) with the **lxml** addon. You can do this using `pip install lxml` from your Python's Scripts folder. 8 | 1. Clone [https://github.com/KhronosGroup/OpenGL-Registry.git](https://github.com/KhronosGroup/OpenGL-Registry.git). 9 | 1. Edit `OpenGL-Registry/xml/genheaders.py`: 10 | 11 | 1. Look for the section titled `# GLES 1.x API + mandatory extensions - GLES/gl.h (no function pointers)` 12 | 1. Change `prefixText = prefixStrings + gles1PlatformStrings + genDateCommentString,` to `prefixText = prefixStrings + gles1PlatformStrings + apiEntryPrefixStrings + genDateCommentString,` 13 | 1. Change `genFuncPointers = False,` to `genFuncPointers = True,` 14 | 1. Change `protectProto = False,` to `protectProto = 'nonzero',` 15 | 1. Change `protectProtoStr = 'GL_GLEXT_PROTOTYPES',` to `protectProtoStr = 'GL_GLES_PROTOTYPES',` 16 | 17 | 1. Set your working directory to `OpenGL-Registry/xml/`. 18 | 1. Run `python genheaders.py ../api/GLES/gl.h` 19 | 1. The generated header will now be in `OpenGL-Registry/api/GLES/gl.h`. You can copy the header over to this folder. 20 | 1. Also update `scripts/gl.xml` with the latest version from `OpenGL-Registry/xml/`. 21 | -------------------------------------------------------------------------------- /deps/include/export.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | 7 | // export.h : Defines ANGLE_EXPORT, a macro for exporting functions from the DLL 8 | 9 | #ifndef LIBGLESV2_EXPORT_H_ 10 | #define LIBGLESV2_EXPORT_H_ 11 | 12 | #if !defined(ANGLE_EXPORT) 13 | # if defined(_WIN32) 14 | # if defined(LIBGLESV2_IMPLEMENTATION) || defined(LIBANGLE_IMPLEMENTATION) || \ 15 | defined(LIBFEATURE_SUPPORT_IMPLEMENTATION) || defined(LIBCL_IMPLEMENTATION) 16 | # define ANGLE_EXPORT __declspec(dllexport) 17 | # else 18 | # define ANGLE_EXPORT __declspec(dllimport) 19 | # endif 20 | # elif defined(__GNUC__) 21 | # if defined(LIBGLESV2_IMPLEMENTATION) || defined(LIBANGLE_IMPLEMENTATION) || \ 22 | defined(LIBFEATURE_SUPPORT_IMPLEMENTATION) || defined(LIBCL_IMPLEMENTATION) 23 | # define ANGLE_EXPORT __attribute__((visibility("default"))) 24 | # else 25 | # define ANGLE_EXPORT 26 | # endif 27 | # else 28 | # define ANGLE_EXPORT 29 | # endif 30 | #endif // !defined(ANGLE_EXPORT) 31 | 32 | #if !defined(ANGLE_NO_EXPORT) 33 | # if defined(__GNUC__) 34 | # define ANGLE_NO_EXPORT __attribute__((visibility("hidden"))) 35 | # else 36 | # define ANGLE_NO_EXPORT 37 | # endif 38 | #endif // !defined(ANGLE_NO_EXPORT) 39 | 40 | #endif // LIBGLESV2_EXPORT_H_ 41 | -------------------------------------------------------------------------------- /src/webrays_cpu.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _WRAYS_CPU_H_ 17 | #define _WRAYS_CPU_H_ 18 | 19 | #include "webrays/webrays.h" 20 | 21 | const char* 22 | wrays_cpu_get_scene_accessor(wr_handle handle); 23 | const wr_binding* 24 | wrays_cpu_get_scene_accessor_bindings(wr_handle handle, wr_size* count); 25 | 26 | wr_error 27 | wrays_cpu_init(wr_handle handle); 28 | wr_error 29 | wrays_cpu_update(wr_handle handle); 30 | 31 | wr_error 32 | wrays_cpu_add_shape(wr_handle handle, wr_handle ads, float* positions, 33 | int position_stride, float* normals, int normal_stride, 34 | float* uvs, int uv_stride, int attr_count, int* faces, 35 | int num_triangles, int* shape_id); 36 | 37 | wr_error 38 | wrays_cpu_ads_create(wr_handle handle, wr_handle ads, 39 | wr_ads_descriptor* descriptor); 40 | 41 | #endif /* _WRAYS_CPU_H_ */ 42 | -------------------------------------------------------------------------------- /examples/native/hello_triangle/kernels/hello.fs.glsl: -------------------------------------------------------------------------------- 1 | precision highp float; 2 | 3 | layout(location = 0) out vec4 out_Color; 4 | 5 | #define FLT_MAX 1.e27 6 | 7 | uniform int u_ADS; 8 | uniform vec3 u_CameraPos, u_CameraUp, u_CameraFront; 9 | uniform float u_CameraFov; 10 | uniform ivec2 u_Dimensions; 11 | 12 | void main(){ 13 | // A. Generate Primary Rays 14 | float sx = (gl_FragCoord.x + 0.5) / float(u_Dimensions.x); 15 | float sy = (gl_FragCoord.y + 0.5) / float(u_Dimensions.y); 16 | float tanFOV2 = tan(radians(u_CameraFov)*0.5); 17 | vec3 cx = tanFOV2 * normalize(cross(u_CameraFront, u_CameraUp)); 18 | vec3 cy = (tanFOV2 / (float(u_Dimensions.x)/float(u_Dimensions.y))) * normalize(cross(cx, u_CameraFront)); 19 | 20 | vec3 ray_origin = u_CameraPos; 21 | vec3 ray_direction = normalize((2.0*sx - 1.0)*cx + (2.0*sy - 1.0)*cy + u_CameraFront); 22 | 23 | // B. Perform Ray Intersection Tests 24 | ivec4 ray_intersection = wr_QueryIntersection(u_ADS, ray_origin, ray_direction, FLT_MAX); 25 | 26 | // C. Compute Color 27 | vec3 ray_color; 28 | // C.1. Miss stage 29 | if (ray_intersection.x < 0) { 30 | ray_color = vec3(0,0,1.0); // White background 31 | } 32 | // C.2. Hit stage 33 | else { 34 | // Visualize using the barycentric coordinates of the intersection 35 | ray_color.xy = wr_GetBaryCoords(ray_intersection); 36 | ray_color.z = 1.0 - ray_color.x - ray_color.y; 37 | } 38 | 39 | out_Color = vec4(ray_color, 0.0); 40 | } -------------------------------------------------------------------------------- /examples/web/kernels/light.inc.glsl: -------------------------------------------------------------------------------- 1 | /* Lighting */ 2 | struct wr_light 3 | { 4 | int type; 5 | vec3 position; 6 | vec3 power; 7 | }; 8 | 9 | #define WR_LIGHT_TYPE_POINT 1 10 | #define WR_LIGHT_TYPE_QUAD 2 11 | wr_light Lights_sample(float u, out float pdf); 12 | vec3 Light_sample(const in event evt, const in wr_light light, const in vec2 u, out vec3 EtL, out float pdf, out float dist); 13 | 14 | wr_light Lights_sample(float u, out float pdf) { 15 | int light_index = clamp(int(u * float(light_count)), 0, light_count - 1); 16 | vec4 position_type = texelFetch(lightBuffer, ivec2(0,light_index), 0); 17 | vec4 power_count = texelFetch(lightBuffer, ivec2(1,light_index), 0); 18 | wr_light light; 19 | light.type = int(position_type.w); 20 | 21 | if (light.type == WR_LIGHT_TYPE_POINT) { 22 | light.position = position_type.xyz; 23 | light.power = power_count.xyz; 24 | pdf = 1.0 / float(light_count); 25 | } else { 26 | pdf = 0.000001; 27 | } 28 | 29 | return light; 30 | } 31 | 32 | vec3 Light_sample(const in event evt, const in wr_light light, const in vec2 u, out vec3 EtL, out float pdf, out float dist) { 33 | dist = 0.0; 34 | pdf = 0.0; 35 | EtL = vec3(0); 36 | if (light.type == WR_LIGHT_TYPE_POINT) { 37 | vec3 light_direction = light.position - evt.position; 38 | float light_dist = length(light_direction); 39 | float light_dist2 = light_dist * light_dist; 40 | pdf = 1.0; 41 | dist = light_dist; 42 | EtL = normalize(light_direction); 43 | return (light.power / WR_4PI) / max(0.001, light_dist2); 44 | } 45 | return vec3(100,100,100); 46 | } -------------------------------------------------------------------------------- /examples/web/kernels/common.inc.glsl: -------------------------------------------------------------------------------- 1 | #define WR_PI 3.14159265359 2 | #define WR_2PI 6.28318530718 3 | #define WR_INV_PI 0.31830988618 4 | #define WR_INV_2PI 0.15915494309 5 | #define WR_4PI 12.5663706144 6 | 7 | struct onb 8 | { 9 | vec3 tangent; 10 | vec3 bitangent; 11 | vec3 normal; 12 | }; 13 | 14 | vec3 hemisphere_cosine_sample(vec2 u); 15 | float hemisphere_cosine_pdf(float costheta); 16 | 17 | onb create_onb(const in vec3 n); 18 | vec3 onb_from(const in onb basis, vec3 v); 19 | vec3 onb_to(const in onb basis, vec3 v); 20 | 21 | onb create_onb(const in vec3 n) 22 | { 23 | onb basis; 24 | //float sign = copysignf(1.0f, n.z); 25 | float sign = (n.z >= 0.0) ? 1.0 : -1.0; 26 | float a = -1.0 / (sign + n.z); 27 | float b = n.x * n.y * a; 28 | basis.tangent = vec3(1.0 + sign * n.x * n.x * a, sign * b, -sign * n.x); 29 | basis.bitangent = vec3(b, sign + n.y * n.y * a, -n.y); 30 | basis.normal = n; 31 | return basis; 32 | } 33 | 34 | vec3 35 | onb_from(const in onb basis, vec3 v) 36 | { 37 | return normalize(v.x * basis.tangent + v.y * basis.bitangent + v.z * basis.normal); 38 | } 39 | 40 | vec3 41 | onb_to(const in onb basis, vec3 v) 42 | { 43 | return normalize(vec3(dot(basis.tangent, v), dot(basis.bitangent, v), dot(basis.normal, v))); 44 | } 45 | 46 | float hemisphere_cosine_pdf(float costheta) { 47 | return costheta * WR_INV_PI; 48 | } 49 | 50 | vec3 hemisphere_cosine_sample(vec2 u) { 51 | // Uniformly sample disk. 52 | float r = sqrt(u.x); 53 | float phi = 2.0 * WR_PI * u.y; 54 | vec3 p; 55 | p.x = r * cos(phi); 56 | p.y = r * sin(phi); 57 | 58 | // Project up to hemisphere. 59 | p.z = sqrt(max(0.0, 1.0 - p.x*p.x - p.y*p.y)); 60 | return p; 61 | } -------------------------------------------------------------------------------- /doc/BUILDING_WINDOWS.md: -------------------------------------------------------------------------------- 1 | # Build webrays on Windows 2 | 3 | ANGLE has seen great adaption on Windows. It is the default graphics backend on the 3 major browsers, namely Chrome, Firefox and Edge. The `cmake` script first attempts to find the ANGLE libraries in the installation of one of those browsers. Alternatively, you can compile ANGLE yourself using the instructions on their github [repo](https://github.com/google/angle) 4 | 5 | You will also need to download the SDL2 development libraries from the [official site](https://www.libsdl.org/download-2.0.php) or some other source. 6 | 7 | **!!IMPORTANT!!** For maximum compatibility it is advices to execute the following commands from a console shell that is setup with the Visual Studio environment of your choice. In most recent Visual Studio versions, the batch files to setup the proper environment can be found at `C:\Program Files (x86)\Microsoft Visual Studio\\\VC\Auxiliary\Build` 8 | 9 | Simply run the `vcvars64.bat` batch file in your current console. 10 | 11 | ``` 12 | cmake -S . -B build -DBUILD_EXAMPLES=1 -DSDL2_PATH=/path/to/SDL2 13 | ``` 14 | or for older Visual Studio versions you should also specify the platform (x64) 15 | ``` 16 | cmake -G "Visual Studio 15 2017" -A x64 -S . -B build -DBUILD_EXAMPLES=1 -DSDL2_PATH=/path/to/SDL2 17 | ``` 18 | 19 | 2. 20 | "D:\Tools\cmake-3.18.1-win64-x64\bin\cmake.exe" --build build_web --config Release 21 | 22 | 3. 23 | "D:\Tools\cmake-3.18.1-win64-x64\bin\cmake.exe" --install build_web --config Release 24 | 25 | 4. 26 | cd bin 27 | 28 | 5. 29 | python2 -m SimpleHTTPServer 30 | or 31 | python3 -m http.server 32 | 33 | -- Build webrays for Native development 34 | 35 | -- Win32 36 | 37 | To build with examples issue 38 | 39 | "D:\Tools\cmake-3.18.1-win64-x64\bin\cmake" -S . -B build -DCMAKE_INSTALL_PREFIX=. -DBUILD_EXAMPLES=1 -DSDL2_PATH="D:\C++\Projects\Phasmatic\webrays\Dependencies\SDL2" 40 | 41 | 42 | -------------------------------------------------------------------------------- /examples/web/kernels/generate.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision highp float; 3 | 4 | layout(location = 0) out vec4 accumulation_OUT; 5 | layout(location = 1) out vec4 origin_OUT; 6 | layout(location = 2) out vec4 direction_OUT; 7 | layout(location = 3) out vec4 payload_OUT; 8 | 9 | uniform ivec4 tile; 10 | uniform ivec2 frame; 11 | uniform uvec2 seed; 12 | /* Camera */ 13 | uniform vec3 camera_pos; 14 | uniform vec3 camera_up; 15 | uniform vec3 camera_front; 16 | uniform vec3 camera_right; 17 | uniform float camera_vfov; 18 | 19 | uniform mat4 ViewInvMatrix; 20 | uniform mat4 ProjectionInvMatrix; 21 | 22 | /* For random4f */ 23 | #include "util.inc.glsl" 24 | 25 | #define USE_INVERSE_MATRIX_PROJECTION 26 | void main() { 27 | vec4 tilef = vec4(tile); 28 | vec2 framef = vec2(frame); 29 | vec2 pixel = tilef.xy * tilef.zw + gl_FragCoord.xy; 30 | vec2 pixel_norm = pixel / framef; 31 | 32 | uint counter = uint(pixel.x) + uint(pixel.y) * uint(frame.x) + 1u; 33 | vec4 randoms = random4f(counter, seed.x, seed.y); 34 | 35 | /* Jitter pixel coordinates */ 36 | pixel_norm = pixel_norm + randoms.xy / framef; 37 | 38 | #ifdef USE_INVERSE_MATRIX_PROJECTION 39 | vec4 pndc = vec4(2.0 * pixel_norm - 1.0, 0.0, 1.0); 40 | vec4 pecs = ProjectionInvMatrix * pndc; 41 | pecs /= pecs.w; 42 | 43 | vec4 direction_ecs = normalize(vec4(pecs.xyz, 0.0)); 44 | vec3 ray_origin = vec3(ViewInvMatrix * vec4(pecs.xyz, 1.0)); 45 | vec3 ray_direction = normalize(vec3(ViewInvMatrix * direction_ecs)); 46 | #else 47 | float tanFOV2 = tan(radians(camera_vfov) / 2.0); 48 | vec3 cx = tanFOV2 * (framef.x / framef.y) * normalize(cross(camera_front, camera_up)); 49 | vec3 cy = tanFOV2 * normalize(cross(cx, camera_front)); 50 | 51 | vec3 ray_origin = camera_pos; 52 | vec3 ray_direction = normalize(2.0 * (pixel_norm.x - 0.5) * cx + 2.0 * (pixel_norm.y - 0.5) * cy + camera_front); 53 | #endif 54 | 55 | direction_OUT = vec4(ray_direction, 10000.0); 56 | origin_OUT = vec4(camera_pos, 0.0); 57 | accumulation_OUT = vec4(0, 0, 0, 0); 58 | payload_OUT = vec4(1,1,1,0); // throughput 59 | } -------------------------------------------------------------------------------- /doc/BUILDING_LINUX.md: -------------------------------------------------------------------------------- 1 | # Build webrays on Linux 2 | 3 | To build webrays and the examples you will at least need something like the following command, depending on your distro's package manager. 4 | 5 | ``` 6 | apt-get install build-essential cmake libsdl2-dev 7 | ``` 8 | 9 | Next, we will require a build of ANGLE. Follow the instructions from ANGLE's repository to build ANGLE from source. Make sure to build a shared version with `is_component_build = false` in order to link dependencies into the build targets. 10 | 11 | With SDL2 and ANGLE installed we simply point our console to the cloned webrays folder and execute 12 | 13 | ``` 14 | cmake -S . -B build -DBUILD_EXAMPLES=1 -DEGL_LIBRARY=path/to/ANGLE/libEGL.so -DGLES_LIBRARY=path/to/ANGLE/libGLESv2.so -DCMAKE_BUILD_TYPE=Release 15 | ``` 16 | 17 | Alternatively, you can use a precompiled version of ANGLE. For example if you happen to have Visual Studio Code installed, it already comes with a compiled version of ANGLE. 18 | 19 | ``` 20 | cmake -S . -B build -DBUILD_EXAMPLES=1 -DEGL_LIBRARY=/usr/share/code/libEGL.so -DGLES_LIBRARY=/usr/share/code/libGLESv2.so -DCMAKE_BUILD_TYPE=Release 21 | ``` 22 | 23 | Build with 24 | 25 | ``` 26 | cmake --build build --config Release 27 | ``` 28 | 29 | Finally, install with 30 | 31 | ``` 32 | cmake --install build --config Release 33 | ``` 34 | 35 | If you prefer a non-default installation path, you can pass `-DCMAKE_INSTALL_PREFIX=/custom/install/path` to the first `cmake` command. 36 | 37 | ## Using webrays in your own application 38 | 39 | After building or installing, it is very easy to use webrays in your own application. An important aspect that you need to consider is that your application and webrays need to use the same libGLESv2 library from ANGLE in order to properly work on the same context. This is easily taken care of by accordingly setting the `rpath` during compilation. 40 | 41 | For example, the `hello_triangle` example can be manually built using the following command 42 | 43 | ``` 44 | clang hello_triangle.c -Wl,-rpath,\$ORIGIN -I /usr/include/SDL2 -I/custom/install/path/webrays/include -o hello_triangle -L/custom/install/path/webrays/lib -lSDL2 -lEGL -lGLESv2 -lwebrays 45 | ``` -------------------------------------------------------------------------------- /deps/include/CL/cl_layer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * OpenCL is a trademark of Apple Inc. used under license by Khronos. 17 | */ 18 | 19 | #ifndef OPENCL_CL_LAYER_H 20 | #define OPENCL_CL_LAYER_H 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef cl_uint cl_layer_info; 29 | typedef cl_uint cl_layer_api_version; 30 | #define CL_LAYER_API_VERSION 0x4240 31 | #define CL_LAYER_API_VERSION_100 100 32 | 33 | extern CL_API_ENTRY cl_int CL_API_CALL 34 | clGetLayerInfo(cl_layer_info param_name, 35 | size_t param_value_size, 36 | void *param_value, 37 | size_t *param_value_size_ret); 38 | 39 | typedef cl_int 40 | (CL_API_CALL *pfn_clGetLayerInfo)(cl_layer_info param_name, 41 | size_t param_value_size, 42 | void *param_value, 43 | size_t *param_value_size_ret); 44 | 45 | extern CL_API_ENTRY cl_int CL_API_CALL 46 | clInitLayer(cl_uint num_entries, 47 | const cl_icd_dispatch *target_dispatch, 48 | cl_uint *num_entries_ret, 49 | const cl_icd_dispatch **layer_dispatch_ret); 50 | 51 | typedef cl_int 52 | (CL_API_CALL *pfn_clInitLayer)(cl_uint num_entries, 53 | const cl_icd_dispatch *target_dispatch, 54 | cl_uint *num_entries_ret, 55 | const cl_icd_dispatch **layer_dispatch_ret); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* OPENCL_CL_LAYER_H */ 62 | -------------------------------------------------------------------------------- /examples/web/js/common/webrays_utils.js: -------------------------------------------------------------------------------- 1 | import * as WebRays from './webrays.js'; 2 | 3 | // 4 | // Constructor 5 | // 6 | export function get_instance(gl) 7 | { 8 | return new WebRays.WebGLIntersectionEngine(gl); 9 | } 10 | 11 | // 12 | // Top-level Acceleration data structure creation 13 | // 14 | export function create_tlas_ads(wr) 15 | { 16 | return wr.CreateAds({type : "TLAS" }); 17 | } 18 | 19 | // 20 | // Bottom-level Acceleration data structure creation 21 | // 22 | export function create_blas_ads(wr) 23 | { 24 | return wr.CreateAds({type : "BLAS" }); 25 | } 26 | 27 | // 28 | // Fill ADS with mesh information 29 | // 30 | export function add_shape(wr, ads_index, mesh) 31 | { 32 | wr.AddShape(ads_index, mesh.vertex_data, mesh.vertex_size, 33 | mesh.normal_data, mesh.normal_size, 34 | mesh.uv_data , mesh.uv_size, 35 | mesh.face_data 36 | ); 37 | } 38 | 39 | // 40 | // Add BLAS instance to TLAS 41 | // 42 | export function add_instance(wr, tlas_index, blas_index, transform) 43 | { 44 | return wr.AddInstance(tlas_index, blas_index, transform); 45 | } 46 | 47 | // 48 | // Update ADS 49 | // 50 | export function update(wr) 51 | { 52 | return wr.Update(); 53 | } 54 | 55 | // 56 | // Get generated shader source 57 | // 58 | export function get_shader_source(wr) 59 | { 60 | return '#version 300 es\n' + wr.GetSceneAccessorString(); 61 | } 62 | 63 | // 64 | // Map ADS bindings to the corresponding shader program 65 | // 66 | export function set_bindings(wr, gl, program, next_texture_unit) 67 | { 68 | var bindings = wr.Bindings; 69 | for (var binding_index = 0; binding_index < bindings.length; ++binding_index) 70 | { 71 | let binding = bindings[binding_index]; 72 | 73 | // if UBO 74 | if (binding.Type == 1) { 75 | } 76 | // if Texture 2D or Texture Array 2D 77 | else { 78 | let bindingType = (binding.Type == 2) ? gl.TEXTURE_2D : gl.TEXTURE_2D_ARRAY; 79 | 80 | gl.activeTexture(gl.TEXTURE0 + next_texture_unit); 81 | gl.bindTexture (bindingType, binding.Texture); 82 | gl.uniform1i (gl.getUniformLocation(program, binding.Name), next_texture_unit); 83 | next_texture_unit++; 84 | } 85 | } 86 | 87 | return next_texture_unit; 88 | } -------------------------------------------------------------------------------- /deps/include/angle_windowsstore.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // angle_windowsstore.h: 7 | 8 | #ifndef ANGLE_WINDOWSSTORE_H_ 9 | #define ANGLE_WINDOWSSTORE_H_ 10 | 11 | // The following properties can be set on the CoreApplication to support additional 12 | // ANGLE configuration options. 13 | // 14 | // The Visual Studio sample templates provided with this version of ANGLE have examples 15 | // of how to set these property values. 16 | 17 | // 18 | // Property: EGLNativeWindowTypeProperty 19 | // Type: IInspectable 20 | // Description: Set this property to specify the window type to use for creating a surface. 21 | // If this property is missing, surface creation will fail. 22 | // 23 | const wchar_t EGLNativeWindowTypeProperty[] = L"EGLNativeWindowTypeProperty"; 24 | 25 | // 26 | // Property: EGLRenderSurfaceSizeProperty 27 | // Type: Size 28 | // Description: Set this property to specify a preferred size in pixels of the render surface. 29 | // The render surface size width and height must be greater than 0. 30 | // If this property is set, then the render surface size is fixed. 31 | // The render surface will then be scaled to the window dimensions. 32 | // If this property is missing, a default behavior will be provided. 33 | // The default behavior uses the window size if a CoreWindow is specified or 34 | // the size of the SwapChainPanel control if one is specified. 35 | // 36 | const wchar_t EGLRenderSurfaceSizeProperty[] = L"EGLRenderSurfaceSizeProperty"; 37 | 38 | // 39 | // Property: EGLRenderResolutionScaleProperty 40 | // Type: Single 41 | // Description: Use this to specify a preferred scale for the render surface compared to the window. 42 | // For example, if the window is 800x480, and: 43 | // - scale is set to 0.5f then the surface will be 400x240 44 | // - scale is set to 1.2f then the surface will be 960x576 45 | // If the window resizes or rotates then the surface will resize accordingly. 46 | // EGLRenderResolutionScaleProperty and EGLRenderSurfaceSizeProperty cannot both be set. 47 | // The scale factor should be > 0.0f. 48 | // 49 | const wchar_t EGLRenderResolutionScaleProperty[] = L"EGLRenderResolutionScaleProperty"; 50 | 51 | #endif // ANGLE_WINDOWSSTORE_H_ 52 | -------------------------------------------------------------------------------- /doc/BUILDING_WEB.md: -------------------------------------------------------------------------------- 1 | # Build webrays for the Web 2 | 3 | Follow the instructions to install the [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html). 4 | 5 | After cloning and installing the latest toolchain, simply execute the scripts to set up the latest environment. 6 | 7 | For Linux and Mac OS 8 | 9 | ``` 10 | ./emsdk activate latest 11 | source ./emsdk_env.sh 12 | ``` 13 | or for Windows 14 | ``` 15 | "path\to\emsdk\emsdk" activate latest 16 | "path\to\emsdk\emsdk_env.bat" 17 | ``` 18 | 19 | To prepare build targets, on Linux and Mac OS, we simply execute 20 | 21 | ``` 22 | emcmake cmake -S . -B build -DCMAKE_BUILD_TYPE=Release 23 | ``` 24 | 25 | **!!IMPORTANT!!** On Windows the `make` utility is not available by default. We have 2 options. If Visual Studio is installed, we can use `nmake` which is a tool similar to `make` that comes with the standard Visual Studio installation. To be able to use `nmake` we need to setup the Visual Studio environment on our current console. In most recent Visual Studio versions, the batch files to setup the proper environment can be found at `C:\Program Files (x86)\Microsoft Visual Studio\\\VC\Auxiliary\Build` 26 | 27 | The console is now set up with both the Emscripten and Visual Studio environments. From here, we can issue the following command 28 | 29 | ``` 30 | emcmake cmake -S . -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release 31 | ``` 32 | 33 | If Visual Studio is not installed we can download a Windows version of `make`, e.g. from [here](http://gnuwin32.sourceforge.net/packages/make.htm) (Make sure to download both the `Binary` and the `Dependencies`). 34 | 35 | With `make` installed we execute the following command 36 | 37 | ``` 38 | emcmake cmake -S . -B build -G "Unix Makefiles" -DCMAKE_MAKE_PROGRAM=/path/to/make -DCMAKE_BUILD_TYPE=Release 39 | ``` 40 | 41 | Build the library and examples 42 | 43 | ``` 44 | cmake.exe --build build --config Release 45 | ``` 46 | 47 | Install the library and examples. 48 | 49 | ``` 50 | cmake.exe --install build --config Release 51 | ``` 52 | 53 | We can set the `CMAKE_INSTALL_PREFIX` variable during the initial `cmake` command to control the installation directory. E.g. `-DCMAKE_INSTALL_PREFIX=/path/to/install` 54 | 55 | then, 56 | 57 | ``` 58 | cd /path/to/install/webrays 59 | ``` 60 | 61 | And start a local server with 62 | 63 | ``` 64 | python2 -m SimpleHTTPServer 65 | ``` 66 | or 67 | ``` 68 | python3 -m http.server 69 | ``` 70 | 71 | Point your browser to 72 | ``` 73 | http://localhost:8000/ 74 | ``` 75 | And select one of the examples to start developing -------------------------------------------------------------------------------- /examples/web/kernels/util.inc.glsl: -------------------------------------------------------------------------------- 1 | // Utility Functions 2 | bool is_zerof(float u) { 3 | return (u == 0.0); 4 | } 5 | 6 | bool is_zero(vec3 u) { 7 | return (dot(u,u) == 0.0); 8 | } 9 | 10 | float luminance(vec3 rgb) 11 | { 12 | return dot(rgb, vec3(0.2126, 0.7152, 0.0722)); 13 | } 14 | 15 | #define m4x32_0 0xD2511F53u 16 | #define m4x32_1 0xCD9E8D57u 17 | #define w32_0 0x9E3779B9u 18 | #define w32_1 0xBB67AE85u 19 | 20 | /* compute the upper 32 bits of the product of two unsigned 32-bit integers */ 21 | void umulExtended_(uint a, uint b, out uint hi, out uint lo) { 22 | const uint WHALF = 16u; 23 | const uint LOMASK = (1u<>WHALF; 26 | uint alo = a& LOMASK; 27 | uint bhi = b>>WHALF; 28 | uint blo = b& LOMASK; 29 | 30 | uint ahbl = ahi*blo; 31 | uint albh = alo*bhi; 32 | 33 | uint ahbl_albh = ((ahbl&LOMASK) + (albh&LOMASK)); 34 | hi = ahi*bhi + (ahbl>>WHALF) + (albh>>WHALF); 35 | hi += ahbl_albh >> WHALF; /* carry from the sum of lo(ahbl) + lo(albh) ) */ 36 | /* carry from the sum with alo*blo */ 37 | hi += ((lo >> WHALF) < (ahbl_albh&LOMASK)) ? 1u : 0u; 38 | } 39 | 40 | uvec2 philox4x32Bumpkey(uvec2 key) { 41 | uvec2 ret = key; 42 | ret.x += 0x9E3779B9u; 43 | ret.y += 0xBB67AE85u; 44 | return ret; 45 | } 46 | 47 | uvec4 philox4x32Round(uvec4 state, uvec2 key) { 48 | const uint M0 = 0xD2511F53u, M1 = 0xCD9E8D57u; 49 | uint hi0, lo0, hi1, lo1; 50 | umulExtended_(M0, state.x, hi0, lo0); 51 | umulExtended_(M1, state.z, hi1, lo1); 52 | 53 | return uvec4( 54 | hi1^state.y^key.x, lo1, 55 | hi0^state.w^key.y, lo0); 56 | } 57 | 58 | uvec4 philox4x32_7(uvec4 plain, uvec2 key) { 59 | uvec4 state = plain; 60 | uvec2 round_key = key; 61 | 62 | for(int i=0; i<7; ++i) { 63 | state = philox4x32Round(state, round_key); 64 | round_key = philox4x32Bumpkey(round_key); 65 | } 66 | 67 | return state; 68 | } 69 | 70 | float uintToFloat(uint src) { 71 | return uintBitsToFloat(0x3f800000u | (src & 0x7fffffu))-1.0; 72 | } 73 | 74 | vec4 uintToFloat(uvec4 src) { 75 | return vec4(uintToFloat(src.x), uintToFloat(src.y), uintToFloat(src.z), uintToFloat(src.w)); 76 | } 77 | 78 | vec4 79 | random4f(uint index, uint seed0, uint seed1) { 80 | uvec2 key = uvec2( index , seed0 ); 81 | uvec4 ctr = uvec4( 0u , 0xf00dcafeu, 0xdeadbeefu, seed1 ); 82 | 83 | uvec4 state = ctr; 84 | uvec2 round_key = key; 85 | 86 | for(int i=0; i<7; ++i) { 87 | state = philox4x32Round(state, round_key); 88 | round_key = philox4x32Bumpkey(round_key); 89 | } 90 | 91 | return uintToFloat(state); 92 | } -------------------------------------------------------------------------------- /doc/BUILDING_MACOS.md: -------------------------------------------------------------------------------- 1 | # Build webrays on Linux 2 | 3 | To build webrays and the examples you will need to install XCode from the App Store in order to get a full development environment setup. 4 | 5 | Next, we will require a build of ANGLE. Follow the instructions from ANGLE's repository to build ANGLE from source. Make sure to build a shared version with `is_component_build = false` in order to link dependencies into the build targets. 6 | 7 | **!IMPORTANT!** The official development packages for Mac OS from the SDL website come as a self-contained framework. Frameworks package all dependencies, including libraries, headers and other resources in a single package. To use the SDL framework for building the examples we will need to set the `SDL2_PATH` variable during `cmake` configuration to point directly to the SDL2.framework instead of the folder. 8 | 9 | ``` 10 | /Applications/CMake.app/Contents/bin/cmake -S . -B build -DEGL_LIBRARY=/path/to/angle/libEGL.dylib -DGLES_LIBRARY=/path/to/angle/libGLESv2.dylib -DBUILD_EXAMPLES=1 -DSDL2_PATH=/path/to/SDL2.framework 11 | ``` 12 | 13 | Alternatively, we can use a precompiled version of ANGLE. For example if you happen to have Visual Studio Code installed, it already comes with a compiled version of ANGLE. 14 | 15 | ``` 16 | /Applications/CMake.app/Contents/bin/cmake -S . -B build -DEGL_LIBRARY=/Applications/Visual\ Studio\ Code.app/Contents/Frameworks/Electron\ Framework.framework/Versions/A/Libraries/libEGL.dylib -DGLES_LIBRARY=/Applications/Visual\ Studio\ Code.app/Contents/Frameworks/Electron\ Framework.framework/Versions/A/Libraries/libGLESv2.dylib -DBUILD_EXAMPLES=1 -DSDL2_PATH=/path/to/SDL2.framework 17 | ``` 18 | 19 | If all goes well, build with 20 | 21 | ``` 22 | /Applications/CMake.app/Contents/bin/cmake --build build --config Release 23 | ``` 24 | 25 | Finally, install with 26 | 27 | ``` 28 | /Applications/CMake.app/Contents/bin/cmake --install build --config Release 29 | ``` 30 | 31 | If you prefer a non-default installation path, you can pass `-DCMAKE_INSTALL_PREFIX=/custom/install/path` to the first `cmake` command. 32 | 33 | ## Using webrays in your own application 34 | 35 | After building or installing, it is very easy to use webrays in your own application. An important apsect that you need to consider is that your application and webrays need to use the same libGLESv2 library from ANGLE in order to properly work on the same context. This is easily taken care by accordingly setting the `rpath` during compilation. 36 | 37 | For example, the `hello_triangle` example can be manually built using the following command 38 | 39 | ``` 40 | clang hello_triangle.c -Wl,-rpath,@executable_path -I/custom/install/path/webrays/include -I/path/to/SDL2.framework/Headers -o hello_triangle -L/custom/install/path/webrays/lib -F/path/to/sdl -framework SDL2 -lEGL -lGLESv2 -lwebrays 41 | ``` -------------------------------------------------------------------------------- /src/webrays_queue.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _WRAYS_QUEUE_H_ 17 | #define _WRAYS_QUEUE_H_ 18 | 19 | #include 20 | 21 | #define WR_FIELD_OFFSET(type, field) ((unsigned long long)&(((type*)0)->field)) 22 | 23 | typedef struct wr_queue 24 | { 25 | wr_size size; 26 | wr_size capacity; 27 | wr_byte data[1]; 28 | } wr_queue; 29 | 30 | void 31 | wrays_queue_expand(void** address, wr_size capacity); 32 | 33 | #define wrays_queue_init(address, capacity) \ 34 | { \ 35 | address = WR_NULL; \ 36 | wrays_queue_expand((void**)&address, sizeof(*address) * capacity); \ 37 | } 38 | 39 | #define wrays_queue_size(address) \ 40 | ((wr_queue*)((wr_byte*)address - WR_FIELD_OFFSET(wr_queue, data)))->size 41 | 42 | #define wrays_queue_capacity(address) \ 43 | (((wr_queue*)((wr_byte*)address - WR_FIELD_OFFSET(wr_queue, data))) \ 44 | ->capacity / \ 45 | sizeof(*address)) 46 | 47 | #define wrays_queue_last(address) \ 48 | ((wrays_queue_size(address)) ? address[wrays_queue_size(address) - 1] \ 49 | : GRB_NULL) 50 | 51 | #define wrays_queue_remove(address) \ 52 | if (wrays_queue_size(address)) \ 53 | wrays_queue_size(address)-- 54 | 55 | #define wrays_queue_push(address, value) \ 56 | { \ 57 | if (wrays_queue_size(address) == wrays_queue_capacity(address)) { \ 58 | \ 59 | wrays_queue_expand((void**)&address, sizeof(*address) * \ 60 | wrays_queue_capacity(address) * \ 61 | 2); \ 62 | } \ 63 | address[wrays_queue_size(address)++] = value; \ 64 | } 65 | 66 | #endif /* _WRAYS_QUEUE_H_ */ 67 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: Mozilla 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: true 7 | AlignConsecutiveDeclarations: true 8 | AlignEscapedNewlinesLeft: false 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | AllowAllParametersOfDeclarationOnNextLine: false 12 | AllowShortBlocksOnASingleLine: false 13 | AllowShortCaseLabelsOnASingleLine: true 14 | AllowShortFunctionsOnASingleLine: Inline 15 | AllowShortIfStatementsOnASingleLine: false 16 | AllowShortLoopsOnASingleLine: false 17 | AlwaysBreakAfterDefinitionReturnType: All 18 | AlwaysBreakAfterReturnType: All 19 | AlwaysBreakBeforeMultilineStrings: false 20 | AlwaysBreakTemplateDeclarations: true 21 | BinPackArguments: true 22 | BinPackParameters: true 23 | BraceWrapping: 24 | AfterClass: true 25 | AfterControlStatement: false 26 | AfterEnum: true 27 | AfterFunction: true 28 | AfterNamespace: false 29 | AfterObjCDeclaration: false 30 | AfterStruct: true 31 | AfterUnion: true 32 | BeforeCatch: false 33 | BeforeElse: false 34 | IndentBraces: false 35 | BreakBeforeBinaryOperators: None 36 | BreakBeforeBraces: Mozilla 37 | BreakBeforeTernaryOperators: true 38 | BreakConstructorInitializersBeforeComma: true 39 | BreakAfterJavaFieldAnnotations: false 40 | BreakStringLiterals: true 41 | ColumnLimit: 80 42 | CommentPragmas: '^ IWYU pragma:' 43 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 44 | ConstructorInitializerIndentWidth: 2 45 | ContinuationIndentWidth: 2 46 | Cpp11BracedListStyle: false 47 | DerivePointerAlignment: false 48 | DisableFormat: false 49 | ExperimentalAutoDetectBinPacking: false 50 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 51 | IncludeCategories: 52 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 53 | Priority: 2 54 | - Regex: '^(<|"(gtest|isl|json)/)' 55 | Priority: 3 56 | - Regex: '.*' 57 | Priority: 1 58 | IncludeIsMainRegex: '$' 59 | IndentCaseLabels: true 60 | IndentWidth: 2 61 | IndentWrappedFunctionNames: false 62 | JavaScriptQuotes: Leave 63 | JavaScriptWrapImports: true 64 | KeepEmptyLinesAtTheStartOfBlocks: true 65 | MacroBlockBegin: '' 66 | MacroBlockEnd: '' 67 | MaxEmptyLinesToKeep: 1 68 | NamespaceIndentation: None 69 | ObjCBlockIndentWidth: 2 70 | ObjCSpaceAfterProperty: true 71 | ObjCSpaceBeforeProtocolList: false 72 | PenaltyBreakBeforeFirstCallParameter: 19 73 | PenaltyBreakComment: 300 74 | PenaltyBreakFirstLessLess: 120 75 | PenaltyBreakString: 1000 76 | PenaltyExcessCharacter: 1000000 77 | PenaltyReturnTypeOnItsOwnLine: 200 78 | PointerAlignment: Left 79 | ReflowComments: true 80 | SortIncludes: false 81 | SpaceAfterCStyleCast: false 82 | SpaceBeforeAssignmentOperators: true 83 | SpaceBeforeParens: ControlStatements 84 | SpaceInEmptyParentheses: false 85 | SpacesBeforeTrailingComments: 1 86 | SpacesInAngles: false 87 | SpacesInContainerLiterals: true 88 | SpacesInCStyleCastParentheses: false 89 | SpacesInParentheses: false 90 | SpacesInSquareBrackets: false 91 | Standard: Cpp11 92 | TabWidth: 8 93 | UseTab: Never 94 | ... 95 | -------------------------------------------------------------------------------- /deps/include/CL/cl_version.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2018-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __CL_VERSION_H 18 | #define __CL_VERSION_H 19 | 20 | /* Detect which version to target */ 21 | #if !defined(CL_TARGET_OPENCL_VERSION) 22 | #pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)") 23 | #define CL_TARGET_OPENCL_VERSION 300 24 | #endif 25 | #if CL_TARGET_OPENCL_VERSION != 100 && \ 26 | CL_TARGET_OPENCL_VERSION != 110 && \ 27 | CL_TARGET_OPENCL_VERSION != 120 && \ 28 | CL_TARGET_OPENCL_VERSION != 200 && \ 29 | CL_TARGET_OPENCL_VERSION != 210 && \ 30 | CL_TARGET_OPENCL_VERSION != 220 && \ 31 | CL_TARGET_OPENCL_VERSION != 300 32 | #pragma message("cl_version: CL_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220, 300). Defaulting to 300 (OpenCL 3.0)") 33 | #undef CL_TARGET_OPENCL_VERSION 34 | #define CL_TARGET_OPENCL_VERSION 300 35 | #endif 36 | 37 | 38 | /* OpenCL Version */ 39 | #if CL_TARGET_OPENCL_VERSION >= 300 && !defined(CL_VERSION_3_0) 40 | #define CL_VERSION_3_0 1 41 | #endif 42 | #if CL_TARGET_OPENCL_VERSION >= 220 && !defined(CL_VERSION_2_2) 43 | #define CL_VERSION_2_2 1 44 | #endif 45 | #if CL_TARGET_OPENCL_VERSION >= 210 && !defined(CL_VERSION_2_1) 46 | #define CL_VERSION_2_1 1 47 | #endif 48 | #if CL_TARGET_OPENCL_VERSION >= 200 && !defined(CL_VERSION_2_0) 49 | #define CL_VERSION_2_0 1 50 | #endif 51 | #if CL_TARGET_OPENCL_VERSION >= 120 && !defined(CL_VERSION_1_2) 52 | #define CL_VERSION_1_2 1 53 | #endif 54 | #if CL_TARGET_OPENCL_VERSION >= 110 && !defined(CL_VERSION_1_1) 55 | #define CL_VERSION_1_1 1 56 | #endif 57 | #if CL_TARGET_OPENCL_VERSION >= 100 && !defined(CL_VERSION_1_0) 58 | #define CL_VERSION_1_0 1 59 | #endif 60 | 61 | /* Allow deprecated APIs for older OpenCL versions. */ 62 | #if CL_TARGET_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS) 63 | #define CL_USE_DEPRECATED_OPENCL_2_2_APIS 64 | #endif 65 | #if CL_TARGET_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS) 66 | #define CL_USE_DEPRECATED_OPENCL_2_1_APIS 67 | #endif 68 | #if CL_TARGET_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS) 69 | #define CL_USE_DEPRECATED_OPENCL_2_0_APIS 70 | #endif 71 | #if CL_TARGET_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) 72 | #define CL_USE_DEPRECATED_OPENCL_1_2_APIS 73 | #endif 74 | #if CL_TARGET_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 75 | #define CL_USE_DEPRECATED_OPENCL_1_1_APIS 76 | #endif 77 | #if CL_TARGET_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS) 78 | #define CL_USE_DEPRECATED_OPENCL_1_0_APIS 79 | #endif 80 | 81 | #endif /* __CL_VERSION_H */ 82 | -------------------------------------------------------------------------------- /examples/native/hello_triangle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | cmake_policy(SET CMP0048 NEW) 3 | 4 | project (hello_triangle) 5 | 6 | add_executable(hello_triangle 7 | hello_triangle.c 8 | ) 9 | 10 | if(WIN32) 11 | string(REPLACE "SDL2.lib" "SDL2.dll" SDL2_LIBPATH "${SDL2_LIBRARY}") 12 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 13 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 14 | "${SDL2_LIBPATH}" 15 | "${CMAKE_BINARY_DIR}/bin/$") 16 | 17 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 18 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 19 | "${GLES_LIBRARY}" 20 | "${CMAKE_BINARY_DIR}/bin/$") 21 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 22 | COMMAND ${CMAKE_COMMAND} -E copy_if_different 23 | "${EGL_LIBRARY}" 24 | "${CMAKE_BINARY_DIR}/bin/$") 25 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 26 | COMMAND ${CMAKE_COMMAND} -E copy_directory 27 | "${PROJECT_SOURCE_DIR}/kernels" 28 | "${CMAKE_BINARY_DIR}/bin/$/kernels") 29 | set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$") 30 | endif() 31 | 32 | target_compile_definitions(${PROJECT_NAME} PUBLIC _CRT_SECURE_NO_WARNINGS) 33 | 34 | set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$") 35 | set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$") 36 | 37 | target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_INCLUDE_DIR} "${CMAKE_SOURCE_DIR}/include" ${ANGLE_INCLUDE_DIR}) 38 | if(WIN32) 39 | target_link_libraries(${PROJECT_NAME} webrays ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY} "${GLES_ARCHIVE}" "${EGL_ARCHIVE}") 40 | elseif(APPLE) 41 | set(MACOSX_RPATH ON) 42 | set(CMAKE_MACOSX_RPATH ON) 43 | set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH @executable_path/../lib) 44 | set(CMAKE_INSTALL_RPATH "@executable_path/../lib") 45 | target_link_libraries(${PROJECT_NAME} webrays "${SDL2_LIBRARY}" "${GLES_LIBRARY}" "${EGL_LIBRARY}") 46 | target_link_libraries(${PROJECT_NAME} "-framework Foundation") 47 | else() 48 | set(CMAKE_INSTALL_RPATH "\$ORIGIN") 49 | target_link_libraries(${PROJECT_NAME} webrays "${SDL2_LIBRARY}" "${GLES_LIBRARY}" "${EGL_LIBRARY}") 50 | endif() 51 | 52 | install(TARGETS ${PROJECT_NAME} 53 | RUNTIME DESTINATION webrays/bin) 54 | 55 | if(WIN32) 56 | install(FILES ${SDL2_LIBPATH} DESTINATION webrays/bin) 57 | elseif(APPLE) 58 | install(FILES "${GLES_LIBRARY}" "${EGL_LIBRARY}" DESTINATION webrays/lib) 59 | install(DIRECTORY "${SDL2_LIBRARY}" DESTINATION webrays/lib) 60 | else() 61 | set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH $ORIGIN/../lib) 62 | install(FILES "${GLES_LIBRARY}" "${EGL_LIBRARY}" DESTINATION webrays/lib) 63 | endif() 64 | 65 | install(DIRECTORY kernels DESTINATION webrays/bin) 66 | 67 | # There has to be a better solution 68 | if(APPLE) 69 | install(CODE "execute_process(COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change ./libEGL.dylib @rpath/libEGL.dylib ${CMAKE_INSTALL_PREFIX}/webrays/bin/hello_triangle)") 70 | install(CODE "execute_process(COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change ./libGLESv2.dylib @rpath/libGLESv2.dylib ${CMAKE_INSTALL_PREFIX}/webrays/bin/hello_triangle)") 71 | endif() -------------------------------------------------------------------------------- /examples/web/kernels/bxdf.inc.glsl: -------------------------------------------------------------------------------- 1 | #define BxDF_DIFFUS 0x00000001u 2 | #define Masked 0x00000002u 3 | #define Translucent 0x00000004u 4 | 5 | #define BxDF_DIFFUSE_REFLECTION 1 6 | #define BxDF_SPECULAR_REFLECTION 2 7 | 8 | struct event 9 | { 10 | onb basis; 11 | vec3 reflectance; 12 | vec3 base_color; 13 | vec3 shading_normal; 14 | vec3 position; 15 | int type; 16 | float alpha; 17 | }; 18 | 19 | float ggx_isotropic_ndf(const in event evt, const vec3 h); 20 | vec3 ggx_isotropic_ndf_sample(const in event evt, const vec3 wo, const vec2 u); 21 | float ggx_isotropic_ndf_pdf(const in event evt, const vec3 wo, const vec3 h); 22 | 23 | vec3 fresnel_schlick(const in event evt, const float costheta); 24 | 25 | float ggx_isotropic_lambda( const in event evt, const vec3 dir); 26 | float ggx_isotropic_geometric(const in event evt, const vec3 wi, const vec3 wo); 27 | 28 | float BxDF_pdfD(const in event evt, const in vec3 wo, const in vec3 wi); 29 | float BxDF_pdfG(const in event evt, const in vec3 wo, const in vec3 wi); 30 | vec3 BxDF_evalD(const in event evt, const in vec3 wo, const in vec3 wi); 31 | vec3 BxDF_evalG(const in event evt, const in vec3 wo, const in vec3 wi); 32 | 33 | // BSDF Functions 34 | float BxDF_pdf(const in event evt, const in vec3 wo, const in vec3 wi); 35 | vec3 BxDF_eval(const in event evt, const in vec3 wo, const in vec3 wi); 36 | vec3 BxDF_sample(const in event evt, const in vec3 wo, const in vec2 u, out vec3 wi, out float pdf); 37 | 38 | float BxDF_diffuse_reflection_pdf(const in event evt, const in vec3 wo, const in vec3 wi); 39 | vec3 BxDF_diffuse_reflection_eval(const in event evt, const in vec3 wo, const in vec3 wi); 40 | vec3 BxDF_diffuse_reflection_sample(const in event evt, const in vec3 wo, const in vec2 u, out vec3 wi, out float pdf); 41 | 42 | vec3 BxDF_sample(const in event evt, const in vec3 woWorld, const in vec2 u, out vec3 wiWorld, out float pdf) 43 | { 44 | vec3 BxDF = vec3(0); 45 | vec3 wo = onb_to(evt.basis, woWorld); 46 | vec3 wi; 47 | if (BxDF_DIFFUSE_REFLECTION == evt.type) 48 | BxDF = BxDF_diffuse_reflection_sample(evt, wo, u, wi, pdf); 49 | else { 50 | wi = vec3(0); 51 | BxDF = vec3(0,0,0); 52 | } 53 | 54 | wiWorld = onb_from(evt.basis, wi); 55 | 56 | return BxDF; 57 | } 58 | 59 | vec3 BxDF_eval(const in event evt, const in vec3 woWorld, const in vec3 wiWorld) 60 | { 61 | vec3 wo = onb_to(evt.basis, woWorld); 62 | vec3 wi = onb_to(evt.basis, wiWorld); 63 | if (BxDF_DIFFUSE_REFLECTION == evt.type) 64 | return BxDF_diffuse_reflection_eval(evt, wo, wi); 65 | else 66 | return vec3(0,0,0); 67 | } 68 | 69 | float BxDF_pdf(const in event evt, const in vec3 woWorld, const in vec3 wiWorld) 70 | { 71 | vec3 wo = onb_to(evt.basis, woWorld); 72 | vec3 wi = onb_to(evt.basis, wiWorld); 73 | if (BxDF_DIFFUSE_REFLECTION == evt.type) 74 | return BxDF_diffuse_reflection_pdf(evt, wo, wi); 75 | else 76 | return 0.0; 77 | } 78 | 79 | vec3 BxDF_diffuse_reflection_sample(const in event evt, const in vec3 wo, const in vec2 u, out vec3 wi, out float pdf) { 80 | if ( is_zerof( dot( wo, evt.shading_normal ) ) ) 81 | return vec3(0.0); 82 | 83 | vec3 wi_lcs = hemisphere_cosine_sample(u); 84 | pdf = BxDF_diffuse_reflection_pdf(evt, wo, wi_lcs); 85 | wi = wi_lcs; 86 | 87 | return BxDF_diffuse_reflection_eval(evt, wo, wi_lcs); 88 | } 89 | 90 | vec3 BxDF_diffuse_reflection_eval(const in event evt, const in vec3 wo, const in vec3 wi) 91 | { 92 | return evt.base_color * WR_INV_PI; 93 | } 94 | 95 | float BxDF_diffuse_reflection_pdf(const in event evt, const in vec3 wo, const in vec3 wi) 96 | { 97 | return SameHemisphere(wo, wi) ? hemisphere_cosine_pdf(AbsCosTheta(wi)) : 0.0; 98 | } -------------------------------------------------------------------------------- /src/webrays_shader_engine.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "webrays/webrays.h" 17 | 18 | #include 19 | 20 | wr_string_buffer 21 | wr_string_buffer_create(wr_size reserve) 22 | { 23 | std::string* sb = new std::string; 24 | 25 | sb->reserve(reserve); 26 | 27 | return static_cast(sb); 28 | } 29 | 30 | wr_error 31 | wr_string_buffer_destroy(wr_string_buffer* string_buffer) 32 | { 33 | std::string* sb = static_cast(*string_buffer); 34 | delete sb; 35 | *string_buffer = nullptr; 36 | 37 | return nullptr; 38 | } 39 | 40 | wr_error 41 | wr_string_buffer_append_range(wr_string_buffer string_buffer, const char* begin, 42 | const char* end) 43 | { 44 | std::string* sb = static_cast(string_buffer); 45 | 46 | sb->append(begin, end); 47 | 48 | return nullptr; 49 | } 50 | 51 | wr_error 52 | wr_string_buffer_append(wr_string_buffer string_buffer, const char* data) 53 | { 54 | std::string* sb = static_cast(string_buffer); 55 | 56 | (*sb) += data; 57 | 58 | return nullptr; 59 | } 60 | 61 | wr_error 62 | wr_string_buffer_prepend(wr_string_buffer string_buffer, const char* data) 63 | { 64 | std::string* sb = static_cast(string_buffer); 65 | 66 | sb->insert(0, std::string(data)); 67 | 68 | return nullptr; 69 | } 70 | 71 | wr_error 72 | wr_string_buffer_clear(wr_string_buffer string_buffer) 73 | { 74 | std::string* sb = static_cast(string_buffer); 75 | 76 | sb->clear(); 77 | 78 | return nullptr; 79 | } 80 | 81 | wr_error 82 | wr_string_buffer_appendln(wr_string_buffer string_buffer, const char* data) 83 | { 84 | std::string* sb = static_cast(string_buffer); 85 | 86 | (*sb) += data; 87 | (*sb) += "\n"; 88 | 89 | return nullptr; 90 | } 91 | 92 | wr_error 93 | wr_string_buffer_appendsp(wr_string_buffer string_buffer, const char* data) 94 | { 95 | std::string* sb = static_cast(string_buffer); 96 | 97 | (*sb) += data; 98 | (*sb) += " "; 99 | 100 | return nullptr; 101 | } 102 | 103 | const char* 104 | wr_string_buffer_data(wr_string_buffer string_buffer) 105 | { 106 | return (static_cast(string_buffer))->data(); 107 | } 108 | 109 | void 110 | wr_string_buffer_pretty_print(wr_string_buffer string_buffer) 111 | { 112 | std::string* sb = static_cast(string_buffer); 113 | int line_count = 1; 114 | printf("%04d", line_count++); 115 | for (const char c : *sb) { 116 | if ('\n' == c) 117 | printf("%c%04d. ", c, line_count++); 118 | else 119 | printf("%c", c); 120 | } 121 | } 122 | 123 | wr_error 124 | wr_string_buffer_pop_back(wr_string_buffer string_buffer) 125 | { 126 | std::string* sb = static_cast(string_buffer); 127 | 128 | sb->pop_back(); 129 | 130 | return nullptr; 131 | } 132 | 133 | char 134 | wr_string_buffer_back(wr_string_buffer string_buffer) 135 | { 136 | std::string* sb = static_cast(string_buffer); 137 | return sb->back(); 138 | } 139 | -------------------------------------------------------------------------------- /doc/API_REFERENCE_GLSL.md: -------------------------------------------------------------------------------- 1 | ## WebRays GLSL API Reference 2 | 3 | Commonly, shaders in WebGL are submitted for compilation in text-form. For convenience, WebRays also returns the entire GLSL API as a regular string which can be safely **pre**pended to the user's code. This string defines the uniforms and intersection routines of the WebRays GLSL API. Together, with the required bindings, it can be used to add intersection functionality to a WebGL application. 4 | 5 | | Function | Description | 6 | |:--|:--| 7 | | `ivec4` wr_QueryIntersection (
    `int` ads,
    `vec3` ray_origin,
    `vec3` ray_direction,
    `float` tmax
) | Return the closest-hit information of the intersection of the `(ray_origin, ray_direction)` ray and `ads` | 8 | | `bool` wr_QueryOcclusion (
    `int` ads,
    `vec3` ray_origin,
    `vec3` ray_direction,
    `float` tmax
) | Return occlusion information of the intersection of the `(ray_origin, ray_direction)` ray and `ads` | 9 | | `ivec4` wr_GetFace (
    `int` ads,
    `ivec4` intersection
) | Get index data of the primitive at the closes hit. The `w` component directly corresponds to the `w` component that was submitted during `AddShape` | 10 | | `vec3` wr_GetPosition (
    `int` ads,
    `ivec4` intersection,
    `int` index
) | Get 3D position at `index` | 11 | | `vec3` wr_GetNormal (
    `int` ads,
    `ivec4` intersection,
    `int` index
) | Get 3D normal at `index` | 12 | | `vec2` wr_GetTexCoords (
    `int` ads,
    `ivec4` intersection,
    `int` index
) | Get 2D texture coordinates at `index` | 13 | | `vec3` wr_GetInterpolatedPosition (
    `int` ads,
    `ivec4` intersection
) | Get 3D position of the closest-hit | 14 | | `vec3` wr_GetInterpolatedNormal (
    `int` ads,
    `ivec4` intersection
) | Get 3D normal at the closest-hit | 15 | | `vec3` wr_GetGeomNormal (
    `int` ads,
    `ivec4` intersection
) | Get 3D geometric normal at the closest-hit | 16 | | `vec2` wr_GetInterpolatedTexCoords (
    `int` ads,
    `ivec4` intersection
) | Get 2D texture coordinates of the closest-hit | 17 | | `float` wr_GetHitDistance (
    `ivec4` intersection
) | Get distance to closest-hit | 18 | | `vec3` wr_GetBaryCoords3D (
    `ivec4` intersection
) | Get 3D barycentric coordinates of closest hit | 19 | | `vec2` wr_GetBaryCoords (
    `ivec4` intersection
) | Get 2D barycentric coordinates of closest hit | 20 | | `bool` wr_IsValidIntersection (
    `ivec4` intersection
) | Is it a **hit** (`true`) or a **miss** (`false`) | 21 | | `int` wr_GetInstanceID (
    `int` ads,
    `ivec4` intersection
) | When `ads` is a TLAS, returns the instance id of the closest hit object | 22 | | `mat4` wr_GetObjectTranform (
    `int` ads,
    `ivec4` intersection
) | When `ads` is a TLAS, returns the object transform matrix of the closest hit object | 23 | | `mat4` wr_GetNormalTranform (
    `int` ads,
    `ivec4` intersection
) | When `ads` is a TLAS, returns the normal transform matrix of the closest hit object | 24 | -------------------------------------------------------------------------------- /deps/include/angle_cl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2021 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // angle_cl.h: Includes all necessary CL headers and definitions for ANGLE. 7 | 8 | #ifndef ANGLECL_H_ 9 | #define ANGLECL_H_ 10 | 11 | #define CL_TARGET_OPENCL_VERSION 300 12 | #define CL_USE_DEPRECATED_OPENCL_1_0_APIS 13 | #define CL_USE_DEPRECATED_OPENCL_1_1_APIS 14 | #define CL_USE_DEPRECATED_OPENCL_1_2_APIS 15 | #define CL_USE_DEPRECATED_OPENCL_2_0_APIS 16 | #define CL_USE_DEPRECATED_OPENCL_2_1_APIS 17 | #define CL_USE_DEPRECATED_OPENCL_2_2_APIS 18 | 19 | #include "CL/cl_icd.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace cl 26 | { 27 | 28 | using ContextErrorCB = void(CL_CALLBACK *)(const char *errinfo, 29 | const void *private_info, 30 | size_t cb, 31 | void *user_data); 32 | 33 | using MemoryCB = void(CL_CALLBACK *)(cl_mem memobj, void *user_data); 34 | using ProgramCB = void(CL_CALLBACK *)(cl_program program, void *user_data); 35 | using EventCB = void(CL_CALLBACK *)(cl_event event, cl_int event_command_status, void *user_data); 36 | using UserFunc = void(CL_CALLBACK *)(void *args); 37 | 38 | template 39 | struct Dispatch 40 | { 41 | explicit Dispatch(std::uint32_t magic) : mDispatch(sDispatch), mMagic(magic) {} 42 | 43 | const cl_icd_dispatch &getDispatch() const { return *mDispatch; } 44 | 45 | static const cl_icd_dispatch *sDispatch; 46 | 47 | protected: 48 | // This has to be the first member to be OpenCL ICD compatible 49 | const cl_icd_dispatch *const mDispatch; 50 | const std::uint32_t mMagic; 51 | }; 52 | 53 | template 54 | const cl_icd_dispatch *Dispatch::sDispatch = nullptr; 55 | 56 | template 57 | struct NativeObject : public Dispatch<> 58 | { 59 | NativeObject() : Dispatch<>(magic) 60 | { 61 | static_assert(std::is_standard_layout::value && 62 | offsetof(NativeObjectType, mDispatch) == 0u, 63 | "Not ICD compatible"); 64 | } 65 | 66 | template 67 | T &cast() 68 | { 69 | return static_cast(*this); 70 | } 71 | 72 | template 73 | const T &cast() const 74 | { 75 | return static_cast(*this); 76 | } 77 | 78 | NativeObjectType *getNative() { return static_cast(this); } 79 | 80 | const NativeObjectType *getNative() const 81 | { 82 | return static_cast(this); 83 | } 84 | 85 | static NativeObjectType *CastNative(NativeObjectType *p) { return p; } 86 | 87 | static bool IsValid(const NativeObjectType *p) 88 | { 89 | return p != nullptr && p->mDispatch == sDispatch && p->mMagic == magic; 90 | } 91 | }; 92 | 93 | } // namespace cl 94 | 95 | struct _cl_platform_id : public cl::NativeObject<_cl_platform_id, 0x12345678u> 96 | {}; 97 | 98 | struct _cl_device_id : public cl::NativeObject<_cl_device_id, 0x23456789u> 99 | {}; 100 | 101 | struct _cl_context : public cl::NativeObject<_cl_context, 0x3456789Au> 102 | {}; 103 | 104 | struct _cl_command_queue : public cl::NativeObject<_cl_command_queue, 0x456789ABu> 105 | {}; 106 | 107 | struct _cl_mem : public cl::NativeObject<_cl_mem, 0x56789ABCu> 108 | {}; 109 | 110 | struct _cl_program : public cl::NativeObject<_cl_program, 0x6789ABCDu> 111 | {}; 112 | 113 | struct _cl_kernel : public cl::NativeObject<_cl_kernel, 0x789ABCDEu> 114 | {}; 115 | 116 | struct _cl_event : public cl::NativeObject<_cl_event, 0x89ABCDEFu> 117 | {}; 118 | 119 | struct _cl_sampler : public cl::NativeObject<_cl_sampler, 0x9ABCDEF0u> 120 | {}; 121 | 122 | #endif // ANGLECL_H_ 123 | -------------------------------------------------------------------------------- /src/webrays_context.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _WRAYS_CONTEXT_H_ 17 | #define _WRAYS_CONTEXT_H_ 18 | 19 | #include "webrays/webrays.h" 20 | 21 | #if defined(_DEBUG) && WR_WIN32 22 | #define _CRTDBG_MAP_ALLOC 23 | #include 24 | #include 25 | #endif 26 | 27 | #define WR_FREE(x) \ 28 | if (WR_NULL != x) { \ 29 | free((x)); \ 30 | (x = WR_NULL); \ 31 | } 32 | #define WR_PTR2INT(p) ((int)(unsigned long long)(p)) 33 | #define WR_INT2PTR(i) ((void*)(unsigned long long)(i)) 34 | 35 | #define WR_TLAS_ID_MASK 0x80000000 36 | #define WR_MAX_TLAS_COUNT 8 37 | #define WR_MAX_BLAS_COUNT 256 38 | 39 | typedef enum 40 | { 41 | WR_BLAS_TYPE_UNKNOWN, 42 | WR_BLAS_TYPE_SAH, 43 | WR_BLAS_TYPE_WIDEBVH, 44 | WR_BLAS_TYPE_MAX 45 | } wr_blas_type; 46 | 47 | typedef struct 48 | { 49 | class ADS* blas_handles[WR_MAX_BLAS_COUNT]; 50 | int blas_count; 51 | wr_blas_type blas_type; 52 | 53 | class TLAS* tlas_handles[WR_MAX_TLAS_COUNT]; 54 | int tlas_count; 55 | 56 | } wr_scene, wr_ads; 57 | 58 | typedef struct 59 | { 60 | wr_scene scene; 61 | wr_handle ads[WR_MAX_BLAS_COUNT]; 62 | 63 | wr_handle webgl; 64 | wr_handle cpu; 65 | wr_backend_type backend_type; 66 | 67 | /* Properties */ 68 | int bvh_count; 69 | 70 | unsigned int sphere_count; 71 | unsigned int triangle_count; 72 | 73 | int needs_update; 74 | wr_update_flags update_flags; 75 | } wr_context; 76 | 77 | #ifdef WRAYS_WIN32 78 | 79 | #define wrays_dlopen(path) LoadLibrary((char*)path) 80 | #define wrays_dlsym(handle, symbol) \ 81 | (void*)GetProcAddress((HMODULE)handle, symbol) 82 | #define wrays_dlclose(handle) (FreeLibrary((HMODULE)handle) ? 0 : -1) 83 | #define WRAYS_GLES_LIBRARY "libGLESv2.dll" 84 | 85 | #elif WRAYS_EMSCRIPTEN 86 | 87 | #define wrays_dlopen(path) WR_NULL 88 | #define wrays_dlsym(handle, symbol) WR_NULL 89 | #define wrays_dlclose(handle) 90 | #define WRAYS_GLES_LIBRARY "" 91 | 92 | #else 93 | 94 | #define wrays_dlopen(path) dlopen((char*)path, RTLD_NOW | RTLD_GLOBAL) 95 | #define wrays_dlsym(handle, symbol) dlsym(handle, symbol) 96 | #define wrays_dlclose(handle) dlclose(handle) 97 | #if WRAYS_LINUX 98 | #define WRAYS_GLES_LIBRARY "libGLESv2.so" 99 | #elif WRAYS_APPLE 100 | #define WRAYS_GLES_LIBRARY "libGLESv2.dylib" 101 | #else 102 | #endif /* WRAYS_LINUX */ 103 | 104 | #endif 105 | 106 | /* Internal API */ 107 | wr_string_buffer 108 | wr_string_buffer_create(wr_size reserve); 109 | wr_error 110 | wr_string_buffer_destroy(wr_string_buffer*); 111 | wr_error 112 | wr_string_buffer_append(wr_string_buffer string_buffer, const char* data); 113 | wr_error 114 | wr_string_buffer_prepend(wr_string_buffer string_buffer, const char* data); 115 | wr_error 116 | wr_string_buffer_append_range(wr_string_buffer string_buffer, const char* begin, 117 | const char* end); 118 | wr_error 119 | wr_string_buffer_appendln(wr_string_buffer string_buffer, const char* data); 120 | wr_error 121 | wr_string_buffer_appendsp(wr_string_buffer string_buffer, const char* data); 122 | wr_error 123 | wr_string_buffer_clear(wr_string_buffer string_buffer); 124 | wr_error 125 | wr_string_buffer_pop_back(wr_string_buffer string_buffer); 126 | char 127 | wr_string_buffer_back(wr_string_buffer string_buffer); 128 | const char* 129 | wr_string_buffer_data(wr_string_buffer string_buffer); 130 | void 131 | wr_string_buffer_pretty_print(wr_string_buffer string_buffer); 132 | 133 | #endif /* _WRAYS_CONTEXT_H_ */ -------------------------------------------------------------------------------- /deps/include/platform/FrontendFeatures.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | 7 | // FrontendFeatures.h: Features/workarounds for driver bugs and other behaviors seen 8 | // on all platforms. 9 | 10 | #ifndef ANGLE_PLATFORM_FRONTENDFEATURES_H_ 11 | #define ANGLE_PLATFORM_FRONTENDFEATURES_H_ 12 | 13 | #include "platform/Feature.h" 14 | 15 | namespace angle 16 | { 17 | 18 | struct FrontendFeatures : angle::FeatureSetBase 19 | { 20 | FrontendFeatures(); 21 | ~FrontendFeatures(); 22 | 23 | // Force the context to be lost (via KHR_robustness) if a GL_OUT_OF_MEMORY error occurs. The 24 | // driver may be in an inconsistent state if this happens, and some users of ANGLE rely on this 25 | // notification to prevent further execution. 26 | angle::Feature loseContextOnOutOfMemory = { 27 | "lose_context_on_out_of_memory", angle::FeatureCategory::FrontendWorkarounds, 28 | "Some users rely on a lost context notification if a GL_OUT_OF_MEMORY " 29 | "error occurs", 30 | &members}; 31 | 32 | // Program binaries don't contain transform feedback varyings on Qualcomm GPUs. 33 | // Work around this by disabling the program cache for programs with transform feedback. 34 | angle::Feature disableProgramCachingForTransformFeedback = { 35 | "disable_program_caching_for_transform_feedback", 36 | angle::FeatureCategory::FrontendWorkarounds, 37 | "On some GPUs, program binaries don't contain transform feedback varyings", &members}; 38 | 39 | // On Windows Intel OpenGL drivers TexImage sometimes seems to interact with the Framebuffer. 40 | // Flaky crashes can occur unless we sync the Framebuffer bindings. The workaround is to add 41 | // Framebuffer binding dirty bits to TexImage updates. See http://anglebug.com/2906 42 | angle::Feature syncFramebufferBindingsOnTexImage = { 43 | "sync_framebuffer_bindings_on_tex_image", angle::FeatureCategory::FrontendWorkarounds, 44 | "On some drivers TexImage sometimes seems to interact " 45 | "with the Framebuffer", 46 | &members}; 47 | 48 | angle::Feature scalarizeVecAndMatConstructorArgs = { 49 | "scalarize_vec_and_mat_constructor_args", angle::FeatureCategory::FrontendWorkarounds, 50 | "Always rewrite vec/mat constructors to be consistent", &members, 51 | "http://crbug.com/1165751"}; 52 | 53 | // Disable support for GL_OES_get_program_binary 54 | angle::Feature disableProgramBinary = { 55 | "disable_program_binary", angle::FeatureCategory::FrontendFeatures, 56 | "Disable support for GL_OES_get_program_binary", &members, "http://anglebug.com/5007"}; 57 | 58 | // Allow disabling of GL_EXT_texture_filter_anisotropic through a runtime feature for 59 | // performance comparisons. 60 | angle::Feature disableAnisotropicFiltering = { 61 | "disable_anisotropic_filtering", angle::FeatureCategory::FrontendWorkarounds, 62 | "Disable support for anisotropic filtering", &members}; 63 | 64 | // We can use this feature to override compressed format support for portability. 65 | angle::Feature allowCompressedFormats = {"allow_compressed_formats", 66 | angle::FeatureCategory::FrontendWorkarounds, 67 | "Allow compressed formats", &members}; 68 | 69 | angle::Feature captureLimits = {"enable_capture_limits", 70 | angle::FeatureCategory::FrontendFeatures, 71 | "Set the context limits like frame capturing was enabled", 72 | &members, "http://anglebug.com/5750"}; 73 | 74 | // Whether we should compress pipeline cache in thread pool before it's stored in blob cache. 75 | // http://anglebug.com/4722 76 | angle::Feature enableCompressingPipelineCacheInThreadPool = { 77 | "enableCompressingPipelineCacheInThreadPool", angle::FeatureCategory::FrontendWorkarounds, 78 | "Enable compressing pipeline cache in thread pool.", &members, "http://anglebug.com/4722"}; 79 | 80 | angle::Feature forceRobustResourceInit = { 81 | "forceRobustResourceInit", angle::FeatureCategory::FrontendWorkarounds, 82 | "Force-enable robust resource init", &members, "http://anglebug.com/6041"}; 83 | }; 84 | 85 | inline FrontendFeatures::FrontendFeatures() = default; 86 | inline FrontendFeatures::~FrontendFeatures() = default; 87 | 88 | } // namespace angle 89 | 90 | #endif // ANGLE_PLATFORM_FRONTENDFEATURES_H_ 91 | -------------------------------------------------------------------------------- /examples/web/js/common/webgl_viewer.js: -------------------------------------------------------------------------------- 1 | import * as webgl_utils from './webgl_utils.js'; 2 | 3 | // 4 | // Initialize the GL context 5 | // 6 | export function context_init(webglviewer, xr) 7 | { 8 | webglviewer.canvas = document.getElementById('webrays-main-canvas'); 9 | webglviewer.canvas.width = webglviewer.canvas.clientWidth; 10 | webglviewer.canvas.height = webglviewer.canvas.clientHeight; 11 | webglviewer.webgl_context_attribs = { 'majorVersion' : 2, 'minorVersion' : 0 }; 12 | 13 | webglviewer.gl = webglviewer.canvas.getContext("webgl2", { 14 | stencil: false, 15 | alpha: false, 16 | antialias: false, 17 | premultipliedAlpha: false, 18 | preserveDrawingBuffer: false, 19 | depth: false, 20 | xrCompatible: xr 21 | }); 22 | 23 | const gl = webglviewer.gl; 24 | 25 | // If we don't have a GL context, give up now 26 | // Only continue if WebGL is available and working 27 | if (!gl) { 28 | throw ("Unable to initialize WebGL 2. Your browser or machine may not support it."); 29 | } 30 | 31 | var gl_ext_color_buffer_float = gl.getExtension('Ext_color_buffer_float'); 32 | if (!gl_ext_color_buffer_float) { 33 | throw ("Unable to initialize WebGL ext: Ext_color_buffer_float. Your browser or machine may not support it."); 34 | } 35 | 36 | var gl_ext_float_blend = gl.getExtension('Ext_float_blend'); 37 | if (!gl_ext_float_blend) { 38 | throw ("Unable to initialize WebGL ext: Ext_float_blend. Your browser or machine may not support it."); 39 | } 40 | 41 | webglviewer.gl_timer_ext = gl.getExtension('EXT_disjoint_timer_query_webgl2'); 42 | if (!webglviewer.gl_timer_ext) { 43 | console.log("Unable to initialize WebGL ext: EXT_disjoint_timer_query_webgl2. Your browser or machine may not support it."); 44 | } 45 | } 46 | 47 | // 48 | // Initialize the VAO we'll need for the sceen quad rendering 49 | // 50 | export function vao_init(webglviewer) 51 | { 52 | const gl = webglviewer.gl; 53 | const screen_fill_triangle = new Float32Array( 54 | [ -1.0, -1.0, 0.0, 55 | 8.0, -1.0, 0.0, 56 | -1.0, 8.0, 0.0] 57 | ); 58 | 59 | const vbo = gl.createBuffer(); 60 | gl.bindBuffer(gl.ARRAY_BUFFER, vbo); 61 | gl.bufferData(gl.ARRAY_BUFFER, screen_fill_triangle, gl.STATIC_DRAW); 62 | gl.bindBuffer(gl.ARRAY_BUFFER, null); 63 | 64 | webglviewer.vao = gl.createVertexArray(); 65 | gl.bindVertexArray(webglviewer.vao); 66 | { 67 | gl.bindBuffer (gl.ARRAY_BUFFER, vbo); 68 | gl.vertexAttribPointer (0, 3, gl.FLOAT, false, 0, 0); 69 | gl.enableVertexAttribArray(0); 70 | gl.bindBuffer(gl.ARRAY_BUFFER, null); 71 | } 72 | gl.bindVertexArray(null); 73 | 74 | webgl_utils.check_error(gl); 75 | } 76 | 77 | // 78 | // Initialize the framebuffers we'll need for the rendering 79 | // 80 | export function fbo_init(webglviewer) 81 | { 82 | const gl = webglviewer.gl; 83 | // Delete previous state 84 | if(webglviewer.framebuffer !== undefined) { 85 | gl.deleteTexture(webglviewer.framebuffer.rt_accum_texture); 86 | gl.deleteFramebuffer(webglviewer.framebuffer.rt_fbo); 87 | } 88 | 89 | webglviewer.framebuffer = { 90 | rt_fbo: gl.createFramebuffer(), 91 | rt_accum_texture: webgl_utils.texture_2d_alloc(gl, gl.RGBA32F, webglviewer.canvas.width, webglviewer.canvas.height), 92 | }; 93 | 94 | gl.bindFramebuffer(gl.FRAMEBUFFER, webglviewer.framebuffer.rt_fbo); 95 | gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, webglviewer.framebuffer.rt_accum_texture, 0); 96 | webgl_utils.check_fbo_error(gl); 97 | 98 | gl.bindFramebuffer(gl.FRAMEBUFFER, null); 99 | } 100 | 101 | // 102 | // Copy framebuffer to the screen 103 | // 104 | export function fbo_blit(webglviewer, read_fbo) 105 | { 106 | const gl = webglviewer.gl; 107 | gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); 108 | gl.bindFramebuffer(gl.READ_FRAMEBUFFER, read_fbo); 109 | gl.readBuffer (gl.COLOR_ATTACHMENT0); 110 | gl.drawBuffers ([gl.BACK]); 111 | 112 | var dst_viewport = [ 0, 0, webglviewer.canvas.width, webglviewer.canvas.height]; 113 | var src_viewport = [ 0, 0, webglviewer.canvas.width, webglviewer.canvas.height]; 114 | 115 | gl.blitFramebuffer( 116 | src_viewport[0], src_viewport[1], src_viewport[2], src_viewport[3], 117 | dst_viewport[0], dst_viewport[1], dst_viewport[2], dst_viewport[3], 118 | gl.COLOR_BUFFER_BIT, gl.NEAREST); 119 | } 120 | 121 | // 122 | // Resize Canvas 123 | // 124 | export function resize(webglviewer) 125 | { 126 | webglviewer.camera.set_size(webglviewer.gl.canvas.clientWidth, webglviewer.gl.canvas.clientHeight); 127 | 128 | fbo_init(webglviewer); 129 | } -------------------------------------------------------------------------------- /deps/cmake/modules/FindANGLE.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # Find ANGLE 3 | # ---------------- 4 | # 5 | # Finds the OpenGL ES 3 library. This module defines: 6 | # 7 | # OpenGLES3_FOUND - True if OpenGL ES 3 library is found 8 | # OpenGLES3::OpenGLES3 - OpenGL ES 3 imported target 9 | # 10 | # Additionally these variables are defined for internal usage: 11 | # 12 | # ANGLE_LIBRARY - OpenGL ES 3 library 13 | # 14 | # Please note this find module is tailored especially for the needs of Magnum. 15 | # In particular, it depends on its platform definitions and doesn't look for 16 | # OpenGL ES includes as Magnum has its own, generated using flextGL. 17 | # 18 | 19 | # 20 | # This file is part of Magnum. 21 | # 22 | # Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 23 | # 2020, 2021 Vladimír Vondruš 24 | # 25 | # Permission is hereby granted, free of charge, to any person obtaining a 26 | # copy of this software and associated documentation files (the "Software"), 27 | # to deal in the Software without restriction, including without limitation 28 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 29 | # and/or sell copies of the Software, and to permit persons to whom the 30 | # Software is furnished to do so, subject to the following conditions: 31 | # 32 | # The above copyright notice and this permission notice shall be included 33 | # in all copies or substantial portions of the Software. 34 | # 35 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 40 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 41 | # DEALINGS IN THE SOFTWARE. 42 | # 43 | 44 | # Under Emscripten, GL is linked implicitly. With MINIMAL_RUNTIME you need to 45 | # specify -lGL. Simply set the library name to that. 46 | 47 | macro(SUBDIRLIST result curdir) 48 | file(GLOB children RELATIVE ${curdir} ${curdir}/*) 49 | set(dirlist "") 50 | foreach(child ${children}) 51 | if(IS_DIRECTORY ${curdir}/${child}) 52 | list(APPEND dirlist ${child}) 53 | endif() 54 | endforeach() 55 | set(${result} ${dirlist}) 56 | endmacro() 57 | 58 | set(PROGRAM_FILES_X86 "C:/Program Files (x86)") 59 | set(PROGRAM_FILES "C:/Program Files") 60 | set(FIREFOX_DIRECTORY "${PROGRAM_FILES}/Mozilla Firefox") 61 | set(CHROME_DIRECTORY "${PROGRAM_FILES_X86}/Google/Chrome/Application") 62 | set(EDGE_DIRECTORY "${PROGRAM_FILES_X86}/Microsoft/Edge/Application") 63 | 64 | # First try Chrome, then Edge, then Firefox 65 | SUBDIRLIST(CHROME_SUBDIRECTORIES ${CHROME_DIRECTORY}) 66 | foreach(subdir ${CHROME_SUBDIRECTORIES}) 67 | if ( ${subdir} MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)$" ) 68 | set(CHROME_DIRECTORY "${CHROME_DIRECTORY}/${subdir}") 69 | 70 | find_file(EGL_LIBRARY libEGL.dll HINTS ${CHROME_DIRECTORY} PATHS ${CHROME_DIRECTORY} NO_CMAKE_FIND_ROOT_PATH) 71 | find_file(GLES_LIBRARY libGLESv2.dll HINTS ${CHROME_DIRECTORY} PATHS ${CHROME_DIRECTORY} NO_CMAKE_FIND_ROOT_PATH) 72 | endif() 73 | endforeach() 74 | 75 | SUBDIRLIST(EDGE_SUBDIRECTORIES ${EDGE_DIRECTORY}) 76 | foreach(subdir ${EDGE_SUBDIRECTORIES}) 77 | if ( ${subdir} MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)$" ) 78 | set(EDGE_DIRECTORY "${EDGE_DIRECTORY}/${subdir}") 79 | 80 | find_file(EGL_LIBRARY libEGL.dll HINTS ${EDGE_DIRECTORY} PATHS ${EDGE_DIRECTORY} NO_CMAKE_FIND_ROOT_PATH) 81 | find_file(GLES_LIBRARY libGLESv2.dll HINTS ${EDGE_DIRECTORY} PATHS ${EDGE_DIRECTORY} NO_CMAKE_FIND_ROOT_PATH) 82 | endif() 83 | endforeach() 84 | 85 | find_file(EGL_LIBRARY libEGL.dll HINTS ${FIREFOX_DIRECTORY} PATHS ${FIREFOX_DIRECTORY} NO_CMAKE_FIND_ROOT_PATH) 86 | find_file(GLES_LIBRARY libGLESv2.dll HINTS ${FIREFOX_DIRECTORY} PATHS ${FIREFOX_DIRECTORY} NO_CMAKE_FIND_ROOT_PATH) 87 | 88 | # Include dir 89 | find_path(EGL_INCLUDE_DIR NAMES 90 | EGL/egl.h HINTS "${CMAKE_SOURCE_DIR}/deps/include" PATHS "${CMAKE_SOURCE_DIR}/deps/include") 91 | # Include dir 92 | find_path(ANGLE_INCLUDE_DIR NAMES 93 | GLES2/gl2ext_angle.h HINTS "${CMAKE_SOURCE_DIR}/deps/include" PATHS "${CMAKE_SOURCE_DIR}/deps/include") 94 | 95 | if(EXISTS "${GLES_LIBRARY}") 96 | set(ANGLE_LIBRARY "${GLES_LIBRARY}") 97 | endif() 98 | 99 | include(FindPackageHandleStandardArgs) 100 | find_package_handle_standard_args("ANGLE" DEFAULT_MSG 101 | ANGLE_LIBRARY ANGLE_INCLUDE_DIR EGL_INCLUDE_DIR) 102 | 103 | #mark_as_advanced(ANGLE_LIBRARY) 104 | -------------------------------------------------------------------------------- /deps/include/CL/cl_d3d11.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __OPENCL_CL_D3D11_H 18 | #define __OPENCL_CL_D3D11_H 19 | 20 | #if defined(_MSC_VER) 21 | #if _MSC_VER >=1500 22 | #pragma warning( push ) 23 | #pragma warning( disable : 4201 ) 24 | #endif 25 | #endif 26 | #include 27 | #if defined(_MSC_VER) 28 | #if _MSC_VER >=1500 29 | #pragma warning( pop ) 30 | #endif 31 | #endif 32 | #include 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /****************************************************************************** 40 | * cl_khr_d3d11_sharing */ 41 | #define cl_khr_d3d11_sharing 1 42 | 43 | typedef cl_uint cl_d3d11_device_source_khr; 44 | typedef cl_uint cl_d3d11_device_set_khr; 45 | 46 | /******************************************************************************/ 47 | 48 | /* Error Codes */ 49 | #define CL_INVALID_D3D11_DEVICE_KHR -1006 50 | #define CL_INVALID_D3D11_RESOURCE_KHR -1007 51 | #define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 52 | #define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 53 | 54 | /* cl_d3d11_device_source */ 55 | #define CL_D3D11_DEVICE_KHR 0x4019 56 | #define CL_D3D11_DXGI_ADAPTER_KHR 0x401A 57 | 58 | /* cl_d3d11_device_set */ 59 | #define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B 60 | #define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C 61 | 62 | /* cl_context_info */ 63 | #define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D 64 | #define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D 65 | 66 | /* cl_mem_info */ 67 | #define CL_MEM_D3D11_RESOURCE_KHR 0x401E 68 | 69 | /* cl_image_info */ 70 | #define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F 71 | 72 | /* cl_command_type */ 73 | #define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 74 | #define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 75 | 76 | /******************************************************************************/ 77 | 78 | typedef cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( 79 | cl_platform_id platform, 80 | cl_d3d11_device_source_khr d3d_device_source, 81 | void * d3d_object, 82 | cl_d3d11_device_set_khr d3d_device_set, 83 | cl_uint num_entries, 84 | cl_device_id * devices, 85 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; 86 | 87 | typedef cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( 88 | cl_context context, 89 | cl_mem_flags flags, 90 | ID3D11Buffer * resource, 91 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 92 | 93 | typedef cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( 94 | cl_context context, 95 | cl_mem_flags flags, 96 | ID3D11Texture2D * resource, 97 | UINT subresource, 98 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 99 | 100 | typedef cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( 101 | cl_context context, 102 | cl_mem_flags flags, 103 | ID3D11Texture3D * resource, 104 | UINT subresource, 105 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 106 | 107 | typedef cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( 108 | cl_command_queue command_queue, 109 | cl_uint num_objects, 110 | const cl_mem * mem_objects, 111 | cl_uint num_events_in_wait_list, 112 | const cl_event * event_wait_list, 113 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 114 | 115 | typedef cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( 116 | cl_command_queue command_queue, 117 | cl_uint num_objects, 118 | const cl_mem * mem_objects, 119 | cl_uint num_events_in_wait_list, 120 | const cl_event * event_wait_list, 121 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __OPENCL_CL_D3D11_H */ 128 | 129 | -------------------------------------------------------------------------------- /deps/include/CL/cl_d3d10.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __OPENCL_CL_D3D10_H 18 | #define __OPENCL_CL_D3D10_H 19 | 20 | #if defined(_MSC_VER) 21 | #if _MSC_VER >=1500 22 | #pragma warning( push ) 23 | #pragma warning( disable : 4201 ) 24 | #endif 25 | #endif 26 | #include 27 | #if defined(_MSC_VER) 28 | #if _MSC_VER >=1500 29 | #pragma warning( pop ) 30 | #endif 31 | #endif 32 | #include 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /****************************************************************************** 40 | * cl_khr_d3d10_sharing */ 41 | #define cl_khr_d3d10_sharing 1 42 | 43 | typedef cl_uint cl_d3d10_device_source_khr; 44 | typedef cl_uint cl_d3d10_device_set_khr; 45 | 46 | /******************************************************************************/ 47 | 48 | /* Error Codes */ 49 | #define CL_INVALID_D3D10_DEVICE_KHR -1002 50 | #define CL_INVALID_D3D10_RESOURCE_KHR -1003 51 | #define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 52 | #define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 53 | 54 | /* cl_d3d10_device_source_nv */ 55 | #define CL_D3D10_DEVICE_KHR 0x4010 56 | #define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 57 | 58 | /* cl_d3d10_device_set_nv */ 59 | #define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 60 | #define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 61 | 62 | /* cl_context_info */ 63 | #define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 64 | #define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C 65 | 66 | /* cl_mem_info */ 67 | #define CL_MEM_D3D10_RESOURCE_KHR 0x4015 68 | 69 | /* cl_image_info */ 70 | #define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 71 | 72 | /* cl_command_type */ 73 | #define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 74 | #define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 75 | 76 | /******************************************************************************/ 77 | 78 | typedef cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( 79 | cl_platform_id platform, 80 | cl_d3d10_device_source_khr d3d_device_source, 81 | void * d3d_object, 82 | cl_d3d10_device_set_khr d3d_device_set, 83 | cl_uint num_entries, 84 | cl_device_id * devices, 85 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; 86 | 87 | typedef cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( 88 | cl_context context, 89 | cl_mem_flags flags, 90 | ID3D10Buffer * resource, 91 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 92 | 93 | typedef cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( 94 | cl_context context, 95 | cl_mem_flags flags, 96 | ID3D10Texture2D * resource, 97 | UINT subresource, 98 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 99 | 100 | typedef cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( 101 | cl_context context, 102 | cl_mem_flags flags, 103 | ID3D10Texture3D * resource, 104 | UINT subresource, 105 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 106 | 107 | typedef cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( 108 | cl_command_queue command_queue, 109 | cl_uint num_objects, 110 | const cl_mem * mem_objects, 111 | cl_uint num_events_in_wait_list, 112 | const cl_event * event_wait_list, 113 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 114 | 115 | typedef cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( 116 | cl_command_queue command_queue, 117 | cl_uint num_objects, 118 | const cl_mem * mem_objects, 119 | cl_uint num_events_in_wait_list, 120 | const cl_event * event_wait_list, 121 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __OPENCL_CL_D3D10_H */ 128 | 129 | -------------------------------------------------------------------------------- /deps/include/CL/cl_egl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __OPENCL_CL_EGL_H 18 | #define __OPENCL_CL_EGL_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | 27 | /* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ 28 | #define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F 29 | #define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D 30 | #define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E 31 | 32 | /* Error type for clCreateFromEGLImageKHR */ 33 | #define CL_INVALID_EGL_OBJECT_KHR -1093 34 | #define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 35 | 36 | /* CLeglImageKHR is an opaque handle to an EGLImage */ 37 | typedef void* CLeglImageKHR; 38 | 39 | /* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ 40 | typedef void* CLeglDisplayKHR; 41 | 42 | /* CLeglSyncKHR is an opaque handle to an EGLSync object */ 43 | typedef void* CLeglSyncKHR; 44 | 45 | /* properties passed to clCreateFromEGLImageKHR */ 46 | typedef intptr_t cl_egl_image_properties_khr; 47 | 48 | 49 | #define cl_khr_egl_image 1 50 | 51 | extern CL_API_ENTRY cl_mem CL_API_CALL 52 | clCreateFromEGLImageKHR(cl_context context, 53 | CLeglDisplayKHR egldisplay, 54 | CLeglImageKHR eglimage, 55 | cl_mem_flags flags, 56 | const cl_egl_image_properties_khr * properties, 57 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 58 | 59 | typedef cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( 60 | cl_context context, 61 | CLeglDisplayKHR egldisplay, 62 | CLeglImageKHR eglimage, 63 | cl_mem_flags flags, 64 | const cl_egl_image_properties_khr * properties, 65 | cl_int * errcode_ret); 66 | 67 | 68 | extern CL_API_ENTRY cl_int CL_API_CALL 69 | clEnqueueAcquireEGLObjectsKHR(cl_command_queue command_queue, 70 | cl_uint num_objects, 71 | const cl_mem * mem_objects, 72 | cl_uint num_events_in_wait_list, 73 | const cl_event * event_wait_list, 74 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 75 | 76 | typedef cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( 77 | cl_command_queue command_queue, 78 | cl_uint num_objects, 79 | const cl_mem * mem_objects, 80 | cl_uint num_events_in_wait_list, 81 | const cl_event * event_wait_list, 82 | cl_event * event); 83 | 84 | 85 | extern CL_API_ENTRY cl_int CL_API_CALL 86 | clEnqueueReleaseEGLObjectsKHR(cl_command_queue command_queue, 87 | cl_uint num_objects, 88 | const cl_mem * mem_objects, 89 | cl_uint num_events_in_wait_list, 90 | const cl_event * event_wait_list, 91 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 92 | 93 | typedef cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( 94 | cl_command_queue command_queue, 95 | cl_uint num_objects, 96 | const cl_mem * mem_objects, 97 | cl_uint num_events_in_wait_list, 98 | const cl_event * event_wait_list, 99 | cl_event * event); 100 | 101 | 102 | #define cl_khr_egl_event 1 103 | 104 | extern CL_API_ENTRY cl_event CL_API_CALL 105 | clCreateEventFromEGLSyncKHR(cl_context context, 106 | CLeglSyncKHR sync, 107 | CLeglDisplayKHR display, 108 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 109 | 110 | typedef cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( 111 | cl_context context, 112 | CLeglSyncKHR sync, 113 | CLeglDisplayKHR display, 114 | cl_int * errcode_ret); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif /* __OPENCL_CL_EGL_H */ 121 | -------------------------------------------------------------------------------- /src/webrays_cpu.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "webrays_context.h" 17 | #include "webrays_cpu.h" 18 | #include "webrays_queue.h" 19 | #include "webrays_math.h" 20 | #include "webrays_ads.h" 21 | 22 | #include // memset 23 | 24 | typedef struct 25 | { 26 | wr_binding intersection_bindings[3]; 27 | int binding_count; 28 | } wr_cpu_context; 29 | 30 | wr_error 31 | wrays_cpu_init(wr_handle handle) 32 | { 33 | wr_context* webrays = (wr_context*)handle; 34 | if (WR_NULL == webrays) 35 | return (wr_error) "Invalid WebRays context"; 36 | wr_cpu_context* webrays_cpu = (wr_cpu_context*)malloc(sizeof(*webrays_cpu)); 37 | if (WR_NULL == webrays_cpu) 38 | return (wr_error) "Failed to allocate CPU WebRays context"; 39 | 40 | memset(webrays_cpu, 0, sizeof(*webrays_cpu)); 41 | 42 | webrays->cpu = webrays_cpu; 43 | 44 | return WR_SUCCESS; 45 | } 46 | 47 | wr_error 48 | wrays_cpu_add_shape(wr_handle handle, wr_handle ads_id, float* positions, 49 | int position_stride, float* normals, int normal_stride, 50 | float* uvs, int uv_stride, int attr_count, int* faces, 51 | int num_triangles, int* shape_id) 52 | { 53 | 54 | wr_context* webrays = (wr_context*)handle; 55 | if (WR_NULL == webrays) 56 | return WR_NULL; 57 | wr_cpu_context* webrays_cpu = (wr_cpu_context*)webrays->cpu; 58 | if (WR_NULL == webrays_cpu) 59 | return WR_NULL; 60 | 61 | ADS* ads = webrays->scene.blas_handles[(int)(size_t)ads_id]; 62 | 63 | *shape_id = 64 | ads->AddTriangularMesh(positions, position_stride, normals, normal_stride, 65 | uvs, uv_stride, attr_count, faces, num_triangles); 66 | 67 | return WR_SUCCESS; 68 | } 69 | 70 | wr_error 71 | wrays_cpu_ads_create(wr_handle handle, wr_handle ads, 72 | wr_ads_descriptor* descriptor) 73 | { 74 | 75 | return WR_SUCCESS; 76 | } 77 | 78 | const char* 79 | wrays_cpu_get_scene_accessor(wr_handle handle) 80 | { 81 | 82 | return WR_NULL; 83 | } 84 | 85 | const wr_binding* 86 | wrays_cpu_get_scene_accessor_bindings(wr_handle handle, wr_size* count) 87 | { 88 | wr_context* webrays = (wr_context*)handle; 89 | if (WR_NULL == webrays) 90 | return WR_NULL; 91 | wr_cpu_context* webrays_cpu = (wr_cpu_context*)webrays->cpu; 92 | if (WR_NULL == webrays_cpu) 93 | return WR_NULL; 94 | 95 | *count = webrays_cpu->binding_count; 96 | 97 | return &webrays_cpu->intersection_bindings[0]; 98 | } 99 | 100 | WR_INTERNAL wr_error 101 | wrays_cpu_ads_build(wr_handle handle) 102 | { 103 | wr_context* webrays = (wr_context*)handle; 104 | if (WR_NULL == webrays) 105 | return (wr_error) "Invalid WebRays context"; 106 | wr_cpu_context* webrays_cpu = (wr_cpu_context*)webrays->cpu; 107 | if (WR_NULL == webrays_cpu) 108 | return (wr_error) "Invalid CPU WebRays context"; 109 | 110 | ADS* ads = (ADS*)webrays->scene.blas_handles[0]; 111 | 112 | ads->Build(); 113 | 114 | return WR_SUCCESS; 115 | } 116 | 117 | wr_error 118 | wrays_cpu_update(wr_handle handle) 119 | { 120 | wr_context* webrays = (wr_context*)handle; 121 | if (WR_NULL == webrays) 122 | return (wr_error) "Invalid WebRays context"; 123 | wr_cpu_context* webrays_cpu = (wr_cpu_context*)webrays->cpu; 124 | if (WR_NULL == webrays_cpu) 125 | return (wr_error) "Invalid CPU WebRays context"; 126 | 127 | wrays_cpu_ads_build(handle); 128 | 129 | SAHBVH* ads = (SAHBVH*)webrays->scene.blas_handles[0]; 130 | 131 | webrays_cpu->intersection_bindings[0] = { "wr_scene_vertices", 132 | WR_BINDING_TYPE_CPU_BUFFER, 0 }; 133 | webrays_cpu->intersection_bindings[1] = { "wr_scene_indices", 134 | WR_BINDING_TYPE_CPU_BUFFER, 0 }; 135 | webrays_cpu->intersection_bindings[2] = { "wr_bvh_nodes", 136 | WR_BINDING_TYPE_CPU_BUFFER, 0 }; 137 | webrays_cpu->intersection_bindings[0].data.cpu_buffer.buffer = 138 | ads->m_vertex_data.data(); 139 | webrays_cpu->intersection_bindings[0].data.cpu_buffer.size = 140 | (unsigned int)ads->m_vertex_data.size(); 141 | webrays_cpu->intersection_bindings[1].data.cpu_buffer.buffer = 142 | ads->m_triangles.data(); 143 | webrays_cpu->intersection_bindings[1].data.cpu_buffer.size = 144 | (unsigned int)ads->m_triangles.size(); 145 | webrays_cpu->intersection_bindings[2].data.cpu_buffer.buffer = 146 | ads->m_linear_nodes; 147 | webrays_cpu->intersection_bindings[2].data.cpu_buffer.size = 148 | (unsigned int)ads->m_total_nodes; 149 | webrays_cpu->binding_count = 150 | (int)(sizeof(webrays_cpu->intersection_bindings) / 151 | sizeof(webrays_cpu->intersection_bindings[0])); 152 | 153 | return WR_SUCCESS; 154 | } -------------------------------------------------------------------------------- /src/webrays_gl_shaders.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _WRAYS_GL_SHADERS_H_ 17 | #define _WRAYS_GL_SHADERS_H_ 18 | 19 | static char const* const wr_brute_force_scene_accessor_uniform_blocks[] = { 20 | "wr_Vertices", 21 | "wr_Normals", 22 | "wr_Faces", 23 | }; 24 | 25 | static char const* const wr_brute_force_scene_accessor_string = 26 | R"glsl( 27 | layout (std140) uniform wr_VerticesUBO 28 | { 29 | vec4 wr_Vertices[wr_AttributeCount]; 30 | }; 31 | 32 | layout (std140) uniform wr_NormalsUBO 33 | { 34 | vec4 wr_Normals[wr_AttributeCount]; 35 | }; 36 | 37 | layout (std140) uniform wr_FacesUBO 38 | { 39 | ivec4 wr_Faces[wr_FaceCount]; 40 | }; 41 | 42 | vec3 rg_fast_intersect_triangle(vec3 direction, vec3 origin, vec3 v1, vec3 v2, vec3 v3, float t_max) 43 | { 44 | vec3 e1 = v2 - v1; 45 | vec3 e2 = v3 - v1; 46 | vec3 s1 = cross(direction, e2); 47 | 48 | #define USE_SAFE_MATH 49 | #ifdef USE_SAFE_MATH 50 | float invd = 1.0 / dot(s1, e1); 51 | #else 52 | float invd = native_recip(dot(s1, e1)); 53 | #endif 54 | 55 | vec3 d = origin - v1; 56 | float b1 = dot(d, s1) * invd; 57 | vec3 s2 = cross(d, e1); 58 | float b2 = dot(direction, s2) * invd; 59 | float temp = dot(e2, s2) * invd; 60 | //return vec3(b1, b2, temp); 61 | if (b1 < 0.0 || b1 > 1.0 || b2 < 0.0 || b1 + b2 > 1.0 || temp < 0.0 || temp > t_max) 62 | { 63 | return vec3(0, 0, t_max); 64 | } 65 | else 66 | { 67 | return vec3(b1, b2, temp); 68 | } 69 | } 70 | 71 | ivec4 wr_query_intersection(vec3 origin, vec3 direction, float t_max) { 72 | ivec4 intersection = ivec4(-1, 0, 0, 0); 73 | float min_distance = t_max; 74 | for (int face_index = 0; face_index < wr_FaceCount; ++face_index) { 75 | ivec4 face = wr_Faces[face_index]; 76 | vec3 res = rg_fast_intersect_triangle(direction, origin, wr_Vertices[face.x].xyz, wr_Vertices[face.y].xyz, wr_Vertices[face.z].xyz, min_distance); 77 | if (res.z < min_distance) { 78 | min_distance = res.z; 79 | intersection = ivec4(face_index, floatBitsToInt(res.xy), floatBitsToInt(res.z)); 80 | } 81 | } 82 | 83 | return intersection; 84 | } 85 | 86 | bool wr_query_occlusion(vec3 direction, vec3 origin, float t_max) { 87 | float min_distance = t_max; 88 | for (int face_index = 0; face_index < wr_FaceCount; ++face_index) { 89 | ivec4 face = wr_Faces[face_index]; 90 | vec3 res = rg_fast_intersect_triangle(direction, origin, wr_Vertices[face.x].xyz, wr_Vertices[face.y].xyz, wr_Vertices[face.z].xyz, min_distance); 91 | if (res.z < min_distance) { 92 | return true; 93 | } 94 | } 95 | 96 | return false; 97 | } 98 | 99 | vec2 100 | wr_GetBaryCoords(ivec4 intersection) { 101 | return intBitsToFloat(intersection.yz); 102 | } 103 | 104 | ivec4 105 | wr_GetFace(ivec4 intersection) { 106 | return wr_Faces[intersection.x]; 107 | } 108 | 109 | vec3 110 | wr_GetNormal(ivec4 intersection) { 111 | ivec4 face = wr_Faces[intersection.x]; 112 | return wr_Normals[face.x].xyz; 113 | } 114 | 115 | float 116 | wr_GetHitDistance(ivec4 intersection) { 117 | return intBitsToFloat(intersection.w); 118 | } 119 | 120 | )glsl"; 121 | 122 | static char const* const wr_intersection_fragment_shader = 123 | R"glsl( 124 | layout(location = 0) out ivec4 wr_Intersection; 125 | 126 | uniform sampler2D wr_RayOrigins; 127 | uniform sampler2D wr_RayDirections; 128 | 129 | uniform int wr_ADS; 130 | 131 | void main() { 132 | vec4 ray_direction = texelFetch(wr_RayDirections, ivec2(gl_FragCoord.xy), 0); 133 | vec4 ray_origin = texelFetch(wr_RayOrigins, ivec2(gl_FragCoord.xy), 0); 134 | 135 | if (0.0 == ray_direction.w) return; 136 | ray_origin.xyz = ray_origin.xyz + ray_origin.w * ray_direction.xyz; 137 | 138 | wr_Intersection = wr_query_intersection(wr_ADS, ray_origin.xyz, ray_direction.xyz, ray_direction.w); 139 | } 140 | )glsl"; 141 | 142 | static char const* const wr_occlusion_fragment_shader = 143 | R"glsl( 144 | layout(location = 0) out int wr_Occlusion; 145 | 146 | uniform sampler2D wr_RayOrigins; 147 | uniform sampler2D wr_RayDirections; 148 | 149 | uniform int wr_ADS; 150 | 151 | void main() { 152 | vec4 ray_direction = texelFetch(wr_RayDirections, ivec2(gl_FragCoord.xy), 0); 153 | vec4 ray_origin = texelFetch(wr_RayOrigins, ivec2(gl_FragCoord.xy), 0); 154 | 155 | if (0.0 == ray_direction.w) return; 156 | ray_origin.xyz = ray_origin.xyz + ray_origin.w * ray_direction.xyz; 157 | 158 | wr_Occlusion = wr_query_occlusion(wr_ADS, ray_origin.xyz, ray_direction.xyz, ray_direction.w) ? 1 : 0; 159 | } 160 | )glsl"; 161 | 162 | static char const* const wr_screen_fill_vertex_shader = 163 | R"glsl(#version 300 es 164 | precision highp float; 165 | 166 | layout(location = 0) in vec3 wr_VertexPosition; 167 | 168 | const vec3 screen_fill_triangle[3] = vec3[3]( 169 | vec3(-4.0f, -4.0f, 0.0f), 170 | vec3( 4.0f, -4.0f, 0.0f), 171 | vec3( 0.0f, 4.0f, 0.0f) 172 | ); 173 | 174 | void main(){ 175 | gl_Position = vec4(wr_VertexPosition, 1.0f); 176 | 177 | /* In-shader */ 178 | //vec2 uvs = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2); 179 | //gl_Position = vec4(uvs * 2.0f - 1.0f, 0.0f, 1.0f); 180 | //gl_Position = vec4(screen_fill_triangle[gl_VertexID], 1.0); 181 | } 182 | 183 | )glsl"; 184 | 185 | #endif /* _WRAYS_GL_SHADERS_H_ */ 186 | -------------------------------------------------------------------------------- /deps/include/CL/cl_va_api_media_sharing_intel.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H 18 | #define __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /****************************************** 29 | * cl_intel_va_api_media_sharing extension * 30 | *******************************************/ 31 | 32 | #define cl_intel_va_api_media_sharing 1 33 | 34 | /* error codes */ 35 | #define CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL -1098 36 | #define CL_INVALID_VA_API_MEDIA_SURFACE_INTEL -1099 37 | #define CL_VA_API_MEDIA_SURFACE_ALREADY_ACQUIRED_INTEL -1100 38 | #define CL_VA_API_MEDIA_SURFACE_NOT_ACQUIRED_INTEL -1101 39 | 40 | /* cl_va_api_device_source_intel */ 41 | #define CL_VA_API_DISPLAY_INTEL 0x4094 42 | 43 | /* cl_va_api_device_set_intel */ 44 | #define CL_PREFERRED_DEVICES_FOR_VA_API_INTEL 0x4095 45 | #define CL_ALL_DEVICES_FOR_VA_API_INTEL 0x4096 46 | 47 | /* cl_context_info */ 48 | #define CL_CONTEXT_VA_API_DISPLAY_INTEL 0x4097 49 | 50 | /* cl_mem_info */ 51 | #define CL_MEM_VA_API_MEDIA_SURFACE_INTEL 0x4098 52 | 53 | /* cl_image_info */ 54 | #define CL_IMAGE_VA_API_PLANE_INTEL 0x4099 55 | 56 | /* cl_command_type */ 57 | #define CL_COMMAND_ACQUIRE_VA_API_MEDIA_SURFACES_INTEL 0x409A 58 | #define CL_COMMAND_RELEASE_VA_API_MEDIA_SURFACES_INTEL 0x409B 59 | 60 | typedef cl_uint cl_va_api_device_source_intel; 61 | typedef cl_uint cl_va_api_device_set_intel; 62 | 63 | extern CL_API_ENTRY cl_int CL_API_CALL 64 | clGetDeviceIDsFromVA_APIMediaAdapterINTEL( 65 | cl_platform_id platform, 66 | cl_va_api_device_source_intel media_adapter_type, 67 | void* media_adapter, 68 | cl_va_api_device_set_intel media_adapter_set, 69 | cl_uint num_entries, 70 | cl_device_id* devices, 71 | cl_uint* num_devices) CL_API_SUFFIX__VERSION_1_2; 72 | 73 | typedef cl_int (CL_API_CALL * clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn)( 74 | cl_platform_id platform, 75 | cl_va_api_device_source_intel media_adapter_type, 76 | void* media_adapter, 77 | cl_va_api_device_set_intel media_adapter_set, 78 | cl_uint num_entries, 79 | cl_device_id* devices, 80 | cl_uint* num_devices) CL_API_SUFFIX__VERSION_1_2; 81 | 82 | extern CL_API_ENTRY cl_mem CL_API_CALL 83 | clCreateFromVA_APIMediaSurfaceINTEL( 84 | cl_context context, 85 | cl_mem_flags flags, 86 | VASurfaceID* surface, 87 | cl_uint plane, 88 | cl_int* errcode_ret) CL_API_SUFFIX__VERSION_1_2; 89 | 90 | typedef cl_mem (CL_API_CALL * clCreateFromVA_APIMediaSurfaceINTEL_fn)( 91 | cl_context context, 92 | cl_mem_flags flags, 93 | VASurfaceID* surface, 94 | cl_uint plane, 95 | cl_int* errcode_ret) CL_API_SUFFIX__VERSION_1_2; 96 | 97 | extern CL_API_ENTRY cl_int CL_API_CALL 98 | clEnqueueAcquireVA_APIMediaSurfacesINTEL( 99 | cl_command_queue command_queue, 100 | cl_uint num_objects, 101 | const cl_mem* mem_objects, 102 | cl_uint num_events_in_wait_list, 103 | const cl_event* event_wait_list, 104 | cl_event* event) CL_API_SUFFIX__VERSION_1_2; 105 | 106 | typedef cl_int (CL_API_CALL *clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)( 107 | cl_command_queue command_queue, 108 | cl_uint num_objects, 109 | const cl_mem* mem_objects, 110 | cl_uint num_events_in_wait_list, 111 | const cl_event* event_wait_list, 112 | cl_event* event) CL_API_SUFFIX__VERSION_1_2; 113 | 114 | extern CL_API_ENTRY cl_int CL_API_CALL 115 | clEnqueueReleaseVA_APIMediaSurfacesINTEL( 116 | cl_command_queue command_queue, 117 | cl_uint num_objects, 118 | const cl_mem* mem_objects, 119 | cl_uint num_events_in_wait_list, 120 | const cl_event* event_wait_list, 121 | cl_event* event) CL_API_SUFFIX__VERSION_1_2; 122 | 123 | typedef cl_int (CL_API_CALL *clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)( 124 | cl_command_queue command_queue, 125 | cl_uint num_objects, 126 | const cl_mem* mem_objects, 127 | cl_uint num_events_in_wait_list, 128 | const cl_event* event_wait_list, 129 | cl_event* event) CL_API_SUFFIX__VERSION_1_2; 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | 135 | #endif /* __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H */ 136 | 137 | -------------------------------------------------------------------------------- /deps/include/EGL/eglplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __eglplatform_h_ 2 | #define __eglplatform_h_ 3 | 4 | /* 5 | ** Copyright 2007-2020 The Khronos Group Inc. 6 | ** SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /* Platform-specific types and definitions for egl.h 10 | * 11 | * Adopters may modify khrplatform.h and this file to suit their platform. 12 | * You are encouraged to submit all modifications to the Khronos group so that 13 | * they can be included in future versions of this file. Please submit changes 14 | * by filing an issue or pull request on the public Khronos EGL Registry, at 15 | * https://www.github.com/KhronosGroup/EGL-Registry/ 16 | */ 17 | 18 | #include 19 | 20 | /* Macros used in EGL function prototype declarations. 21 | * 22 | * EGL functions should be prototyped as: 23 | * 24 | * EGLAPI return-type EGLAPIENTRY eglFunction(arguments); 25 | * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments); 26 | * 27 | * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h 28 | */ 29 | 30 | #ifndef EGLAPI 31 | #define EGLAPI KHRONOS_APICALL 32 | #endif 33 | 34 | #ifndef EGLAPIENTRY 35 | #define EGLAPIENTRY KHRONOS_APIENTRY 36 | #endif 37 | #define EGLAPIENTRYP EGLAPIENTRY* 38 | 39 | /* The types NativeDisplayType, NativeWindowType, and NativePixmapType 40 | * are aliases of window-system-dependent types, such as X Display * or 41 | * Windows Device Context. They must be defined in platform-specific 42 | * code below. The EGL-prefixed versions of Native*Type are the same 43 | * types, renamed in EGL 1.3 so all types in the API start with "EGL". 44 | * 45 | * Khronos STRONGLY RECOMMENDS that you use the default definitions 46 | * provided below, since these changes affect both binary and source 47 | * portability of applications using EGL running on different EGL 48 | * implementations. 49 | */ 50 | 51 | #if defined(EGL_NO_PLATFORM_SPECIFIC_TYPES) 52 | 53 | typedef void *EGLNativeDisplayType; 54 | typedef void *EGLNativePixmapType; 55 | typedef void *EGLNativeWindowType; 56 | 57 | #elif defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ 58 | #ifndef WIN32_LEAN_AND_MEAN 59 | #define WIN32_LEAN_AND_MEAN 1 60 | #endif 61 | #include 62 | 63 | typedef HDC EGLNativeDisplayType; 64 | typedef HBITMAP EGLNativePixmapType; 65 | 66 | #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) /* Windows Desktop */ 67 | typedef HWND EGLNativeWindowType; 68 | #else /* Windows Store */ 69 | #include 70 | typedef IInspectable* EGLNativeWindowType; 71 | #endif 72 | 73 | #elif defined(__EMSCRIPTEN__) 74 | 75 | typedef int EGLNativeDisplayType; 76 | typedef int EGLNativePixmapType; 77 | typedef int EGLNativeWindowType; 78 | 79 | #elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */ 80 | 81 | typedef int EGLNativeDisplayType; 82 | typedef void *EGLNativePixmapType; 83 | typedef void *EGLNativeWindowType; 84 | 85 | #elif defined(WL_EGL_PLATFORM) 86 | 87 | typedef struct wl_display *EGLNativeDisplayType; 88 | typedef struct wl_egl_pixmap *EGLNativePixmapType; 89 | typedef struct wl_egl_window *EGLNativeWindowType; 90 | 91 | #elif defined(__GBM__) 92 | 93 | typedef struct gbm_device *EGLNativeDisplayType; 94 | typedef struct gbm_bo *EGLNativePixmapType; 95 | typedef void *EGLNativeWindowType; 96 | 97 | #elif defined(__ANDROID__) || defined(ANDROID) 98 | 99 | struct ANativeWindow; 100 | struct egl_native_pixmap_t; 101 | 102 | typedef void* EGLNativeDisplayType; 103 | typedef struct egl_native_pixmap_t* EGLNativePixmapType; 104 | typedef struct ANativeWindow* EGLNativeWindowType; 105 | 106 | #elif defined(USE_OZONE) 107 | 108 | typedef intptr_t EGLNativeDisplayType; 109 | typedef intptr_t EGLNativePixmapType; 110 | typedef intptr_t EGLNativeWindowType; 111 | 112 | #elif defined(__unix__) && defined(EGL_NO_X11) 113 | 114 | typedef void *EGLNativeDisplayType; 115 | typedef khronos_uintptr_t EGLNativePixmapType; 116 | typedef khronos_uintptr_t EGLNativeWindowType; 117 | 118 | #elif defined(__unix__) || defined(USE_X11) 119 | 120 | /* X11 (tentative) */ 121 | #include 122 | #include 123 | 124 | typedef Display *EGLNativeDisplayType; 125 | typedef Pixmap EGLNativePixmapType; 126 | typedef Window EGLNativeWindowType; 127 | 128 | #elif defined(__APPLE__) 129 | 130 | typedef int EGLNativeDisplayType; 131 | typedef void *EGLNativePixmapType; 132 | typedef void *EGLNativeWindowType; 133 | 134 | #elif defined(__HAIKU__) 135 | 136 | #include 137 | 138 | typedef void *EGLNativeDisplayType; 139 | typedef khronos_uintptr_t EGLNativePixmapType; 140 | typedef khronos_uintptr_t EGLNativeWindowType; 141 | 142 | #elif defined(__Fuchsia__) 143 | 144 | typedef void *EGLNativeDisplayType; 145 | typedef khronos_uintptr_t EGLNativePixmapType; 146 | typedef khronos_uintptr_t EGLNativeWindowType; 147 | 148 | #else 149 | #error "Platform not recognized" 150 | #endif 151 | 152 | /* EGL 1.2 types, renamed for consistency in EGL 1.3 */ 153 | typedef EGLNativeDisplayType NativeDisplayType; 154 | typedef EGLNativePixmapType NativePixmapType; 155 | typedef EGLNativeWindowType NativeWindowType; 156 | 157 | 158 | /* Define EGLint. This must be a signed integral type large enough to contain 159 | * all legal attribute names and values passed into and out of EGL, whether 160 | * their type is boolean, bitmask, enumerant (symbolic constant), integer, 161 | * handle, or other. While in general a 32-bit integer will suffice, if 162 | * handles are 64 bit types, then EGLint should be defined as a signed 64-bit 163 | * integer type. 164 | */ 165 | typedef khronos_int32_t EGLint; 166 | 167 | 168 | /* C++ / C typecast macros for special EGL handle values */ 169 | #if defined(__cplusplus) 170 | #define EGL_CAST(type, value) (static_cast(value)) 171 | #else 172 | #define EGL_CAST(type, value) ((type) (value)) 173 | #endif 174 | 175 | #endif /* __eglplatform_h */ 176 | -------------------------------------------------------------------------------- /doc/API_REFERENCE_JS.md: -------------------------------------------------------------------------------- 1 | ## WebRays JavaScript API Reference 2 | 3 | WebRays is packaged as a JavaScript ES6 `module`. Users submit a callback to the `OnLoad` function that is called when WebRays has been initialized. From there, they can use an existing `gl` context to initialize a `WebGLIntersectionEngine` object. The constructed `WebGLIntersectionEngine` object contains the bulk of the API required for adding ray tracing functionality to an existing `WebGL` application. 4 | 5 | ### WebRays Module Javascript API 6 | 7 | | Function | Description | 8 | |:--|:--| 9 | | OnLoad (
    callback
) | Call `callback` when the WebRays module is ready to use. Only when `OnLoad` has been called, it is safe to call any WebRays specific API function | 10 | | WebGLIntersectionEngine (
    gl
) | Uses the provided `gl` context to create a WebGL-backed intersection engine. On success, it returns a JS object containing the functionality of the WebRays library. This is currently the only available backend | 11 | 12 | ### WebRays Object Javascript API 13 | 14 | Member functions provided by a constructed `WebGLIntersectionEngine` object 15 | ``` 16 | wr = new WebRays.WebGLIntersectionEngine(gl); 17 | ``` 18 | 19 | | Function | Description | 20 | |:--|:--| 21 | | Update () | Perform any pending updates. This function should be called after any important interaction with the WebRays API in order to submit changes. For example every time a shape is added or an instance is updated. The returned `flags` should be used by the user to determine if further updates should take place on the application side as well

`return`: flags indicating what has changed in the backend for the user to perform appropriate actions | 22 | | CreateAds (
    options
) | `options` is JS object with properties for the created ADS. Currently the only available option is the type of the created ADS. Simply pass a JS object with a `type` member that is either "BLAS" or "TLAS"

`return`: A handle for the newly created ADS that can be used to refer to this specific ADS both on the clent side and device side | 23 | | AddShape (
    ads,
    vertices,
    vertex_stride,
    normals,
    normal_stride,
    uvs,
    uv_stride,
    faces
) | Vertices, Normals and UVs are expected as `Float32Array`s. Each vertex and normal is defined by 3 consecutive `float`s (`x, y, z`). UVs are similarly defined by 2 `float`s (`u, v`). The number of attributes is expected to be the `length` of the vertex array. Faces are stored in a `Int32Array` array. They are defined by 4 consecutive `int`s (`x, y, z, w`). The first 3 are the offsets in the attribute arrays. The `w` component is left under user control amd cam be used to store per-face information

`return`: shape handle representing the submitted geometry group | 24 | | AddInstance (
    tlas,
    blas,
    transformation
) | Add an instance of an existing `blas` to an existing `tlas`. The transformation matrix is a `Float32Array`, corresponding to a 4x3 matrix in column-major order with the translation part being at positions 9, 10, and 11

`return`: instance handle representing the submitted instance | 25 | | UpdateInstance (
    tlas,
    instance_id,
    transformation
) | Update the previously submitted instance `instance_id`. The transformation matrix is a `Float32Array`, corresponding to a 4x3 matrix in column-major order with the translation part being at positions 9, 10, and 11 | 26 | | QueryIntersection (
    ray_buffers,
    isect_buffer,
    dims
) | Take the rays from the provided `ray_buffers`, intersect them with the `ads` and store the **closest-hit** results in `isect_buffer` | 27 | | QueryOcclusion (
    ray_buffers,
    occlusion_buffer,
    dims
) | Take the rays from the provided `ray_buffers`, intersect them with the `ads` and store the binary **occlusion** results in `occlusion_buffer` | 28 | | GetSceneAccessorString () | Returns a string representation of the accessor code. For example, in the WebGL implementation, this includes the GLSL API that can be used for in-shader intersections. `Update` flags indicate when this code has changed and users should make sure to always use the latest device-side API in their shaders. In WebGL this API simply needs to get prepended to the user's code | 29 | | GetSceneAccessorBindings () | Get the bindings for the data structures. For example, in the WebGL implementation, these include the textures, buffers e.t.c. that are required for the GLSL API to function within a user's shader. `Update` flags indicate when these bindings have changed and users should make sure to use the latest bindings in their applciation | 30 | | RayBufferRequirements (
    dims
) | Request the requirements for a ray buffer of dimensionality specified by `dims` that will store ray origins or directions. The returned JS object will be filled with the appropriate information. For example a 2D ray buffer will naturally be backed by a 2D RGBA32F texture. The actual allocation of the buffers is left to the application for finer control. The WebGL backend currently only supports 2D ray buffers | 31 | | IntersectionBufferRequirements (
    dims
) | Request the requirements for an intersection buffer of dimensionality specified by `dims` that will receive **closest-hit** results. The returned JS object will be filled with the appropriate information. For example a 2D intersection buffer will naturally be backed by a 2D RGBA32I texture. The actual allocation of the buffers is left to the application for finer control. The WebGL backend currently only supports 2D intersection buffers | 32 | | OcclusionBufferRequirements (
    dims
) | Request the requirements for an occlusion buffer of dimensionality specified by `dims` that will receive **occlusion** results. The returned JS object will be filled with the appropriate information. For example a 2D occlusion buffer will naturally be backed by a 2D R32I texture. The actual allocation of the buffers is left to the application for finer control. The WebGL backend currently only supports 2D occlusion buffers | -------------------------------------------------------------------------------- /deps/include/platform/Feature.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2019 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // Feature.h: Definition of structs to hold feature/workaround information. 7 | // 8 | 9 | #ifndef ANGLE_PLATFORM_FEATURE_H_ 10 | #define ANGLE_PLATFORM_FEATURE_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #define ANGLE_FEATURE_CONDITION(set, feature, cond) \ 17 | do \ 18 | { \ 19 | (set)->feature.enabled = cond; \ 20 | (set)->feature.condition = ANGLE_STRINGIFY(cond); \ 21 | } while (0) 22 | 23 | namespace angle 24 | { 25 | 26 | enum class FeatureCategory 27 | { 28 | FrontendWorkarounds, 29 | FrontendFeatures, 30 | OpenGLWorkarounds, 31 | D3DWorkarounds, 32 | D3DCompilerWorkarounds, 33 | VulkanWorkarounds, 34 | VulkanFeatures, 35 | MetalFeatures, 36 | }; 37 | 38 | constexpr char kFeatureCategoryFrontendWorkarounds[] = "Frontend workarounds"; 39 | constexpr char kFeatureCategoryFrontendFeatures[] = "Frontend features"; 40 | constexpr char kFeatureCategoryOpenGLWorkarounds[] = "OpenGL workarounds"; 41 | constexpr char kFeatureCategoryD3DWorkarounds[] = "D3D workarounds"; 42 | constexpr char kFeatureCategoryD3DCompilerWorkarounds[] = "D3D compiler workarounds"; 43 | constexpr char kFeatureCategoryVulkanWorkarounds[] = "Vulkan workarounds"; 44 | constexpr char kFeatureCategoryVulkanFeatures[] = "Vulkan features"; 45 | constexpr char kFeatureCategoryMetalFeatures[] = "Metal features"; 46 | constexpr char kFeatureCategoryUnknown[] = "Unknown"; 47 | 48 | inline const char *FeatureCategoryToString(const FeatureCategory &fc) 49 | { 50 | switch (fc) 51 | { 52 | case FeatureCategory::FrontendWorkarounds: 53 | return kFeatureCategoryFrontendWorkarounds; 54 | break; 55 | 56 | case FeatureCategory::FrontendFeatures: 57 | return kFeatureCategoryFrontendFeatures; 58 | break; 59 | 60 | case FeatureCategory::OpenGLWorkarounds: 61 | return kFeatureCategoryOpenGLWorkarounds; 62 | break; 63 | 64 | case FeatureCategory::D3DWorkarounds: 65 | return kFeatureCategoryD3DWorkarounds; 66 | break; 67 | 68 | case FeatureCategory::D3DCompilerWorkarounds: 69 | return kFeatureCategoryD3DCompilerWorkarounds; 70 | break; 71 | 72 | case FeatureCategory::VulkanWorkarounds: 73 | return kFeatureCategoryVulkanWorkarounds; 74 | break; 75 | 76 | case FeatureCategory::VulkanFeatures: 77 | return kFeatureCategoryVulkanFeatures; 78 | break; 79 | 80 | case FeatureCategory::MetalFeatures: 81 | return kFeatureCategoryMetalFeatures; 82 | break; 83 | 84 | default: 85 | return kFeatureCategoryUnknown; 86 | break; 87 | } 88 | } 89 | 90 | constexpr char kFeatureStatusEnabled[] = "enabled"; 91 | constexpr char kFeatureStatusDisabled[] = "disabled"; 92 | 93 | inline const char *FeatureStatusToString(const bool &status) 94 | { 95 | if (status) 96 | { 97 | return kFeatureStatusEnabled; 98 | } 99 | return kFeatureStatusDisabled; 100 | } 101 | 102 | struct Feature; 103 | 104 | using FeatureMap = std::map; 105 | using FeatureList = std::vector; 106 | 107 | struct Feature 108 | { 109 | Feature(const Feature &other); 110 | Feature(const char *name, 111 | const FeatureCategory &category, 112 | const char *description, 113 | FeatureMap *const mapPtr, 114 | const char *bug); 115 | ~Feature(); 116 | 117 | // The name of the workaround, lowercase, camel_case 118 | const char *const name; 119 | 120 | // The category that the workaround belongs to. Eg. "Vulkan workarounds" 121 | const FeatureCategory category; 122 | 123 | // A short description to be read by the user. 124 | const char *const description; 125 | 126 | // A link to the bug, if any 127 | const char *const bug; 128 | 129 | // Whether the workaround is enabled or not. Determined by heuristics like vendor ID and 130 | // version, but may be overriden to any value. 131 | bool enabled = false; 132 | 133 | // A stingified version of the condition used to set 'enabled'. ie "IsNvidia() && IsApple()" 134 | const char *condition; 135 | }; 136 | 137 | inline Feature::Feature(const Feature &other) = default; 138 | inline Feature::Feature(const char *name, 139 | const FeatureCategory &category, 140 | const char *description, 141 | FeatureMap *const mapPtr, 142 | const char *bug = "") 143 | : name(name), 144 | category(category), 145 | description(description), 146 | bug(bug), 147 | enabled(false), 148 | condition("") 149 | { 150 | if (mapPtr != nullptr) 151 | { 152 | (*mapPtr)[std::string(name)] = this; 153 | } 154 | } 155 | 156 | inline Feature::~Feature() = default; 157 | 158 | struct FeatureSetBase 159 | { 160 | public: 161 | FeatureSetBase(); 162 | ~FeatureSetBase(); 163 | 164 | private: 165 | // Non-copyable 166 | FeatureSetBase(const FeatureSetBase &other) = delete; 167 | FeatureSetBase &operator=(const FeatureSetBase &other) = delete; 168 | 169 | protected: 170 | FeatureMap members = FeatureMap(); 171 | 172 | public: 173 | void overrideFeatures(const std::vector &featureNames, bool enabled) 174 | { 175 | for (const std::string &name : featureNames) 176 | { 177 | if (members.find(name) != members.end()) 178 | { 179 | members[name]->enabled = enabled; 180 | } 181 | } 182 | } 183 | 184 | void populateFeatureList(FeatureList *features) const 185 | { 186 | for (FeatureMap::const_iterator it = members.begin(); it != members.end(); it++) 187 | { 188 | features->push_back(it->second); 189 | } 190 | } 191 | 192 | const FeatureMap &getFeatures() const { return members; } 193 | }; 194 | 195 | inline FeatureSetBase::FeatureSetBase() = default; 196 | inline FeatureSetBase::~FeatureSetBase() = default; 197 | 198 | } // namespace angle 199 | 200 | #endif // ANGLE_PLATFORM_WORKAROUND_H_ 201 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | cmake_policy(SET CMP0048 NEW) 3 | 4 | set(WEBRAYS_LIBRARY_NAME "webrays") 5 | set(WEBRAYS_LIBRARY_SOURCES webrays.cpp 6 | webrays_ads.cpp 7 | webrays_gl.cpp 8 | webrays_cpu.cpp 9 | webrays_queue.cpp 10 | webrays_shader_engine.cpp) 11 | 12 | project(webrays) 13 | 14 | if(SINGLE_FILE) 15 | set(EMBED_WASM 1) 16 | else() 17 | set(EMBED_WASM 0) 18 | endif() 19 | 20 | if (EMSCRIPTEN) 21 | add_library (${PROJECT_NAME} ${WEBRAYS_LIBRARY_SOURCES}) 22 | else() 23 | add_library (${PROJECT_NAME} SHARED ${WEBRAYS_LIBRARY_SOURCES}) 24 | set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "../include/webrays/webrays.h") 25 | endif() 26 | 27 | if (EMSCRIPTEN) 28 | 29 | set(CMAKE_STATIC_LIBRARY_PREFIX "") 30 | set(CMAKE_AR "${EMSCRIPTEN_ROOT_PATH}/emcc${EMCC_SUFFIX}") 31 | set(EMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES True) 32 | set(CMAKE_STATIC_LIBRARY_SUFFIX ".js") 33 | set(CMAKE_C_CREATE_STATIC_LIBRARY " -o ") 34 | set(CMAKE_CXX_CREATE_STATIC_LIBRARY " -o ") 35 | 36 | set(CMAKE_C_FLAGS_ALL_CONFIGS "-fno-exceptions -s WASM=1 -Wall -Wextra -Wno-double-promotion -Wno-unused-parameter -Wno-unused-variable -Wno-sign-compare -Wno-missing-braces") 37 | set(CMAKE_LINKER_FLAGS_ALL_CONFIGS "-lEGL -lGLESv2 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s MODULARIZE=1 -s EXPORT_ES6=1 -s WASM=1 -s EXPORT_NAME=\"'createWebRaysModule'\" -s ABORTING_MALLOC=0 -s ALLOW_MEMORY_GROWTH=1 -s FULL_ES3=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -s GL_PREINITIALIZED_CONTEXT=1 -s SINGLE_FILE=${EMBED_WASM} -s EXPORTED_RUNTIME_METHODS=\"['cwrap','GL','UTF8ToString','lengthBytesUTF8','stringToUTF8']\" -s EXPORTED_FUNCTIONS=\"['_free', '_malloc']\" --extern-pre-js \"${CMAKE_SOURCE_DIR}/src/webrays_loader.js\"") 38 | 39 | set(CMAKE_C_FLAGS_RELEASE "-O3 ${CMAKE_C_FLAGS_ALL_CONFIGS}") 40 | set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "-O3 ${CMAKE_LINKER_FLAGS_ALL_CONFIGS}") 41 | 42 | set(CMAKE_C_FLAGS_MINSIZEREL "-Os ${CMAKE_C_FLAGS_ALL_CONFIGS}") 43 | set(CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL "-Os ${CMAKE_LINKER_FLAGS_ALL_CONFIGS}") 44 | 45 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_ALL_CONFIGS}") 46 | set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_ALL_CONFIGS}") 47 | 48 | elseif(WIN32) 49 | 50 | string(REPLACE "/cl.exe" "" CMAKE_C_COMPILER_DIRECTORY "${CMAKE_C_COMPILER}") 51 | find_program(DUMPBIN_EXE dumpbin HINTS "${CMAKE_C_COMPILER_DIRECTORY}" PATHS "${CMAKE_C_COMPILER_DIRECTORY}") 52 | find_program(LIB_EXE lib HINTS "${CMAKE_C_COMPILER_DIRECTORY}" PATHS "${CMAKE_C_COMPILER_DIRECTORY}") 53 | 54 | #if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64|x64)") 55 | if (${CMAKE_SIZEOF_VOID_P} MATCHES 8) 56 | set(ARCH "X64") 57 | else() 58 | set(ARCH "X86") 59 | endif() 60 | 61 | exec_program(${DUMPBIN_EXE} ARGS "/EXPORTS \"${EGL_LIBRARY}\"" OUTPUT_VARIABLE EGL_EXPORTS) 62 | string(REGEX MATCHALL "[ ]egl[a-zA-Z_0-9@?]+" EGL_EXPORT_LIST ${EGL_EXPORTS}) 63 | string(APPEND EGL_DEFINITIONS_FILE "EXPORTS\n") 64 | foreach(export_name ${EGL_EXPORT_LIST}) 65 | string(APPEND EGL_DEFINITIONS_FILE "${export_name}\n") 66 | endforeach() 67 | file(WRITE "${CMAKE_BINARY_DIR}/libEGL.def" "${EGL_DEFINITIONS_FILE}") 68 | exec_program(${LIB_EXE} ARGS "/def:\"${CMAKE_BINARY_DIR}/libEGL.def\" /machine:${ARCH} /out:\"${CMAKE_BINARY_DIR}/libEGL.lib\" /NOLOGO") 69 | 70 | exec_program(${DUMPBIN_EXE} ARGS "/EXPORTS \"${GLES_LIBRARY}\"" OUTPUT_VARIABLE GLES_EXPORTS) 71 | string(REGEX MATCHALL "[ ][?][a-zA-Z_0-9@?]+|[ ]gl[a-zA-Z_0-9@?]+|[ ]GL[a-zA-Z_0-9@?]+|[ ]EGL[a-zA-Z_0-9@?]+|[ ]ANGLE[a-zA-Z_0-9@?]+" GLES_EXPORT_LIST ${GLES_EXPORTS}) 72 | string(APPEND GLES_DEFINITIONS_FILE "EXPORTS\n") 73 | foreach(export_name ${GLES_EXPORT_LIST}) 74 | string(APPEND GLES_DEFINITIONS_FILE "${export_name}\n") 75 | endforeach() 76 | file(WRITE "${CMAKE_BINARY_DIR}/libGLESv2.def" "${GLES_DEFINITIONS_FILE}") 77 | exec_program(${LIB_EXE} ARGS "/def:\"${CMAKE_BINARY_DIR}/libGLESv2.def\" /machine:${ARCH} /out:\"${CMAKE_BINARY_DIR}/libGLESv2.lib\" /NOLOGO") 78 | 79 | set(ANGLE_ARCHIVE "${CMAKE_BINARY_DIR}/libGLESv2.lib" CACHE INTERNAL "") 80 | set(GLES_ARCHIVE "${CMAKE_BINARY_DIR}/libGLESv2.lib" CACHE INTERNAL "") 81 | set(EGL_ARCHIVE "${CMAKE_BINARY_DIR}/libEGL.lib" CACHE INTERNAL "") 82 | 83 | endif() 84 | 85 | if(NOT MSVC) 86 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") 87 | endif() 88 | 89 | target_include_directories(${PROJECT_NAME} PRIVATE "../include") 90 | if (EMSCRIPTEN) 91 | 92 | if(NOT SINGLE_FILE) 93 | install(FILES "${CMAKE_BINARY_DIR}/src/${WEBRAYS_LIBRARY_NAME}.wasm" DESTINATION webrays/js/common) 94 | endif() 95 | install(FILES "${CMAKE_BINARY_DIR}/src/${WEBRAYS_LIBRARY_NAME}.js" DESTINATION webrays/js/common) 96 | install(DIRECTORY ../examples/web/ DESTINATION webrays) 97 | 98 | if(PREPARE_FOR_PUBLISH) 99 | if(NOT SINGLE_FILE) 100 | install(FILES "${CMAKE_BINARY_DIR}/src/${WEBRAYS_LIBRARY_NAME}.wasm" DESTINATION ${CMAKE_SOURCE_DIR}/dist) 101 | endif() 102 | install(FILES "${CMAKE_BINARY_DIR}/src/${WEBRAYS_LIBRARY_NAME}.js" DESTINATION ${CMAKE_SOURCE_DIR}/dist) 103 | endif() 104 | else() 105 | 106 | target_include_directories(${PROJECT_NAME} PRIVATE "../deps/include") 107 | 108 | set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION}) 109 | set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 110 | 111 | target_compile_definitions(${PROJECT_NAME} PUBLIC WRAYS_BUILD PUBLIC _CRT_SECURE_NO_WARNINGS) 112 | 113 | install(TARGETS ${PROJECT_NAME} 114 | ARCHIVE DESTINATION webrays/lib 115 | LIBRARY DESTINATION webrays/lib 116 | RUNTIME DESTINATION webrays/bin 117 | PUBLIC_HEADER DESTINATION webrays/include/webrays) 118 | install(DIRECTORY "../deps/include/" DESTINATION webrays/include) 119 | if(WIN32) 120 | install(FILES "${GLES_LIBRARY}" DESTINATION webrays/bin) 121 | install(FILES "${EGL_LIBRARY}" DESTINATION webrays/bin) 122 | else() 123 | install(FILES "${GLES_LIBRARY}" DESTINATION webrays/lib) 124 | install(FILES "${EGL_LIBRARY}" DESTINATION webrays/lib) 125 | endif() 126 | if(NOT "${GLES_ARCHIVE}" MATCHES "") 127 | install(FILES "${GLES_ARCHIVE}" DESTINATION webrays/lib) 128 | endif() 129 | if(NOT "${EGL_ARCHIVE}" MATCHES "") 130 | install(FILES "${EGL_ARCHIVE}" DESTINATION webrays/lib) 131 | endif() 132 | endif() -------------------------------------------------------------------------------- /deps/include/platform/FeaturesMtl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2019 The ANGLE Project Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | // 6 | // FeaturesMtl.h: Optional features for the Metal renderer. 7 | // 8 | 9 | #ifndef ANGLE_PLATFORM_FEATURESMTL_H_ 10 | #define ANGLE_PLATFORM_FEATURESMTL_H_ 11 | 12 | #include "platform/Feature.h" 13 | 14 | namespace angle 15 | { 16 | 17 | struct FeaturesMtl : FeatureSetBase 18 | { 19 | // BaseVertex/Instanced draw support: 20 | Feature hasBaseVertexInstancedDraw = { 21 | "has_base_vertex_instanced_draw", FeatureCategory::MetalFeatures, 22 | "The renderer supports base vertex instanced draw", &members}; 23 | 24 | // Support depth texture filtering 25 | Feature hasDepthTextureFiltering = { 26 | "has_depth_texture_filtering", FeatureCategory::MetalFeatures, 27 | "The renderer supports depth texture's filtering other than nearest", &members}; 28 | 29 | // Support explicit memory barrier 30 | Feature hasExplicitMemBarrier = {"has_explicit_mem_barrier_mtl", FeatureCategory::MetalFeatures, 31 | "The renderer supports explicit memory barrier", &members}; 32 | 33 | // Some renderer can break render pass cheaply, i.e. desktop class GPUs. 34 | Feature hasCheapRenderPass = {"has_cheap_render_pass_mtl", FeatureCategory::MetalFeatures, 35 | "The renderer can cheaply break a render pass.", &members}; 36 | 37 | // Non-uniform compute shader dispatch support, i.e. Group size is not necessarily to be fixed: 38 | Feature hasNonUniformDispatch = { 39 | "has_non_uniform_dispatch", FeatureCategory::MetalFeatures, 40 | "The renderer supports non uniform compute shader dispatch's group size", &members}; 41 | 42 | // fragment stencil output support 43 | Feature hasStencilOutput = {"has_shader_stencil_output", FeatureCategory::MetalFeatures, 44 | "The renderer supports stencil output from fragment shader", 45 | &members}; 46 | 47 | // Texture swizzle support: 48 | Feature hasTextureSwizzle = {"has_texture_swizzle", FeatureCategory::MetalFeatures, 49 | "The renderer supports texture swizzle", &members}; 50 | 51 | Feature hasDepthAutoResolve = { 52 | "has_msaa_depth_auto_resolve", FeatureCategory::MetalFeatures, 53 | "The renderer supports MSAA depth auto resolve at the end of render pass", &members}; 54 | 55 | Feature hasStencilAutoResolve = { 56 | "has_msaa_stencil_auto_resolve", FeatureCategory::MetalFeatures, 57 | "The renderer supports MSAA stencil auto resolve at the end of render pass", &members}; 58 | 59 | Feature hasEvents = {"has_mtl_events", FeatureCategory::MetalFeatures, 60 | "The renderer supports MTL(Shared)Event", &members}; 61 | 62 | Feature allowInlineConstVertexData = { 63 | "allow_inline_const_vertex_data", FeatureCategory::MetalFeatures, 64 | "The renderer supports using inline constant data for small client vertex data", &members}; 65 | 66 | // On macos, separate depth & stencil buffers are not supproted. However, on iOS devices, 67 | // they are supproted: 68 | Feature allowSeparatedDepthStencilBuffers = { 69 | "allow_separate_depth_stencil_buffers", FeatureCategory::MetalFeatures, 70 | "Some Apple platforms such as iOS allows separate depth & stencil buffers, " 71 | "whereas others such as macOS don't", 72 | &members}; 73 | 74 | Feature allowRuntimeSamplerCompareMode = { 75 | "allow_runtime_sampler_compare_mode", FeatureCategory::MetalFeatures, 76 | "The renderer supports changing sampler's compare mode outside shaders", &members}; 77 | 78 | Feature allowSamplerCompareGradient = { 79 | "allow_sampler_compare_gradient", FeatureCategory::MetalFeatures, 80 | "The renderer supports sample_compare with gradients", &members}; 81 | 82 | Feature allowSamplerCompareLod = {"allow_sampler_compare_lod", FeatureCategory::MetalFeatures, 83 | "The renderer supports sample_compare with lod", &members}; 84 | 85 | Feature allowBufferReadWrite = {"allow_buffer_read_write", FeatureCategory::MetalFeatures, 86 | "The renderer supports buffer read & write in the same shader", 87 | &members}; 88 | 89 | Feature allowMultisampleStoreAndResolve = { 90 | "allow_msaa_store_and_resolve", FeatureCategory::MetalFeatures, 91 | "The renderer supports MSAA store and resolve in the same pass", &members}; 92 | 93 | Feature allowGenMultipleMipsPerPass = { 94 | "gen_multiple_mips_per_pass", FeatureCategory::MetalFeatures, 95 | "The renderer supports generating multiple mipmaps per pass", &members}; 96 | 97 | Feature forceD24S8AsUnsupported = {"force_d24s8_as_unsupported", FeatureCategory::MetalFeatures, 98 | "Force Depth24Stencil8 format as unsupported.", &members}; 99 | 100 | Feature forceBufferGPUStorage = { 101 | "force_buffer_gpu_storage", FeatureCategory::MetalFeatures, 102 | "On systems that support both buffer' memory allocation on GPU and shared memory (such as " 103 | "macOS), force using GPU memory allocation for buffers everytime or not.", 104 | &members}; 105 | 106 | // Whether SPIR-V should be generated directly instead of through glslang. Transitory feature 107 | // until the work is complete. 108 | Feature directSPIRVGeneration = {"directSPIRVGeneration", FeatureCategory::MetalFeatures, 109 | "Direct translation to SPIR-V.", &members, 110 | "http://anglebug.com/4889"}; 111 | 112 | Feature forceNonCSBaseMipmapGeneration = { 113 | "force_non_cs_mipmap_gen", FeatureCategory::MetalFeatures, 114 | "Turn this feature on to disallow Compute Shader based mipmap generation. Compute Shader " 115 | "based mipmap generation might cause GPU hang on some older iOS devices.", 116 | &members}; 117 | 118 | Feature emulateTransformFeedback = { 119 | "emulate_transform_feedback", FeatureCategory::MetalFeatures, 120 | "Turn this on to allow transform feedback in Metal using a 2-pass VS for GLES3.", &members}; 121 | 122 | // Rewrite row-major matrices as column-major 123 | Feature rewriteRowMajorMatrices = {"rewrite_row_major_matrices", FeatureCategory::MetalFeatures, 124 | "Rewrite row major matrices in shaders as column major.", 125 | &members}; 126 | }; 127 | 128 | } // namespace angle 129 | 130 | #endif // ANGLE_PLATFORM_FEATURESMTL_H_ 131 | -------------------------------------------------------------------------------- /examples/web/kernels/intersection.glsl: -------------------------------------------------------------------------------- 1 | #line 0 2 | precision highp sampler2D; 3 | precision highp sampler2DArray; 4 | precision highp isampler2D; 5 | 6 | layout(location = 0) out vec4 accumulation_OUT; 7 | layout(location = 1) out vec4 origin_OUT; 8 | layout(location = 2) out vec4 direction_OUT; 9 | layout(location = 3) out vec4 payload_OUT; 10 | 11 | uniform int ads; 12 | uniform int sample_index; 13 | uniform int depth; 14 | uniform ivec4 tile; 15 | uniform ivec2 frame; 16 | uniform uvec2 seed; 17 | 18 | uniform sampler2D ray_origins; 19 | uniform sampler2D ray_accumulations; 20 | uniform sampler2D ray_directions; 21 | uniform sampler2D ray_payloads; 22 | uniform isampler2D intersections; 23 | 24 | uniform sampler2D materialBuffer; 25 | uniform sampler2D lightBuffer; 26 | uniform int light_count; 27 | uniform sampler2DArray texturesBuffer; 28 | 29 | #include "common.inc.glsl" 30 | #include "reflection.inc.glsl" 31 | #include "util.inc.glsl" 32 | #include "bxdf.inc.glsl" 33 | #include "light.inc.glsl" 34 | 35 | void terminate_ray() { 36 | direction_OUT = vec4(0.0); 37 | origin_OUT = vec4(0.0); 38 | } 39 | 40 | void main() { 41 | /* Reconstruct pixel coordinates from tile coordinates */ 42 | vec4 tilef = vec4(tile); 43 | vec2 framef = vec2(frame); 44 | vec2 pixel = tilef.xy * tilef.zw + gl_FragCoord.xy; 45 | 46 | vec4 direction_IN = texelFetch(ray_directions, ivec2(gl_FragCoord.xy), 0); 47 | vec4 origin_IN = texelFetch(ray_origins, ivec2(gl_FragCoord.xy), 0); 48 | vec4 payload_IN = texelFetch(ray_payloads, ivec2(gl_FragCoord.xy), 0); 49 | vec4 accumulation_IN = texelFetch(ray_accumulations, ivec2(gl_FragCoord.xy), 0); 50 | ivec4 intersection = texelFetch(intersections, ivec2(gl_FragCoord.xy), 0); 51 | 52 | vec3 wo = -direction_IN.xyz; 53 | vec3 throughput = payload_IN.xyz; 54 | 55 | if (direction_IN.w == 0.0) { 56 | accumulation_OUT = accumulation_IN; 57 | payload_OUT = vec4(0.0); 58 | terminate_ray(); 59 | return; 60 | } 61 | 62 | if (!wr_IsValidIntersection(intersection) && depth == 0) { 63 | accumulation_OUT = vec4(0); 64 | payload_OUT = vec4(0); 65 | terminate_ray(); 66 | return; 67 | } 68 | 69 | // Generate random numbers 70 | uint counter = uint(pixel.x) + uint(pixel.y) * uint(frame.x) + 1u; 71 | vec4 random_lights = random4f((uint(sample_index) * 2u + 0u) * counter, seed.x, seed.y); 72 | vec4 random_bxdfs = random4f((uint(sample_index) * 2u + 1u) * counter, seed.x, seed.y); 73 | 74 | vec3 origin = wr_GetInterpolatedPosition(ads, intersection); 75 | origin = origin_IN.xyz + direction_IN.xyz * wr_GetHitDistance(intersection); 76 | 77 | ivec4 face = wr_GetFace(ads, intersection); 78 | vec2 uv = wr_GetInterpolatedTexCoords(ads, intersection); 79 | vec3 geom_normal = wr_GetGeomNormal(ads, intersection); 80 | vec3 shading_normal = normalize(wr_GetInterpolatedNormal(ads, intersection)); 81 | shading_normal = faceforward(shading_normal, direction_IN.xyz, shading_normal); 82 | 83 | vec4 type_base_color = texelFetch(materialBuffer, ivec2(0,face.w), 0); 84 | vec3 textureProperties = texelFetch(materialBuffer, ivec2(2,face.w), 0).rgb; // a == -1, for now 85 | 86 | int basecolorTextureIndex = int(textureProperties.r); 87 | int metallicTextureIndex = int(textureProperties.g); 88 | int normalTextureIndex = int(textureProperties.b); 89 | 90 | type_base_color.gba = (basecolorTextureIndex == -1) ? type_base_color.gba : texture(texturesBuffer, vec3(uv.xy, basecolorTextureIndex)).rgb; 91 | vec4 normal_emission = (normalTextureIndex == -1) ? vec4(1,0,0,0) : texture(texturesBuffer, vec3(uv.xy, normalTextureIndex)); 92 | vec4 metal_refl_gloss = (metallicTextureIndex == -1) ? vec4(0,0,0.06,0.8) : texture(texturesBuffer, vec3(uv.xy, metallicTextureIndex)); 93 | 94 | vec3 v0 = wr_GetPosition(ads, intersection, face.x); 95 | vec3 v1 = wr_GetPosition(ads, intersection, face.y); 96 | vec3 v2 = wr_GetPosition(ads, intersection, face.z); 97 | vec2 uv0 = wr_GetTexCoords(ads, intersection, face.x); 98 | vec2 uv1 = wr_GetTexCoords(ads, intersection, face.y); 99 | vec2 uv2 = wr_GetTexCoords(ads, intersection, face.z); 100 | 101 | vec3 deltaPos1 = v1 - v0; 102 | vec3 deltaPos2 = v2 - v0; 103 | 104 | // UV delta 105 | vec2 deltaUV1 = uv1 - uv0; 106 | vec2 deltaUV2 = uv2 - uv0; 107 | 108 | /* TODO: Normal mapping needs revisiting */ 109 | vec3 tangent = normalize(deltaPos1 * deltaUV2.y - deltaPos2 * deltaUV1.y); 110 | vec3 bitangent = normalize(deltaPos2 * deltaUV1.x - deltaPos1 * deltaUV2.x); 111 | 112 | vec3 NN = normal_emission.rgb; 113 | NN = NN * 2.0 - 1.0; 114 | vec3 N = mat3(tangent, bitangent, shading_normal) * normalize(NN); 115 | shading_normal = N; 116 | 117 | event surface; 118 | surface.basis = create_onb(shading_normal); 119 | surface.base_color = (basecolorTextureIndex == -1) ? type_base_color.gba : texture(texturesBuffer, vec3(uv.xy, basecolorTextureIndex)).rgb; 120 | surface.type = int(type_base_color.x); 121 | surface.shading_normal = shading_normal; 122 | surface.position = origin; 123 | 124 | /* Estimate Direct Lighting */ 125 | float light_selection_pdf; 126 | wr_light light = Lights_sample(random_lights.x, light_selection_pdf); 127 | 128 | float light_pdf; 129 | float light_distance; 130 | vec3 wi; 131 | vec3 Li = Light_sample(surface, light, random_lights.yz, wi, light_pdf, light_distance); 132 | vec3 Ld = vec3(0); 133 | vec3 offset_oriign = origin + geom_normal * 0.05; 134 | 135 | if ( light_pdf > 0.0 && !is_zero(Li)) { 136 | float scattering_pdf = BxDF_pdf(surface, wo, wi); 137 | vec3 BxDF = BxDF_eval(surface, wo, wi); 138 | 139 | if(scattering_pdf > 0.0 && !is_zero(BxDF)) { 140 | float NdL = max(0.001, abs(dot(shading_normal, wi))); 141 | bool occluded = wr_QueryOcclusion(ads, offset_oriign, wi, light_distance - 0.05); 142 | 143 | if(!occluded) { 144 | Ld += (throughput * BxDF * NdL * Li) / (light_pdf * light_selection_pdf); 145 | } 146 | } 147 | } 148 | 149 | #define RR_BOUNCES 3 150 | if (depth > RR_BOUNCES) { 151 | float t_probability = min(0.95, luminance(throughput)); 152 | if (t_probability < random_lights.w) { 153 | accumulation_OUT = accumulation_IN; 154 | payload_OUT = vec4(0.0); 155 | terminate_ray(); 156 | return; 157 | } 158 | else { 159 | throughput /= t_probability; 160 | } 161 | } 162 | 163 | /* Next Event */ 164 | float scattering_pdf; 165 | vec3 BxDF = BxDF_sample(surface, wo, random_bxdfs.xy, wi, scattering_pdf); 166 | if(scattering_pdf == 0.0 || is_zero(BxDF)) { 167 | accumulation_OUT = accumulation_IN; 168 | payload_OUT = vec4(0.0); 169 | terminate_ray(); 170 | return; 171 | } 172 | 173 | float NdL = max(0.001, abs(dot(shading_normal, wi))); 174 | 175 | accumulation_OUT = vec4(accumulation_IN.xyz + Ld, 1.0); 176 | direction_OUT = vec4(wi, 10000.0); 177 | origin_OUT = vec4(offset_oriign, 0.0); 178 | payload_OUT = vec4((throughput * BxDF * NdL) / max(0.001, scattering_pdf), 0); // throughput 179 | } -------------------------------------------------------------------------------- /deps/include/CL/cl_gl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2021 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __OPENCL_CL_GL_H 18 | #define __OPENCL_CL_GL_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef cl_uint cl_gl_object_type; 27 | typedef cl_uint cl_gl_texture_info; 28 | typedef cl_uint cl_gl_platform_info; 29 | typedef struct __GLsync *cl_GLsync; 30 | 31 | /* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ 32 | #define CL_GL_OBJECT_BUFFER 0x2000 33 | #define CL_GL_OBJECT_TEXTURE2D 0x2001 34 | #define CL_GL_OBJECT_TEXTURE3D 0x2002 35 | #define CL_GL_OBJECT_RENDERBUFFER 0x2003 36 | #ifdef CL_VERSION_1_2 37 | #define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E 38 | #define CL_GL_OBJECT_TEXTURE1D 0x200F 39 | #define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 40 | #define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 41 | #endif 42 | 43 | /* cl_gl_texture_info */ 44 | #define CL_GL_TEXTURE_TARGET 0x2004 45 | #define CL_GL_MIPMAP_LEVEL 0x2005 46 | #ifdef CL_VERSION_1_2 47 | #define CL_GL_NUM_SAMPLES 0x2012 48 | #endif 49 | 50 | 51 | extern CL_API_ENTRY cl_mem CL_API_CALL 52 | clCreateFromGLBuffer(cl_context context, 53 | cl_mem_flags flags, 54 | cl_GLuint bufobj, 55 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 56 | 57 | #ifdef CL_VERSION_1_2 58 | 59 | extern CL_API_ENTRY cl_mem CL_API_CALL 60 | clCreateFromGLTexture(cl_context context, 61 | cl_mem_flags flags, 62 | cl_GLenum target, 63 | cl_GLint miplevel, 64 | cl_GLuint texture, 65 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 66 | 67 | #endif 68 | 69 | extern CL_API_ENTRY cl_mem CL_API_CALL 70 | clCreateFromGLRenderbuffer(cl_context context, 71 | cl_mem_flags flags, 72 | cl_GLuint renderbuffer, 73 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 74 | 75 | extern CL_API_ENTRY cl_int CL_API_CALL 76 | clGetGLObjectInfo(cl_mem memobj, 77 | cl_gl_object_type * gl_object_type, 78 | cl_GLuint * gl_object_name) CL_API_SUFFIX__VERSION_1_0; 79 | 80 | extern CL_API_ENTRY cl_int CL_API_CALL 81 | clGetGLTextureInfo(cl_mem memobj, 82 | cl_gl_texture_info param_name, 83 | size_t param_value_size, 84 | void * param_value, 85 | size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; 86 | 87 | extern CL_API_ENTRY cl_int CL_API_CALL 88 | clEnqueueAcquireGLObjects(cl_command_queue command_queue, 89 | cl_uint num_objects, 90 | const cl_mem * mem_objects, 91 | cl_uint num_events_in_wait_list, 92 | const cl_event * event_wait_list, 93 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 94 | 95 | extern CL_API_ENTRY cl_int CL_API_CALL 96 | clEnqueueReleaseGLObjects(cl_command_queue command_queue, 97 | cl_uint num_objects, 98 | const cl_mem * mem_objects, 99 | cl_uint num_events_in_wait_list, 100 | const cl_event * event_wait_list, 101 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 102 | 103 | 104 | /* Deprecated OpenCL 1.1 APIs */ 105 | extern CL_API_ENTRY CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL 106 | clCreateFromGLTexture2D(cl_context context, 107 | cl_mem_flags flags, 108 | cl_GLenum target, 109 | cl_GLint miplevel, 110 | cl_GLuint texture, 111 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1_DEPRECATED; 112 | 113 | extern CL_API_ENTRY CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL 114 | clCreateFromGLTexture3D(cl_context context, 115 | cl_mem_flags flags, 116 | cl_GLenum target, 117 | cl_GLint miplevel, 118 | cl_GLuint texture, 119 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1_DEPRECATED; 120 | 121 | /* cl_khr_gl_sharing extension */ 122 | 123 | #define cl_khr_gl_sharing 1 124 | 125 | typedef cl_uint cl_gl_context_info; 126 | 127 | /* Additional Error Codes */ 128 | #define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 129 | 130 | /* cl_gl_context_info */ 131 | #define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 132 | #define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 133 | 134 | /* Additional cl_context_properties */ 135 | #define CL_GL_CONTEXT_KHR 0x2008 136 | #define CL_EGL_DISPLAY_KHR 0x2009 137 | #define CL_GLX_DISPLAY_KHR 0x200A 138 | #define CL_WGL_HDC_KHR 0x200B 139 | #define CL_CGL_SHAREGROUP_KHR 0x200C 140 | 141 | extern CL_API_ENTRY cl_int CL_API_CALL 142 | clGetGLContextInfoKHR(const cl_context_properties * properties, 143 | cl_gl_context_info param_name, 144 | size_t param_value_size, 145 | void * param_value, 146 | size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; 147 | 148 | typedef cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( 149 | const cl_context_properties * properties, 150 | cl_gl_context_info param_name, 151 | size_t param_value_size, 152 | void * param_value, 153 | size_t * param_value_size_ret); 154 | 155 | /* 156 | * cl_khr_gl_event extension 157 | */ 158 | #define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D 159 | 160 | extern CL_API_ENTRY cl_event CL_API_CALL 161 | clCreateEventFromGLsyncKHR(cl_context context, 162 | cl_GLsync sync, 163 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1; 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /* __OPENCL_CL_GL_H */ 170 | -------------------------------------------------------------------------------- /src/webrays_ads.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 Phasmatic 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _WRAYS_ACCELERATION_DATA_STRUCTURE_H_ 17 | #define _WRAYS_ACCELERATION_DATA_STRUCTURE_H_ 18 | 19 | #include "webrays_math.h" 20 | #include "webrays_context.h" 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | struct wr_bounds 28 | { 29 | vec3 min{ std::numeric_limits::max(), 30 | std::numeric_limits::max(), 31 | std::numeric_limits::max() }; 32 | vec3 max{ std::numeric_limits::lowest(), 33 | std::numeric_limits::lowest(), 34 | std::numeric_limits::lowest() }; 35 | }; 36 | 37 | struct wr_linear_bvh_node 38 | { 39 | wr_bounds bounds; 40 | union 41 | { 42 | int primitivesOffset; // leaf 43 | int secondChildOffset; // interior 44 | }; 45 | uint16_t nPrimitives; // 0 -> interior node 46 | uint8_t axis; // interior node: xyz 47 | uint8_t pad[1]; // ensure 32 byte total size 48 | }; 49 | 50 | #define WR_MAX_BINDINGS 8 51 | 52 | class ADS 53 | { 54 | 55 | public: 56 | const wr_binding* 57 | GetBindings() 58 | { 59 | return m_webgl_bindings; 60 | } 61 | int 62 | GetBindingsLength() 63 | { 64 | return m_webgl_binding_count; 65 | } 66 | 67 | virtual int 68 | AddTriangularMesh(float* positions, int position_stride, float* normals, 69 | int normal_stride, float* uvs, int uv_stride, 70 | int num_vertices, int* indices, int num_indices) = 0; 71 | virtual int 72 | AddSphere(float* position, float radius, int materialID) = 0; 73 | 74 | virtual bool 75 | Build() = 0; 76 | 77 | virtual const char* 78 | GetIntersectionCode() = 0; 79 | 80 | std::vector m_normal_data; 81 | std::vector m_vertex_data; 82 | std::vector m_triangles; // Triangles (v0, v1, v2, ID) 83 | 84 | wr_binding m_webgl_bindings[WR_MAX_BINDINGS]; 85 | int m_webgl_binding_count; 86 | int m_vertex_texture_size; 87 | int m_index_texture_size; 88 | int m_instance_texture_size; 89 | }; 90 | 91 | class SAHBVH : public ADS 92 | { 93 | 94 | public: 95 | struct Textures 96 | { 97 | unsigned int scene_vertices; // 2D array (posXYZ, UV.x) | (normXYZ, UV.y) 98 | unsigned int scene_indices; // (v0,v1,v2, ID) 99 | unsigned int 100 | bvh_nodes; // 2D (bbox_min.xyz, prim_child_offset), (bbox_max.xyz, (nPrim 101 | // (16bit), axis(8 bit), padd(8 bit))) 102 | unsigned int attributes[8]; // Attributes buffer 103 | }; 104 | 105 | struct TriangleMesh 106 | { 107 | int ID; // ShapeID 108 | int vertex_offset; 109 | int num_vertices; 110 | int triangle_offset; 111 | int num_triangles; 112 | }; 113 | 114 | std::vector m_triangle_meshes; 115 | 116 | const int maxPrimsInNode; 117 | int m_total_nodes; 118 | wr_linear_bvh_node* m_linear_nodes; 119 | 120 | int m_shape_id_generator; 121 | int m_material_id_generator; 122 | int m_node_texture_size; 123 | 124 | bool m_need_update; 125 | 126 | Textures m_webgl_textures; 127 | 128 | char* intersection_code; 129 | 130 | SAHBVH(); 131 | ~SAHBVH(); 132 | 133 | int 134 | AddTriangularMesh(float* positions, int position_stride, float* normals, 135 | int normal_stride, float* uvs, int uv_stride, 136 | int num_vertices, int* indices, 137 | int num_indices) final override; 138 | int 139 | AddSphere(float* position, float radius, int materialID) final override; 140 | 141 | bool 142 | Build() final override; 143 | 144 | const char* 145 | GetIntersectionCode() final override; 146 | const Textures 147 | GetBVHTexture() 148 | { 149 | return m_webgl_textures; 150 | } 151 | }; 152 | 153 | class LinearNodes : public ADS 154 | { 155 | 156 | public: 157 | struct Textures 158 | { 159 | unsigned int scene_vertices; // 2D array (posXYZ, UV.x) | (normXYZ, UV.y) 160 | unsigned int scene_indices; // (v0,v1,v2, ID) 161 | unsigned int attributes[8]; // Attributes buffer 162 | }; 163 | 164 | private: 165 | struct TriangleMesh 166 | { 167 | int ID; // ShapeID 168 | int vertex_offset; 169 | int num_vertices; 170 | int triangle_offset; 171 | int num_triangles; 172 | }; 173 | 174 | std::vector m_triangle_meshes; 175 | 176 | int m_shape_id_generator; 177 | int m_material_id_generator; 178 | 179 | bool m_need_update; 180 | 181 | Textures m_webgl_textures; 182 | 183 | char* intersection_code; 184 | 185 | public: 186 | LinearNodes(); 187 | ~LinearNodes(); 188 | 189 | int 190 | AddTriangularMesh(float* positions, int position_stride, float* normals, 191 | int normal_stride, float* uvs, int uv_stride, 192 | int num_vertices, int* indices, 193 | int num_indices) final override; 194 | int 195 | AddSphere(float* position, float radius, int materialID) final override; 196 | 197 | bool 198 | Build() final override; 199 | 200 | const char* 201 | GetIntersectionCode() final override; 202 | const Textures 203 | GetBVHTexture() 204 | { 205 | return m_webgl_textures; 206 | } 207 | }; 208 | 209 | struct wr_wide_bvh_node 210 | { 211 | float px; 212 | float py; 213 | float pz; 214 | char ex, ey, ez, 215 | imask; // imask stores which of the children are internal nodes 216 | unsigned int child_node_base_index; // first referenced child node 217 | unsigned int triangle_base_index; // first referenced triangle 218 | unsigned int 219 | meta[2]; // store indexing information needed to find the corresponding node 220 | // or triangle range in the corresponding array. Child nodes: 221 | // 001xxxxx = xxxxx is the child node slot index plus 24. Leaf 222 | // nodes: xxxyyyyy = xxx number of triangles (unary format), yyyyy 223 | // index of the first triangle + triangle_base_index. Empty slot: 224 | // 000000 225 | unsigned int childBBOX[12]; 226 | }; 227 | 228 | class WideBVH : public ADS 229 | { 230 | 231 | public: 232 | struct Textures 233 | { 234 | unsigned int scene_vertices; // 2D array (posXYZ, UV.x) | (normXYZ, UV.y) 235 | unsigned int scene_indices; // (v0,v1,v2, ID) 236 | unsigned int 237 | bvh_nodes; // 2D (bbox_min.xyz, prim_child_offset), (bbox_max.xyz, (nPrim 238 | // (16bit), axis(8 bit), padd(8 bit))) 239 | unsigned int attributes[8]; // Attributes buffer 240 | }; 241 | 242 | struct TriangleMesh 243 | { 244 | int ID; // ShapeID 245 | int vertex_offset; 246 | int num_vertices; 247 | int triangle_offset; 248 | int num_triangles; 249 | }; 250 | 251 | std::vector m_triangle_meshes; 252 | 253 | const int maxPrimsInNode; 254 | int m_total_nodes; 255 | wr_wide_bvh_node* m_linear_nodes; 256 | 257 | int m_shape_id_generator; 258 | int m_node_texture_size; 259 | 260 | bool m_need_update; 261 | 262 | Textures m_webgl_textures; 263 | 264 | char* intersection_code; 265 | 266 | WideBVH(); 267 | ~WideBVH(); 268 | 269 | int 270 | AddTriangularMesh(float* positions, int position_stride, float* normals, 271 | int normal_stride, float* uvs, int uv_stride, 272 | int num_vertices, int* indices, 273 | int num_indices) final override; 274 | int 275 | AddSphere(float* position, float radius, int materialID) final override; 276 | 277 | bool 278 | Build() final override; 279 | 280 | const char* 281 | GetIntersectionCode() final override; 282 | const Textures 283 | GetBVHTexture() 284 | { 285 | return m_webgl_textures; 286 | } 287 | }; 288 | 289 | #endif /* _WRAYS_ACCELERATION_DATA_STRUCTURE_H_ */ -------------------------------------------------------------------------------- /examples/web/js/example1_hello_world.js: -------------------------------------------------------------------------------- 1 | import {SimplePerspectiveCamera} from "./common/webgl_camera.js"; 2 | import * as webgl_viewer from './common/webgl_viewer.js'; 3 | import * as webrays_utils from './common/webrays_utils.js'; 4 | import * as webgl_utils from './common/webgl_utils.js'; 5 | import * as WebRays from './common/webrays.js'; 6 | 7 | var wr; 8 | var gl; 9 | var WebGLViewer; 10 | if (!WebGLViewer) WebGLViewer = (typeof WebGLViewer !== 'undefined' ? WebGLViewer : null) || {}; 11 | 12 | WebRays.OnLoad(() => { 13 | rt_main(); 14 | }); 15 | 16 | // 17 | // Main function 18 | // 19 | function rt_main() 20 | { 21 | webgl_viewer.context_init(WebGLViewer); 22 | //webgl_viewer.context_create(WebGLViewer); 23 | gl = WebGLViewer.gl; 24 | wr = webrays_utils.get_instance(gl); 25 | 26 | rt_init(); 27 | } 28 | 29 | // 30 | // Init function 31 | // 32 | function rt_init() 33 | { 34 | // Camera 35 | WebGLViewer.camera = new SimplePerspectiveCamera(WebGLViewer.canvas); 36 | 37 | // Shader 38 | WebGLViewer.rt_shader = { 39 | vertex_source: `#version 300 es 40 | precision highp float; 41 | layout(location = 0) in vec3 vertex_position; 42 | void main() { 43 | gl_Position = vec4(vertex_position, 1.0f); 44 | }`, 45 | fragment_source: `precision highp int; 46 | precision highp float; 47 | 48 | #define FLT_MAX 1.e27 49 | 50 | uniform int ads_index; 51 | uniform vec3 camera_pos, camera_up, camera_front; 52 | uniform float camera_fov; 53 | 54 | uniform ivec2 dimensions; 55 | 56 | layout(location = 0) out vec4 rt_accumulation_OUT; 57 | 58 | void main() 59 | { 60 | // A. Generate Primary Rays 61 | float sx = (gl_FragCoord.x + 0.5) / float(dimensions.x); 62 | float sy = (gl_FragCoord.y + 0.5) / float(dimensions.y); 63 | float tanFOV2 = tan(camera_fov*0.5); 64 | vec3 cx = tanFOV2 * normalize(cross(camera_front, camera_up)); 65 | vec3 cy = (tanFOV2 / (float(dimensions.x)/float(dimensions.y))) * normalize(cross(cx, camera_front)); 66 | vec3 ray_origin = camera_pos; 67 | vec3 ray_direction = normalize((2.0*sx - 1.0)*cx + (2.0*sy - 1.0)*cy + camera_front); 68 | 69 | // B. Perform Ray Intersection Tests 70 | ivec4 ray_intersection = wr_QueryIntersection(ads_index, ray_origin, ray_direction, FLT_MAX); 71 | 72 | // C. Compute Color 73 | vec3 ray_color; 74 | // C.1. Miss stage 75 | if (!wr_IsValidIntersection(ray_intersection)) { 76 | ray_color = vec3(1.0); // White background 77 | } 78 | // C.2. Hit stage 79 | else { 80 | // Visualize using the barycentric coordinates of the intersection 81 | ray_color.xy = wr_GetBaryCoords(ray_intersection); 82 | ray_color.z = 1.0 - ray_color.x - ray_color.y; 83 | } 84 | rt_accumulation_OUT = vec4(ray_color, 1.0); 85 | }`, 86 | program: null 87 | } 88 | 89 | // Mesh containg one Triangle 90 | WebGLViewer.mesh_triangle = { 91 | vertex_data: new Float32Array ([-1, -1, -1, // 1 92 | 1, -1, -1, // 2 93 | 0, 1, -1]), // 3 94 | vertex_size: 3, 95 | normal_data: new Float32Array ([0, 0, 1, // 1 96 | 0, 0, 1, // 2 97 | 0, 0, 1]), // 3 98 | normal_size: 3, 99 | uv_data: new Float32Array ([0, 0, // 1 100 | 1, 0, // 2 101 | 1, 1,]), // 3 102 | uv_size: 2, 103 | face_data: new Int32Array ([0, 1, 2, // 1 indices 104 | 0,]) // 1 info 105 | } 106 | 107 | WebGLViewer.timer = webgl_utils.create_single_buffered_timer(gl); 108 | 109 | webgl_viewer.vao_init(WebGLViewer); 110 | webgl_viewer.resize(WebGLViewer); 111 | 112 | WebGLViewer.ads_index = webrays_utils.create_blas_ads(wr); 113 | webrays_utils.add_shape(wr, WebGLViewer.ads_index, WebGLViewer.mesh_triangle); 114 | 115 | gl.disable(gl.DEPTH_TEST); 116 | gl.depthMask(false); 117 | 118 | requestAnimationFrame(rt_render); 119 | } 120 | 121 | // 122 | // Render function 123 | // 124 | function rt_render() 125 | { 126 | rt_update(); 127 | 128 | if(WebGLViewer.gl_timer_ext) 129 | webgl_utils.begin_single_buffered_timer(gl, WebGLViewer.gl_timer_ext, WebGLViewer.timer); 130 | 131 | rt_draw(); 132 | 133 | if(WebGLViewer.gl_timer_ext){ 134 | webgl_utils.end_single_buffered_timer(gl, WebGLViewer.gl_timer_ext, WebGLViewer.timer); 135 | 136 | const ellapsedTime = webgl_utils.get_single_buffered_timer(gl, WebGLViewer.gl_timer_ext, WebGLViewer.timer) / 1000000.0; // ms 137 | if(ellapsedTime !== 0.0) 138 | document.getElementById("timer").innerHTML = '[Timing: ' + ellapsedTime.toFixed(2) + ' ms]'; 139 | } 140 | 141 | webgl_viewer.fbo_blit(WebGLViewer, WebGLViewer.framebuffer.rt_fbo); 142 | 143 | requestAnimationFrame(rt_render); 144 | } 145 | 146 | // 147 | // Update function 148 | // 149 | function rt_update() 150 | { 151 | let flags = webrays_utils.update(wr); 152 | if (flags !== WebRays.UpdateFlags.NO_UPDATE) 153 | { 154 | let wr_fragment_source = webrays_utils.get_shader_source(wr); 155 | let vertex_shader = webgl_utils.compile_shader(gl, WebGLViewer.rt_shader.vertex_source, gl.VERTEX_SHADER); 156 | let fragment_source = wr_fragment_source + WebGLViewer.rt_shader.fragment_source; 157 | let fragment_shader = webgl_utils.compile_shader(gl, fragment_source, gl.FRAGMENT_SHADER); 158 | WebGLViewer.rt_shader.program = webgl_utils.create_program(gl, vertex_shader , fragment_shader); 159 | } 160 | } 161 | 162 | // 163 | // Draw function 164 | // 165 | function rt_draw() 166 | { 167 | gl.bindFramebuffer(gl.FRAMEBUFFER, WebGLViewer.framebuffer.rt_fbo); 168 | gl.viewport(0, 0, WebGLViewer.canvas.width, WebGLViewer.canvas.height); 169 | gl.drawBuffers([ gl.COLOR_ATTACHMENT0 ]); 170 | 171 | gl.useProgram(WebGLViewer.rt_shader.program); 172 | 173 | gl.uniform1i(gl.getUniformLocation(WebGLViewer.rt_shader.program, "ads_index"), 174 | WebGLViewer.ads_index); 175 | gl.uniform2iv(gl.getUniformLocation(WebGLViewer.rt_shader.program, "dimensions"), 176 | [WebGLViewer.canvas.width, WebGLViewer.canvas.height]); 177 | gl.uniform3fv(gl.getUniformLocation(WebGLViewer.rt_shader.program, "camera_pos"), 178 | WebGLViewer.camera.camera_pos); 179 | gl.uniform3fv(gl.getUniformLocation(WebGLViewer.rt_shader.program, "camera_up"), 180 | WebGLViewer.camera.camera_up); 181 | gl.uniform3fv(gl.getUniformLocation(WebGLViewer.rt_shader.program, "camera_front"), 182 | WebGLViewer.camera.camera_front); 183 | gl.uniform1f (gl.getUniformLocation(WebGLViewer.rt_shader.program, "camera_fov"), 184 | glMatrix.glMatrix.toRadian(WebGLViewer.camera.field_of_view)); 185 | 186 | let next_texture_unit = webrays_utils.set_bindings(wr, gl, WebGLViewer.rt_shader.program, 0); 187 | 188 | // Full-sceen rendering pass 189 | gl.bindVertexArray(WebGLViewer.vao); 190 | gl.drawArrays(gl.TRIANGLES, 0, 3); 191 | gl.bindVertexArray(null); 192 | 193 | while(next_texture_unit >= 0) 194 | { 195 | gl.activeTexture(gl.TEXTURE0 + next_texture_unit); 196 | gl.bindTexture(gl.TEXTURE_2D, null); 197 | gl.bindTexture(gl.TEXTURE_2D_ARRAY, null); 198 | 199 | next_texture_unit = next_texture_unit - 1; 200 | } 201 | 202 | gl.useProgram(null); 203 | } 204 | 205 | -------------------------------------------------------------------------------- /doc/API_REFERENCE_CPP.md: -------------------------------------------------------------------------------- 1 | ## WebRays C++ API Reference 2 | 3 | WebRays is primarily developed as a C++ library that exposes a low-level C API and gets compiled to WebAssembly for use on the Web. We also strive to maintain a stable C API so that WebRays can be easily used for both **web** and **native** development. 4 | 5 | | Function | Description | 6 | |:--|:--| 7 | | `wr_handle` wrays_init (
    `wr_backend_type` backend_type,
    `wr_handle` data
) | Create a webrays instance with the requested `backend_type` | 8 | | `wr_error` wrays_update (
    `wr_handle` instance,
    `wr_update_flags*` flags
) | Perform any pending updates. This function should be called after any important interaction with the WebRays API in order to submit changes. For example every time a shape is added or an instance is updated. The returned `flags` should be used by the user to determine if further updates should take place on the application side as well. | 9 | | `wr_error` wrays_create_ads (
    `wr_handle` instance,
    `wr_handle*` ads,
    `wr_ads_descriptor*` options,
    `int` options_count
) | `options` are an array `options_count` key-value pairs that control certain properties of the requested ADS. Currently the only available option is to select if the created ADS will be a `BLAS` or a `TLAS` | 10 | | `wr_error` wrays_add_shape (
    `wr_handle` instance,
    `wr_handle` ads,
    `float*` positions,
    `int` position_stride,
    `float*` normals,
    `int` normal_stride,
    `float*` uvs,
    `int` uv_stride,
    `int` num_vertices,
    `int*` indices,
    `int` num_triangles,
    `int*` shape_id
) | Vertices and Normals are defined by 3 consecutive `float`s (X, Y, Z) in their respective arrays. UVs are similarly defined by 2 `float`s (U, V). Faces are defined by 4 consecutive `int`s (X, Y, Z, W). The first 3 are the indices for each attribute. The W component is left under user control amd cam be used to store per-face information. The returned shape id represents the geometry group
defined by the provided arrays | 11 | | `wr_error` wrays_add_instance (
    `wr_handle` instance,
    `wr_handle` tlas,
    `wr_handle` blas,
    `float*` transformation,
    `int*` instance_id
) | The `transformation` matrix is expected in column-major order with the translation part being at positions 9, 10, and 11 | 12 | | `wr_error` wrays_update_instance (
    `wr_handle` instance,
    `wr_handle` tlas,
    `int` instance_id,
    `float*` transformation
) | The `instance_id` is returned ny a previous call to `wrays_add_instance`. The transformation matrix is expected in **column-major** order with the translation part being at positions 9, 10, and 11 | 13 | | `wr_error` wrays_query_intersection (
    `wr_handle` instance,
    `wr_handle` ads,
    `wr_handle*` ray_buffers,
    `wr_size` ray_buffer_count,
    `wr_handle` intersections,
    `wr_size*` dimensions,
    `wr_size` dimension_count
) | Take the ray origins and directions from the provided `ray_buffers`, intersect them with the `ads` and store the **closest-hit** results in `intersections`. | 14 | | `wr_error` wrays_query_occlusion (
    `wr_handle` instance,
    `wr_handle` ads,
    `wr_handle*` ray_buffers,
    `wr_size` ray_buffer_count,
    `wr_handle` occlusion,
    `wr_size*` dimensions,
    `wr_size` dimension_count
) | Take the ray origins and directions from the provided `ray_buffers`, intersect them with the `ads` and store the binary **occlusion** results in `occlusion` | 15 | | `wr_error` wrays_ray_buffer_requirements (
    `wr_handle` instance,
    `wr_buffer_info*` buffer_info,
    `wr_size*` dimensions,
    `wr_size` dimensions_count
) | Request the requirements for a ray buffer of dimensionality `dimensions_count` and size `dimensions`. The `buffer_info` struct will be filled with the appropriate information. For example a 2D ray buffer will naturally be backed by a 2D RGBA32F texture. The actual allocation of the buffers is left to the application for finer control. The WebGL backend currently only supports 2D ray buffers. | 16 | | `wr_error` wrays_intersection_buffer_requirements (
    `wr_handle` instance,
    `wr_buffer_info*` buffer_info,
    `wr_size*` dimensions,
    `wr_size` dimensions_count
) | Request the requirements for an intersection buffer of dimensionality `dimensions_count` and size `dimensions` that will receive **closest-hit** results. The `buffer_info` struct will be filled with the appropriate information. For example a 2D intersection buffer will naturally be backed by a 2D RGBA32I texture. The actual allocation of the buffers is left to the application for finer control. The WebGL backend currently only supports 2D intersection buffers. | 17 | | `wr_error` wrays_occlusion_buffer_requirements (
    `wr_handle` instance,
    `wr_buffer_info*` buffer_info,
    `wr_size*` dimensions,
    `wr_size` dimensions_count
) | Request the requirements for an occlusion buffer of dimensionality `dimensions_count` and size `dimensions` that will receive **occlusion** results. The `buffer_info` struct will be filled with the appropriate information. For example a 2D occlusion buffer will naturally be backed by a 2D R32I texture. The actual allocation of the buffers is left to the application for finer control. The WebGL backend currently only supports 2D occlusion buffers. | 18 | | `const char *` wrays_get_scene_accessor (
    `wr_handle` instance
) | Returns a string representation of the accessor code. For example, in the WebGL implementation, this includes the GLSL API that can be used for in-shader intersections. `wrays_update` indicates when this code has changed and users should make sure to always use the latest in-shader API in their shaders. In WebGL this API simply needs to get prepended to the user's code. | 19 | | `const wr_binding *` wrays_get_scene_accessor_bindings (
    `wr_handle` instance
) | Get the bindings for the data structures. For example, in the WebGL implementation, these include the textures, buffers e.t.c. that are required for the GLSL API to function within a user's shader. `wrays_update` indicates when these bindings have changed and users should make sure to use the latest bindings in their applciation | 20 | | `const char *` wrays_error_string (
    `wr_handle` instance,
    `wr_error` error
) | Returns a human-friendly error message for the provided error. | 21 | | `wr_error` wrays_destroy (
    `wr_handle` instance
) | Destroy a previously created webrays instance | 22 | | `wr_error` wrays_ads_destroy (
    `wr_handle` instance,
    `wr_handle` ads
) | Destroy a previously created ads. | 23 | | `wr_error` wrays_ray_buffer_destroy (
    `wr_handle` instance,
    `wr_handle` buffer
) | Destroy a previously created ray buffer. Since WebRays gives complete memory control to the user regarding buffers, this routines does nothing in most cases | 24 | | `wr_error` wrays_intersection_buffer_destroy (
    `wr_handle` instance,
    `wr_handle` buffer
) | Destroy a previously created intersection buffer. Since WebRays gives complete memory control to the user regarding buffers, this routines does nothing in most cases | 25 | | `wr_error` wrays_occlusion_buffer_destroy (
    `wr_handle` instance,
    `wr_handle` buffer
) | Destroy a previously created occlusion buffer. Since WebRays gives complete memory control to the user regarding buffers, this routines does nothing in most cases | 26 | -------------------------------------------------------------------------------- /deps/include/CL/cl_dx9_media_sharing.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2020 The Khronos Group Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H 18 | #define __OPENCL_CL_DX9_MEDIA_SHARING_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /******************************************************************************/ 28 | /* cl_khr_dx9_media_sharing */ 29 | #define cl_khr_dx9_media_sharing 1 30 | 31 | typedef cl_uint cl_dx9_media_adapter_type_khr; 32 | typedef cl_uint cl_dx9_media_adapter_set_khr; 33 | 34 | #if defined(_WIN32) 35 | #include 36 | typedef struct _cl_dx9_surface_info_khr 37 | { 38 | IDirect3DSurface9 *resource; 39 | HANDLE shared_handle; 40 | } cl_dx9_surface_info_khr; 41 | #endif 42 | 43 | 44 | /******************************************************************************/ 45 | 46 | /* Error Codes */ 47 | #define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 48 | #define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 49 | #define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 50 | #define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 51 | 52 | /* cl_media_adapter_type_khr */ 53 | #define CL_ADAPTER_D3D9_KHR 0x2020 54 | #define CL_ADAPTER_D3D9EX_KHR 0x2021 55 | #define CL_ADAPTER_DXVA_KHR 0x2022 56 | 57 | /* cl_media_adapter_set_khr */ 58 | #define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 59 | #define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 60 | 61 | /* cl_context_info */ 62 | #define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 63 | #define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 64 | #define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 65 | 66 | /* cl_mem_info */ 67 | #define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 68 | #define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 69 | 70 | /* cl_image_info */ 71 | #define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A 72 | 73 | /* cl_command_type */ 74 | #define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B 75 | #define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C 76 | 77 | /******************************************************************************/ 78 | 79 | typedef cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( 80 | cl_platform_id platform, 81 | cl_uint num_media_adapters, 82 | cl_dx9_media_adapter_type_khr * media_adapter_type, 83 | void * media_adapters, 84 | cl_dx9_media_adapter_set_khr media_adapter_set, 85 | cl_uint num_entries, 86 | cl_device_id * devices, 87 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; 88 | 89 | typedef cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( 90 | cl_context context, 91 | cl_mem_flags flags, 92 | cl_dx9_media_adapter_type_khr adapter_type, 93 | void * surface_info, 94 | cl_uint plane, 95 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 96 | 97 | typedef cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( 98 | cl_command_queue command_queue, 99 | cl_uint num_objects, 100 | const cl_mem * mem_objects, 101 | cl_uint num_events_in_wait_list, 102 | const cl_event * event_wait_list, 103 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 104 | 105 | typedef cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( 106 | cl_command_queue command_queue, 107 | cl_uint num_objects, 108 | const cl_mem * mem_objects, 109 | cl_uint num_events_in_wait_list, 110 | const cl_event * event_wait_list, 111 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 112 | 113 | /*************************************** 114 | * cl_intel_dx9_media_sharing extension * 115 | ****************************************/ 116 | 117 | #define cl_intel_dx9_media_sharing 1 118 | 119 | typedef cl_uint cl_dx9_device_source_intel; 120 | typedef cl_uint cl_dx9_device_set_intel; 121 | 122 | /* error codes */ 123 | #define CL_INVALID_DX9_DEVICE_INTEL -1010 124 | #define CL_INVALID_DX9_RESOURCE_INTEL -1011 125 | #define CL_DX9_RESOURCE_ALREADY_ACQUIRED_INTEL -1012 126 | #define CL_DX9_RESOURCE_NOT_ACQUIRED_INTEL -1013 127 | 128 | /* cl_dx9_device_source_intel */ 129 | #define CL_D3D9_DEVICE_INTEL 0x4022 130 | #define CL_D3D9EX_DEVICE_INTEL 0x4070 131 | #define CL_DXVA_DEVICE_INTEL 0x4071 132 | 133 | /* cl_dx9_device_set_intel */ 134 | #define CL_PREFERRED_DEVICES_FOR_DX9_INTEL 0x4024 135 | #define CL_ALL_DEVICES_FOR_DX9_INTEL 0x4025 136 | 137 | /* cl_context_info */ 138 | #define CL_CONTEXT_D3D9_DEVICE_INTEL 0x4026 139 | #define CL_CONTEXT_D3D9EX_DEVICE_INTEL 0x4072 140 | #define CL_CONTEXT_DXVA_DEVICE_INTEL 0x4073 141 | 142 | /* cl_mem_info */ 143 | #define CL_MEM_DX9_RESOURCE_INTEL 0x4027 144 | #define CL_MEM_DX9_SHARED_HANDLE_INTEL 0x4074 145 | 146 | /* cl_image_info */ 147 | #define CL_IMAGE_DX9_PLANE_INTEL 0x4075 148 | 149 | /* cl_command_type */ 150 | #define CL_COMMAND_ACQUIRE_DX9_OBJECTS_INTEL 0x402A 151 | #define CL_COMMAND_RELEASE_DX9_OBJECTS_INTEL 0x402B 152 | /******************************************************************************/ 153 | 154 | extern CL_API_ENTRY cl_int CL_API_CALL 155 | clGetDeviceIDsFromDX9INTEL( 156 | cl_platform_id platform, 157 | cl_dx9_device_source_intel dx9_device_source, 158 | void* dx9_object, 159 | cl_dx9_device_set_intel dx9_device_set, 160 | cl_uint num_entries, 161 | cl_device_id* devices, 162 | cl_uint* num_devices) CL_API_SUFFIX__VERSION_1_1; 163 | 164 | typedef cl_int (CL_API_CALL* clGetDeviceIDsFromDX9INTEL_fn)( 165 | cl_platform_id platform, 166 | cl_dx9_device_source_intel dx9_device_source, 167 | void* dx9_object, 168 | cl_dx9_device_set_intel dx9_device_set, 169 | cl_uint num_entries, 170 | cl_device_id* devices, 171 | cl_uint* num_devices) CL_API_SUFFIX__VERSION_1_1; 172 | 173 | extern CL_API_ENTRY cl_mem CL_API_CALL 174 | clCreateFromDX9MediaSurfaceINTEL( 175 | cl_context context, 176 | cl_mem_flags flags, 177 | IDirect3DSurface9* resource, 178 | HANDLE sharedHandle, 179 | UINT plane, 180 | cl_int* errcode_ret) CL_API_SUFFIX__VERSION_1_1; 181 | 182 | typedef cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceINTEL_fn)( 183 | cl_context context, 184 | cl_mem_flags flags, 185 | IDirect3DSurface9* resource, 186 | HANDLE sharedHandle, 187 | UINT plane, 188 | cl_int* errcode_ret) CL_API_SUFFIX__VERSION_1_1; 189 | 190 | extern CL_API_ENTRY cl_int CL_API_CALL 191 | clEnqueueAcquireDX9ObjectsINTEL( 192 | cl_command_queue command_queue, 193 | cl_uint num_objects, 194 | const cl_mem* mem_objects, 195 | cl_uint num_events_in_wait_list, 196 | const cl_event* event_wait_list, 197 | cl_event* event) CL_API_SUFFIX__VERSION_1_1; 198 | 199 | typedef cl_int (CL_API_CALL *clEnqueueAcquireDX9ObjectsINTEL_fn)( 200 | cl_command_queue command_queue, 201 | cl_uint num_objects, 202 | const cl_mem* mem_objects, 203 | cl_uint num_events_in_wait_list, 204 | const cl_event* event_wait_list, 205 | cl_event* event) CL_API_SUFFIX__VERSION_1_1; 206 | 207 | extern CL_API_ENTRY cl_int CL_API_CALL 208 | clEnqueueReleaseDX9ObjectsINTEL( 209 | cl_command_queue command_queue, 210 | cl_uint num_objects, 211 | cl_mem* mem_objects, 212 | cl_uint num_events_in_wait_list, 213 | const cl_event* event_wait_list, 214 | cl_event* event) CL_API_SUFFIX__VERSION_1_1; 215 | 216 | typedef cl_int (CL_API_CALL *clEnqueueReleaseDX9ObjectsINTEL_fn)( 217 | cl_command_queue command_queue, 218 | cl_uint num_objects, 219 | cl_mem* mem_objects, 220 | cl_uint num_events_in_wait_list, 221 | const cl_event* event_wait_list, 222 | cl_event* event) CL_API_SUFFIX__VERSION_1_1; 223 | 224 | #ifdef __cplusplus 225 | } 226 | #endif 227 | 228 | #endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ 229 | 230 | --------------------------------------------------------------------------------