Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff356216d5 | ||
|
|
6fd87cdfef | ||
|
|
8ba001d0ca | ||
|
|
6fd031c611 | ||
|
|
b0e90c48a2 | ||
|
|
149acf4213 | ||
|
|
9b356926b8 | ||
|
|
7179ab5b9d | ||
|
|
0a6bbdb35c | ||
|
|
29919e64cd | ||
|
|
a7660e40f8 | ||
|
|
22e1f9b930 | ||
|
|
e205611128 |
@@ -49,6 +49,8 @@ option(FILAMENT_SUPPORTS_OSMESA "Enable OSMesa (headless GL context) for Filamen
|
|||||||
|
|
||||||
option(FILAMENT_ENABLE_FGVIEWER "Enable the frame graph viewer" OFF)
|
option(FILAMENT_ENABLE_FGVIEWER "Enable the frame graph viewer" OFF)
|
||||||
|
|
||||||
|
option(FILAMENT_ENABLE_INIT_GL_WARNINGS_FOR_OPTIMIZED_BUILD "Enable GL error warnings during init in optimized builds" OFF)
|
||||||
|
|
||||||
set(FILAMENT_NDK_VERSION "" CACHE STRING
|
set(FILAMENT_NDK_VERSION "" CACHE STRING
|
||||||
"Android NDK version or version prefix to be used when building for Android."
|
"Android NDK version or version prefix to be used when building for Android."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.android.filament:filament-android:1.59.3'
|
implementation 'com.google.android.filament:filament-android:1.59.4'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
|
|||||||
iOS projects can use CocoaPods to install the latest release:
|
iOS projects can use CocoaPods to install the latest release:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
pod 'Filament', '~> 1.59.3'
|
pod 'Filament', '~> 1.59.4'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ A new header is inserted each time a *tag* is created.
|
|||||||
Instead, if you are authoring a PR for the main branch, add your release note to
|
Instead, if you are authoring a PR for the main branch, add your release note to
|
||||||
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
|
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
|
||||||
|
|
||||||
|
## v1.59.5
|
||||||
|
|
||||||
|
|
||||||
## v1.59.4
|
## v1.59.4
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1980,7 +1980,7 @@ public class View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reconstruction filter width typically between 0.2 (sharper, aliased) and 1.5 (smoother)
|
* reconstruction filter width typically between 1 (sharper) and 2 (smoother)
|
||||||
*/
|
*/
|
||||||
public float filterWidth = 1.0f;
|
public float filterWidth = 1.0f;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
GROUP=com.google.android.filament
|
GROUP=com.google.android.filament
|
||||||
VERSION_NAME=1.59.3
|
VERSION_NAME=1.59.4
|
||||||
|
|
||||||
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
|
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
|
||||||
|
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+36
-19
@@ -166,7 +166,7 @@ This document is part of the <a href="https://github.com/google/filament">Filame
|
|||||||
</p><ul>
|
</p><ul>
|
||||||
<li class="minus"><a href="https://github.com/romainguy">Romain Guy</a>, <a href="https://twitter.com/romainguy">@romainguy</a>
|
<li class="minus"><a href="https://github.com/romainguy">Romain Guy</a>, <a href="https://twitter.com/romainguy">@romainguy</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="minus"><a href="https://github.com/pixelflinger">Mathias Agopian</a>, <a href="https://twitter.com/darthmoosious">@darthmoosious</a></li></ul>
|
<li class="minus"><a href="https://github.com/pixelflinger">Mathias Agopian</a>, <a href="https://bsky.app/profile/pixelflinger.bsky.social">@pixelflinger</a></li></ul>
|
||||||
|
|
||||||
<p></p>
|
<p></p>
|
||||||
<a class="target" name="overview"> </a><a class="target" name="overview"> </a><a class="target" name="toc2"> </a><h1>Overview</h1>
|
<a class="target" name="overview"> </a><a class="target" name="overview"> </a><a class="target" name="toc2"> </a><h1>Overview</h1>
|
||||||
@@ -259,26 +259,27 @@ in <a href="#table_standardproperties">table 1</a>.
|
|||||||
</p><div class="table">
|
</p><div class="table">
|
||||||
<table class="table"><tbody><tr><th style="text-align:right"> Property </th><th style="text-align:left"> Definition </th></tr>
|
<table class="table"><tbody><tr><th style="text-align:right"> Property </th><th style="text-align:left"> Definition </th></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">baseColor</strong> </td><td style="text-align:left"> Diffuse albedo for non-metallic surfaces, and specular color for metallic surfaces </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">baseColor</strong> </td><td style="text-align:left"> Diffuse albedo for non-metallic surfaces, and specular color for metallic surfaces </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">metallic</strong> </td><td style="text-align:left"> Whether a surface appears to be dielectric (0.0) or conductor (1.0). Often used as a binary value (0 or 1) </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">roughness</strong> </td><td style="text-align:left"> Perceived smoothness (1.0) or roughness (0.0) of a surface. Smooth surfaces exhibit sharp reflections </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">roughness</strong> </td><td style="text-align:left"> Perceived smoothness (1.0) or roughness (0.0) of a surface. Smooth surfaces exhibit sharp reflections </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">metallic</strong> </td><td style="text-align:left"> Whether a surface appears to be dielectric (0.0) or conductor (1.0). Often used as a binary value (0 or 1) </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">reflectance</strong> </td><td style="text-align:left"> Fresnel reflectance at normal incidence for dielectric surfaces. This directly controls the strength of the reflections </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">reflectance</strong> </td><td style="text-align:left"> Fresnel reflectance at normal incidence for dielectric surfaces. This directly controls the strength of the reflections </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">sheenColor</strong> </td><td style="text-align:left"> Strength of the sheen layer </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">ambientOcclusion</strong> </td><td style="text-align:left"> Defines how much of the ambient light is accessible to a surface point. It is a per-pixel shadowing factor between 0.0 and 1.0 </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">sheenRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the sheen layer </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">clearCoat</strong> </td><td style="text-align:left"> Strength of the clear coat layer </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">clearCoat</strong> </td><td style="text-align:left"> Strength of the clear coat layer </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the clear coat layer </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the clear coat layer </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatNormal</strong> </td><td style="text-align:left"> A detail normal used to perturb the clear coat layer using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">anisotropy</strong> </td><td style="text-align:left"> Amount of anisotropy in either the tangent or bitangent direction </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">anisotropy</strong> </td><td style="text-align:left"> Amount of anisotropy in either the tangent or bitangent direction </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">anisotropyDirection</strong> </td><td style="text-align:left"> Local surface direction in tangent space </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">anisotropyDirection</strong> </td><td style="text-align:left"> Local surface direction in tangent space </td></tr>
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">ambientOcclusion</strong> </td><td style="text-align:left"> Defines how much of the ambient light is accessible to a surface point. It is a per-pixel shadowing factor between 0.0 and 1.0 </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">normal</strong> </td><td style="text-align:left"> A detail normal used to perturb the surface using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">bentNormal</strong> </td><td style="text-align:left"> A normal pointing in the average unoccluded direction. Can be used to improve indirect lighting quality </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">clearCoatNormal</strong> </td><td style="text-align:left"> A detail normal used to perturb the clear coat layer using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">emissive</strong> </td><td style="text-align:left"> Additional diffuse albedo to simulate emissive surfaces (such as neons, etc.) This property is mostly useful in an HDR pipeline with a bloom pass </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">postLightingColor</strong> </td><td style="text-align:left"> Additional color that can be blended with the result of the lighting computations. See <code>postLightingBlending</code> </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">ior</strong> </td><td style="text-align:left"> Index of refraction, either for refractive objects or as an alternative to reflectance </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">transmission</strong> </td><td style="text-align:left"> Defines how much of the diffuse light of a dielectric is transmitted through the object, in other words this defines how transparent an object is </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">absorption</strong> </td><td style="text-align:left"> Absorption factor for refractive objects </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">microThickness</strong> </td><td style="text-align:left"> Thickness of the thin layer of refractive objects </td></tr>
|
|
||||||
<tr><td style="text-align:right"> <strong class="asterisk">thickness</strong> </td><td style="text-align:left"> Thickness of the solid volume of refractive objects </td></tr>
|
<tr><td style="text-align:right"> <strong class="asterisk">thickness</strong> </td><td style="text-align:left"> Thickness of the solid volume of refractive objects </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">sheenColor</strong> </td><td style="text-align:left"> Strength of the sheen layer </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">sheenRoughness</strong> </td><td style="text-align:left"> Perceived smoothness or roughness of the sheen layer </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">emissive</strong> </td><td style="text-align:left"> Additional diffuse albedo to simulate emissive surfaces (such as neons, etc.) This property is mostly useful in an HDR pipeline with a bloom pass </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">normal</strong> </td><td style="text-align:left"> A detail normal used to perturb the surface using <em class="underscore">bump mapping</em> (<em class="underscore">normal mapping</em>) </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">postLightingColor</strong> </td><td style="text-align:left"> Additional color that can be blended with the result of the lighting computations. See <code>postLightingBlending</code> </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">absorption</strong> </td><td style="text-align:left"> Absorption factor for refractive objects </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">transmission</strong> </td><td style="text-align:left"> Defines how much of the diffuse light of a dielectric is transmitted through the object, in other words this defines how transparent an object is </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">ior</strong> </td><td style="text-align:left"> Index of refraction, either for refractive objects or as an alternative to reflectance </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">microThickness</strong> </td><td style="text-align:left"> Thickness of the thin layer of refractive objects </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">bentNormal</strong> </td><td style="text-align:left"> A normal pointing in the average unoccluded direction. Can be used to improve indirect lighting quality </td></tr>
|
||||||
|
<tr><td style="text-align:right"> <strong class="asterisk">shadowStrength</strong> </td><td style="text-align:left"> Strength factor between 0 and 1 for all shadows received by this material </td></tr>
|
||||||
</tbody></table><center><div class="tablecaption"><a class="target" name="table_standardproperties"> </a><b style="font-style:normal;">Table 1:</b> Properties of the standard model</div></center></div>
|
</tbody></table><center><div class="tablecaption"><a class="target" name="table_standardproperties"> </a><b style="font-style:normal;">Table 1:</b> Properties of the standard model</div></center></div>
|
||||||
|
|
||||||
<p></p><p>
|
<p></p><p>
|
||||||
@@ -1486,10 +1487,13 @@ non-shader data.
|
|||||||
</p><dl><dt>Type</dt><dd><p> array of parameter objects
|
</p><dl><dt>Type</dt><dd><p> array of parameter objects
|
||||||
|
|
||||||
</p></dd><dt>Value</dt><dd><p> Each entry is an object with the properties <code>name</code> and <code>type</code>, both of <code>string</code> type. The
|
</p></dd><dt>Value</dt><dd><p> Each entry is an object with the properties <code>name</code> and <code>type</code>, both of <code>string</code> type. The
|
||||||
name must be a valid GLSL identifier. Entries also have an optional <code>precision</code>, which can be
|
name must be a valid GLSL identifier. Entries have an optional <code>precision</code>, which can be
|
||||||
one of <code>default</code> (best precision for the platform, typically <code>high</code> on desktop, <code>medium</code> on
|
one of <code>default</code> (best precision for the platform, typically <code>high</code> on desktop, <code>medium</code> on
|
||||||
mobile), <code>low</code>, <code>medium</code>, <code>high</code>. The type must be one of the types described in
|
mobile), <code>low</code>, <code>medium</code>, <code>high</code>. The type must be one of the types described in
|
||||||
<a href="#table_materialparamstypes">table 14</a>.
|
<a href="#table_materialparamstypes">table 14</a>. For Android external textures, entries also have an optional
|
||||||
|
transformName parameter to specify the name of the material parameter that will be
|
||||||
|
used to expose the transform matrix associated with the external sampler. In iOS and Vulkan,
|
||||||
|
this will always be identity.
|
||||||
|
|
||||||
</p></dd></dl><div class="table">
|
</p></dd></dl><div class="table">
|
||||||
<table class="table"><tbody><tr><th style="text-align:left"> Type </th><th style="text-align:left"> Description </th></tr>
|
<table class="table"><tbody><tr><th style="text-align:left"> Type </th><th style="text-align:left"> Description </th></tr>
|
||||||
@@ -1752,7 +1756,13 @@ non-shader data.
|
|||||||
when selecting any shading model that is not <code>unlit</code>. See the shader sections of this document
|
when selecting any shading model that is not <code>unlit</code>. See the shader sections of this document
|
||||||
for more information on how to access these attributes from the shaders.
|
for more information on how to access these attributes from the shaders.
|
||||||
|
|
||||||
</p></dd></dl><p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
</p></dd></dl><div class="admonition note"><div class="admonition-title"> Interaction with custom variables</div>
|
||||||
|
|
||||||
|
<p></p><p>
|
||||||
|
|
||||||
|
When the <code>color</code> attribute is specified, only four custom variables are available instead of five.</p></div>
|
||||||
|
|
||||||
|
<p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
||||||
<span class="line"> parameters : [</span>
|
<span class="line"> parameters : [</span>
|
||||||
<span class="line"> {</span>
|
<span class="line"> {</span>
|
||||||
<span class="line"> type : sampler2d,</span>
|
<span class="line"> type : sampler2d,</span>
|
||||||
@@ -1779,7 +1789,7 @@ non-shader data.
|
|||||||
|
|
||||||
</p><dl><dt>Type</dt><dd><p> array of <code>string</code>
|
</p><dl><dt>Type</dt><dd><p> array of <code>string</code>
|
||||||
|
|
||||||
</p></dd><dt>Value</dt><dd><p> Up to 4 strings, each must be a valid GLSL identifier.
|
</p></dd><dt>Value</dt><dd><p> Up to 5 strings, each must be a valid GLSL identifier.
|
||||||
|
|
||||||
</p></dd><dt>Description</dt><dd><p> Defines custom interpolants (or variables) that are output by the material's vertex shader.
|
</p></dd><dt>Description</dt><dd><p> Defines custom interpolants (or variables) that are output by the material's vertex shader.
|
||||||
Each entry of the array defines the name of an interpolant. The full name in the fragment
|
Each entry of the array defines the name of an interpolant. The full name in the fragment
|
||||||
@@ -1794,7 +1804,14 @@ non-shader data.
|
|||||||
particular if <code>default</code> is specified the default precision is used is the fragment shader
|
particular if <code>default</code> is specified the default precision is used is the fragment shader
|
||||||
(<code>mediump</code>) and in the vertex shader (<code>highp</code>).
|
(<code>mediump</code>) and in the vertex shader (<code>highp</code>).
|
||||||
|
|
||||||
</p></dd></dl><p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
</p></dd></dl><div class="admonition warning"><div class="admonition-title"> Interaction with required attributes</div>
|
||||||
|
|
||||||
|
<p></p><p>
|
||||||
|
|
||||||
|
If the <code>color</code> attribute is specified in the <code>required</code> list, then only four variables can be used
|
||||||
|
instead of five.</p></div>
|
||||||
|
|
||||||
|
<p></p><pre class="listing tilde"><code><span class="line">material {</span>
|
||||||
<span class="line"> name : Skybox,</span>
|
<span class="line"> name : Skybox,</span>
|
||||||
<span class="line"> parameters : [</span>
|
<span class="line"> parameters : [</span>
|
||||||
<span class="line"> {</span>
|
<span class="line"> {</span>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16
-16
@@ -49,7 +49,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#EntityManager">EntityManager</a></td>
|
<td align="left"><a href="#EntityManager">EntityManager</a></td>
|
||||||
<td align="left">Singleton used for constructing entities in Filament's ECS.</td>
|
<td align="left">Singleton used for constructing entities in Filament's ECS.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Frustum">Frustum</a></td>
|
<td align="left"><a href="#Frustum">Frustum</a></td>
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Renderer">Renderer</a></td>
|
<td align="left"><a href="#Renderer">Renderer</a></td>
|
||||||
<td align="left">Represents the platform's native window.</td>
|
<td align="left">Represents the platform's native window.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Scene">Scene</a></td>
|
<td align="left"><a href="#Scene">Scene</a></td>
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#SwapChain">SwapChain</a></td>
|
<td align="left"><a href="#SwapChain">SwapChain</a></td>
|
||||||
<td align="left">Represents the platform's native rendering surface.</td>
|
<td align="left">Represents the platform's native rendering surface.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left"><a href="#Texture">Texture</a></td>
|
<td align="left"><a href="#Texture">Texture</a></td>
|
||||||
@@ -604,11 +604,11 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<p>To create an entity with no components, use <a href="#EntityManager">EntityManager</a>.
|
<p>To create an entity with no components, use <a href="#EntityManager">EntityManager</a>.
|
||||||
TODO: It would be better to expose these as JS numbers rather than as JS objects.
|
TODO: It would be better to expose these as JS numbers rather than as JS objects.
|
||||||
This would also be more consistent with Filament's Java bindings.</p>
|
This would also be more consistent with Filament's Java bindings.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='EntityManager' href='#EntityManager'>EntityManager</a></h2>
|
<h2>class <a id='EntityManager' href='#EntityManager'>EntityManager</a></h2>
|
||||||
<p>Singleton used for constructing entities in Filament's ECS.</p>
|
<p>Singleton used for constructing entities in Filament's ECS.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>entityManager.create()</strong>
|
<li><strong>entityManager.create()</strong>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -742,7 +742,7 @@ properties.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='PixelBufferDescriptor' href='#PixelBufferDescriptor'>PixelBufferDescriptor</a></h2>
|
<h2>class <a id='PixelBufferDescriptor' href='#PixelBufferDescriptor'>PixelBufferDescriptor</a></h2>
|
||||||
@@ -780,11 +780,11 @@ properties.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='Renderer' href='#Renderer'>Renderer</a></h2>
|
<h2>class <a id='Renderer' href='#Renderer'>Renderer</a></h2>
|
||||||
<p>Represents the platform's native window.</p>
|
<p>Represents the platform's native window.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>renderer.render(swapChain, view)</strong>
|
<li><strong>renderer.render(swapChain, view)</strong>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -803,7 +803,7 @@ properties.</p>
|
|||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='SwapChain' href='#SwapChain'>SwapChain</a></h2>
|
<h2>class <a id='SwapChain' href='#SwapChain'>SwapChain</a></h2>
|
||||||
<p>Represents the platform's native rendering surface.</p>
|
<p>Represents the platform's native rendering surface.</p>
|
||||||
<p>See also the <a href="#Engine">Engine</a> methods <code>createSwapChain</code> and <code>destroySwapChain</code>.</p>
|
<p>See also the <a href="#Engine">Engine</a> methods <code>createSwapChain</code> and <code>destroySwapChain</code>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
@@ -847,7 +847,7 @@ properties.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
<p>Be sure to call the instance's <code>delete</code> method when you're done with it.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='classdoc'>
|
<div class='classdoc'>
|
||||||
<h2>class <a id='VertexBuffer' href='#VertexBuffer'>VertexBuffer</a></h2>
|
<h2>class <a id='VertexBuffer' href='#VertexBuffer'>VertexBuffer</a></h2>
|
||||||
@@ -944,7 +944,7 @@ See also the <a href="#Engine">Engine</a> methods <code>createView</code> and <c
|
|||||||
<ul>
|
<ul>
|
||||||
<li><strong>assets</strong>
|
<li><strong>assets</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Array of strings containing URL's of required assets.</li>
|
<li>Array of strings containing URL's of required assets.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><strong>onDone</strong>
|
<li><strong>onDone</strong>
|
||||||
@@ -954,7 +954,7 @@ See also the <a href="#Engine">Engine</a> methods <code>createView</code> and <c
|
|||||||
</li>
|
</li>
|
||||||
<li><strong>onFetched</strong>
|
<li><strong>onFetched</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>optional callback that's invoked after each asset is downloaded.</li>
|
<li>optional callback that's invoked after each asset is downloaded.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -1001,7 +1001,7 @@ useful for compressed textures. For example, some platforms accept ETC and other
|
|||||||
<ul>
|
<ul>
|
||||||
<li><strong>assets</strong>
|
<li><strong>assets</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Array of strings containing URL's of required assets.</li>
|
<li>Array of strings containing URL's of required assets.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><strong>onready</strong>
|
<li><strong>onready</strong>
|
||||||
@@ -1010,12 +1010,12 @@ useful for compressed textures. For example, some platforms accept ETC and other
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>All JavaScript clients must call the init function, passing in a list of asset URL's and a
|
<p>All JavaScript clients must call the init function, passing in a list of asset URL's and a
|
||||||
callback. This callback gets invoked only after all assets have been downloaded and the Filament
|
callback. This callback gets invoked only after all assets have been downloaded and the Filament
|
||||||
WebAssembly module has been loaded. Clients should only pass asset URL's that absolutely must
|
WebAssembly module has been loaded. Clients should only pass asset URL's that absolutely must
|
||||||
be ready at initialization time.
|
be ready at initialization time.
|
||||||
When the callback is called, each downloaded asset is available in the <code>Filament.assets</code> global
|
When the callback is called, each downloaded asset is available in the <code>Filament.assets</code> global
|
||||||
object, which contains a mapping from URL's to Uint8Array objects.</p>
|
object, which contains a mapping from URL's to Uint8Array objects.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class='funcdoc'>
|
<div class='funcdoc'>
|
||||||
<h2>function <a id='loadMathExtensions' href='#loadMathExtensions'>loadMathExtensions</a>()</h2>
|
<h2>function <a id='loadMathExtensions' href='#loadMathExtensions'>loadMathExtensions</a>()</h2>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+157
-157
@@ -10,7 +10,7 @@
|
|||||||
textures.</p>
|
textures.</p>
|
||||||
<p>For starters, create a text file called <code>redball.html</code> and copy over the HTML that we used in the
|
<p>For starters, create a text file called <code>redball.html</code> and copy over the HTML that we used in the
|
||||||
<a href="tutorial_triangle.html">previous tutorial</a>. Change the last script tag from <code>triangle.js</code> to <code>redball.js</code>.</p>
|
<a href="tutorial_triangle.html">previous tutorial</a>. Change the last script tag from <code>triangle.js</code> to <code>redball.js</code>.</p>
|
||||||
<p>Next you'll need to get a couple command-line tools: <code>matc</code> and <code>cmgen</code>. You can find these in the
|
<p>Next you'll need to get a couple command-line tools: <code>matc</code> and <code>cmgen</code>. You can find these in the
|
||||||
appropriate <a href="//github.com/google/filament/releases">Filament release</a>. You should choose the
|
appropriate <a href="//github.com/google/filament/releases">Filament release</a>. You should choose the
|
||||||
archive that corresponds to your development machine rather than the one for web, and the version
|
archive that corresponds to your development machine rather than the one for web, and the version
|
||||||
that matches the <code>unpkg.com/filament@x.x.x</code> url in the script tag of <code>redball.html</code> (you may check
|
that matches the <code>unpkg.com/filament@x.x.x</code> url in the script tag of <code>redball.html</code> (you may check
|
||||||
@@ -19,7 +19,7 @@ out the last available release of <a href="https://www.npmjs.com/package/filamen
|
|||||||
<p>The <code>matc</code> tool consumes a text file containing a high-level description of a PBR material, and
|
<p>The <code>matc</code> tool consumes a text file containing a high-level description of a PBR material, and
|
||||||
produces a binary material package that contains shader code and associated metadata. For more
|
produces a binary material package that contains shader code and associated metadata. For more
|
||||||
information, see the official document describing the <a href="https://google.github.io/filament/Materials.md.html">Filament Material System</a>.</p>
|
information, see the official document describing the <a href="https://google.github.io/filament/Materials.md.html">Filament Material System</a>.</p>
|
||||||
<p>Let's try out <code>matc</code>. Create the following file in your favorite text editor and call it
|
<p>Let's try out <code>matc</code>. Create the following file in your favorite text editor and call it
|
||||||
<code>plastic.mat</code>.</p>
|
<code>plastic.mat</code>.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
||||||
name : Lit,
|
name : Lit,
|
||||||
@@ -44,16 +44,16 @@ fragment {
|
|||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next, invoke <code>matc</code> as follows.</p>
|
<p>Next, invoke <code>matc</code> as follows.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc -a opengl -p mobile -o plastic.filamat plastic.mat
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc<span style="color: #BBB"> </span>-a<span style="color: #BBB"> </span>opengl<span style="color: #BBB"> </span>-p<span style="color: #BBB"> </span>mobile<span style="color: #BBB"> </span>-o<span style="color: #BBB"> </span>plastic.filamat<span style="color: #BBB"> </span>plastic.mat
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a material archive in your working directory, which we'll use later in the
|
<p>You should now have a material archive in your working directory, which we'll use later in the
|
||||||
tutorial.</p>
|
tutorial.</p>
|
||||||
<h2>Bake environment map</h2>
|
<h2>Bake environment map</h2>
|
||||||
<p>Next we'll use Filament's <code>cmgen</code> tool to consume a HDR environment map in latlong format, and
|
<p>Next we'll use Filament's <code>cmgen</code> tool to consume a HDR environment map in latlong format, and
|
||||||
produce two cubemap files: a mipmapped IBL and a blurry skybox.</p>
|
produce two cubemap files: a mipmapped IBL and a blurry skybox.</p>
|
||||||
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/pillars_2k.hdr">pillars_2k.hdr</a>, then invoke the following command in your terminal.</p>
|
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/pillars_2k.hdr">pillars_2k.hdr</a>, then invoke the following command in your terminal.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen -x pillars_2k --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 pillars_2k.hdr
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>pillars_2k<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>pillars_2k.hdr
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a <code>pillars_2k</code> folder containing a couple KTX files for the IBL and skybox, as
|
<p>You should now have a <code>pillars_2k</code> folder containing a couple KTX files for the IBL and skybox, as
|
||||||
@@ -61,84 +61,84 @@ well as a text file with spherical harmonics coefficients. You can discard the t
|
|||||||
IBL KTX contains these coefficients in its metadata.</p>
|
IBL KTX contains these coefficients in its metadata.</p>
|
||||||
<h2>Create JavaScript</h2>
|
<h2>Create JavaScript</h2>
|
||||||
<p>Next, create <code>redball.js</code> with the following content.</p>
|
<p>Next, create <code>redball.js</code> with the following content.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>environ<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'pillars_2k'</span>;<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>environ<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'pillars_2k'</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibl_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibl_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamat_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'plastic.filamat'</span><span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamat_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'plastic.filamat'</span>
|
||||||
|
|
||||||
Filament.init([<span style="color: #bbbbbb"> </span>filamat_url,<span style="color: #bbbbbb"> </span>ibl_url,<span style="color: #bbbbbb"> </span>sky_url<span style="color: #bbbbbb"> </span>],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
Filament.init([<span style="color: #BBB"> </span>filamat_url,<span style="color: #BBB"> </span>ibl_url,<span style="color: #BBB"> </span>sky_url<span style="color: #BBB"> </span>],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// Create some global aliases to enums for convenience.</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// Create some global aliases to enums for convenience.</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.VertexAttribute<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexAttribute;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.VertexAttribute<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexAttribute;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.AttributeType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer$AttributeType;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.AttributeType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer$AttributeType;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.PrimitiveType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.RenderableManager$PrimitiveType;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.PrimitiveType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.RenderableManager$PrimitiveType;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.IndexType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndexBuffer$IndexType;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.IndexType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndexBuffer$IndexType;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.Fov<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Camera$Fov;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.Fov<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Camera$Fov;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.LightType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.LightManager$Type;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.LightType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.LightManager$Type;
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// Obtain the canvas DOM object and pass it to the App.</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// Obtain the canvas DOM object and pass it to the App.</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666">0</span>];
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.app<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>App(canvas);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.app<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>App(canvas);
|
||||||
}<span style="color: #bbbbbb"> </span>);<span style="color: #bbbbbb"></span>
|
}<span style="color: #BBB"> </span>);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">class</span><span style="color: #bbbbbb"> </span>App<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">class</span><span style="color: #BBB"> </span>App<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>canvas;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>canvas;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Engine.create(canvas);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Engine.create(canvas);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>scene<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createScene();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>scene<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createScene();
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create material</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create material</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sphere</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sphere</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create lights</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create lights</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create IBL</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create IBL</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create skybox</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create skybox</span>
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createSwapChain();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createSwapChain();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createRenderer();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createRenderer();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createCamera(Filament.EntityManager.get().create());<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createCamera(Filament.EntityManager.get().create());
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createView();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createView();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(scene);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(scene);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>render()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>eye<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">4</span>],<span style="color: #bbbbbb"> </span>center<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>],<span style="color: #bbbbbb"> </span>up<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>eye<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">4</span>],<span style="color: #BBB"> </span>center<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>],<span style="color: #BBB"> </span>up<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>];
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>radians<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Date</span>.now()<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">10000</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>radians<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">Date</span>.now()<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">10000</span>;
|
||||||
<span style="color: #bbbbbb"> </span>vec3.rotateY(eye,<span style="color: #bbbbbb"> </span>eye,<span style="color: #bbbbbb"> </span>center,<span style="color: #bbbbbb"> </span>radians);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>vec3.rotateY(eye,<span style="color: #BBB"> </span>eye,<span style="color: #BBB"> </span>center,<span style="color: #BBB"> </span>radians);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #bbbbbb"> </span>center,<span style="color: #bbbbbb"> </span>up);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #BBB"> </span>center,<span style="color: #BBB"> </span>up);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span>resize()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>resize()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>dpr<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.devicePixelRatio;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>dpr<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.devicePixelRatio;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>width,<span style="color: #bbbbbb"> </span>height]);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>width,<span style="color: #BBB"> </span>height]);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666666">45</span>,<span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>height,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">10.0</span>,<span style="color: #bbbbbb"> </span>Fov.VERTICAL);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666">45</span>,<span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span>height,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>,<span style="color: #BBB"> </span><span style="color: #666">10.0</span>,<span style="color: #BBB"> </span>Fov.VERTICAL);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
}<span style="color: #bbbbbb"></span>
|
}
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The above boilerplate should be familiar to you from the previous tutorial, although it loads in a
|
<p>The above boilerplate should be familiar to you from the previous tutorial, although it loads in a
|
||||||
new set of assets. We also added some animation to the camera.</p>
|
new set of assets. We also added some animation to the camera.</p>
|
||||||
<p>Next let's create a material instance from the package that we built at the beginning the tutorial.
|
<p>Next let's create a material instance from the package that we built at the beginning the tutorial.
|
||||||
Replace the <strong>create material</strong> comment with the following snippet.</p>
|
Replace the <strong>create material</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>material<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createMaterial(filamat_url);<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>material<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createMaterial(filamat_url);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>matinstance<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>material.createInstance();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>matinstance<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>material.createInstance();
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>red<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0.8</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.0</span>];<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>red<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0.8</span>,<span style="color: #BBB"> </span><span style="color: #666">0.0</span>,<span style="color: #BBB"> </span><span style="color: #666">0.0</span>];
|
||||||
matinstance.setColor3Parameter(<span style="color: #BA2121">'baseColor'</span>,<span style="color: #bbbbbb"> </span>Filament.RgbType.sRGB,<span style="color: #bbbbbb"> </span>red);<span style="color: #bbbbbb"></span>
|
matinstance.setColor3Parameter(<span style="color: #BA2121">'baseColor'</span>,<span style="color: #BBB"> </span>Filament.RgbType.sRGB,<span style="color: #BBB"> </span>red);
|
||||||
matinstance.setFloatParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.5</span>);<span style="color: #bbbbbb"></span>
|
matinstance.setFloatParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #BBB"> </span><span style="color: #666">0.5</span>);
|
||||||
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoat'</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>);<span style="color: #bbbbbb"></span>
|
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoat'</span>,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>);
|
||||||
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoatRoughness'</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.3</span>);<span style="color: #bbbbbb"></span>
|
matinstance.setFloatParameter(<span style="color: #BA2121">'clearCoatRoughness'</span>,<span style="color: #BBB"> </span><span style="color: #666">0.3</span>);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The next step is to create a renderable for the sphere. To help with this, we'll use the <code>IcoSphere</code>
|
<p>The next step is to create a renderable for the sphere. To help with this, we'll use the <code>IcoSphere</code>
|
||||||
utility class, whose constructor takes a LOD. Its job is to subdivide an icosadedron, producing
|
utility class, whose constructor takes a LOD. Its job is to subdivide an icosadedron, producing
|
||||||
three arrays:</p>
|
three arrays:</p>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -147,137 +147,137 @@ three arrays:</p>
|
|||||||
as quaternions.</li>
|
as quaternions.</li>
|
||||||
<li><code>icosphere.triangles</code> Uint16Array with triangle indices.</li>
|
<li><code>icosphere.triangles</code> Uint16Array with triangle indices.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Let's go ahead use these arrays to build the vertex buffer and index buffer. Replace <strong>create
|
<p>Let's go ahead use these arrays to build the vertex buffer and index buffer. Replace <strong>create
|
||||||
sphere</strong> with the following snippet.</p>
|
sphere</strong> with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>renderable<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>renderable<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
||||||
scene.addEntity(renderable);<span style="color: #bbbbbb"></span>
|
scene.addEntity(renderable);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>icosphere<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.IcoSphere(<span style="color: #666666">5</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>icosphere<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.IcoSphere(<span style="color: #666">5</span>);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>vb<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>vb<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer.Builder()
|
||||||
<span style="color: #bbbbbb"> </span>.vertexCount(icosphere.vertices.length<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.vertexCount(icosphere.vertices.length<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.bufferCount(<span style="color: #666666">2</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.bufferCount(<span style="color: #666">2</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>AttributeType.FLOAT3,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>AttributeType.FLOAT3,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.TANGENTS,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>AttributeType.SHORT4,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.attribute(VertexAttribute.TANGENTS,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>AttributeType.SHORT4,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.normalized(VertexAttribute.TANGENTS)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.normalized(VertexAttribute.TANGENTS)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ib<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ib<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndexBuffer.Builder()
|
||||||
<span style="color: #bbbbbb"> </span>.indexCount(icosphere.triangles.length)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.indexCount(icosphere.triangles.length)
|
||||||
<span style="color: #bbbbbb"> </span>.bufferType(IndexType.USHORT)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.bufferType(IndexType.USHORT)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine);
|
||||||
|
|
||||||
vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>icosphere.vertices);<span style="color: #bbbbbb"></span>
|
vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>icosphere.vertices);
|
||||||
vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>icosphere.tangents);<span style="color: #bbbbbb"></span>
|
vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>icosphere.tangents);
|
||||||
ib.setBuffer(engine,<span style="color: #bbbbbb"> </span>icosphere.triangles);<span style="color: #bbbbbb"></span>
|
ib.setBuffer(engine,<span style="color: #BBB"> </span>icosphere.triangles);
|
||||||
|
|
||||||
Filament.RenderableManager.Builder(<span style="color: #666666">1</span>)<span style="color: #bbbbbb"></span>
|
Filament.RenderableManager.Builder(<span style="color: #666">1</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.boundingBox({<span style="color: #bbbbbb"> </span>center<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>],<span style="color: #bbbbbb"> </span>halfExtent<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>]<span style="color: #bbbbbb"> </span>})<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.boundingBox({<span style="color: #BBB"> </span>center<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>],<span style="color: #BBB"> </span>halfExtent<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>]<span style="color: #BBB"> </span>})
|
||||||
<span style="color: #bbbbbb"> </span>.material(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>matinstance)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.material(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>matinstance)
|
||||||
<span style="color: #bbbbbb"> </span>.geometry(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>PrimitiveType.TRIANGLES,<span style="color: #bbbbbb"> </span>vb,<span style="color: #bbbbbb"> </span>ib)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.geometry(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>PrimitiveType.TRIANGLES,<span style="color: #BBB"> </span>vb,<span style="color: #BBB"> </span>ib)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span>renderable);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span>renderable);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>At this point, the app is rendering a sphere, but it is black so it doesn't show up. To prove that
|
<p>At this point, the app is rendering a sphere, but it is black so it doesn't show up. To prove that
|
||||||
the sphere is there, you can try changing the background color to blue via <code>setClearColor</code>, like we
|
the sphere is there, you can try changing the background color to blue via <code>setClearColor</code>, like we
|
||||||
did in the first tutorial.</p>
|
did in the first tutorial.</p>
|
||||||
<h2>Add lighting</h2>
|
<h2>Add lighting</h2>
|
||||||
<p>In this section we will create some directional light sources, as well as an image-based light (IBL)
|
<p>In this section we will create some directional light sources, as well as an image-based light (IBL)
|
||||||
defined by one of the KTX files we built at the start of the demo. First, replace the <strong>create
|
defined by one of the KTX files we built at the start of the demo. First, replace the <strong>create
|
||||||
lights</strong> comment with the following snippet.</p>
|
lights</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sunlight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sunlight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
||||||
scene.addEntity(sunlight);<span style="color: #bbbbbb"></span>
|
scene.addEntity(sunlight);
|
||||||
Filament.LightManager.Builder(LightType.SUN)<span style="color: #bbbbbb"></span>
|
Filament.LightManager.Builder(LightType.SUN)
|
||||||
<span style="color: #bbbbbb"> </span>.color([<span style="color: #666666">0.98</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.92</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.89</span>])<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.color([<span style="color: #666">0.98</span>,<span style="color: #BBB"> </span><span style="color: #666">0.92</span>,<span style="color: #BBB"> </span><span style="color: #666">0.89</span>])
|
||||||
<span style="color: #bbbbbb"> </span>.intensity(<span style="color: #666666">110000.0</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.intensity(<span style="color: #666">110000.0</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.direction([<span style="color: #666666">0.6</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-0.8</span>])<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.direction([<span style="color: #666">0.6</span>,<span style="color: #BBB"> </span><span style="color: #666">-1.0</span>,<span style="color: #BBB"> </span><span style="color: #666">-0.8</span>])
|
||||||
<span style="color: #bbbbbb"> </span>.sunAngularRadius(<span style="color: #666666">1.9</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.sunAngularRadius(<span style="color: #666">1.9</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.sunHaloSize(<span style="color: #666666">10.0</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.sunHaloSize(<span style="color: #666">10.0</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.sunHaloFalloff(<span style="color: #666666">80.0</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.sunHaloFalloff(<span style="color: #666">80.0</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span>sunlight);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span>sunlight);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>backlight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>backlight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
||||||
scene.addEntity(backlight);<span style="color: #bbbbbb"></span>
|
scene.addEntity(backlight);
|
||||||
Filament.LightManager.Builder(LightType.DIRECTIONAL)<span style="color: #bbbbbb"></span>
|
Filament.LightManager.Builder(LightType.DIRECTIONAL)
|
||||||
<span style="color: #bbbbbb"> </span>.direction([<span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>])<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.direction([<span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>])
|
||||||
<span style="color: #bbbbbb"> </span>.intensity(<span style="color: #666666">50000.0</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.intensity(<span style="color: #666">50000.0</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span>backlight);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span>backlight);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The <code>SUN</code> light source is similar to the <code>DIRECTIONAL</code> light source, but has some extra
|
<p>The <code>SUN</code> light source is similar to the <code>DIRECTIONAL</code> light source, but has some extra
|
||||||
parameters because Filament will automatically draw a disk into the skybox.</p>
|
parameters because Filament will automatically draw a disk into the skybox.</p>
|
||||||
<p>Next we need to create an <code>IndirectLight</code> object from the KTX IBL. One way of doing this is the
|
<p>Next we need to create an <code>IndirectLight</code> object from the KTX IBL. One way of doing this is the
|
||||||
following (don't type this out, there's an easier way).</p>
|
following (don't type this out, there's an easier way).</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>format<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelDataFormat.RGB;<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>format<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelDataFormat.RGB;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>datatype<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelDataType.UINT_10F_11F_11F_REV;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>datatype<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelDataType.UINT_10F_11F_11F_REV;
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Create a Texture object for the mipmapped cubemap.</span><span style="color: #bbbbbb"></span>
|
<span style="color: #3D7B7B; font-style: italic">// Create a Texture object for the mipmapped cubemap.</span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibl_package<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Buffer(Filament.assets[ibl_url]);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibl_package<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Buffer(Filament.assets[ibl_url]);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>iblktx<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.Ktx1Bundle(ibl_package);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>iblktx<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.Ktx1Bundle(ibl_package);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibltex<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Texture.Builder()<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibltex<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Texture.Builder()
|
||||||
<span style="color: #bbbbbb"> </span>.width(iblktx.info().pixelWidth)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.width(iblktx.info().pixelWidth)
|
||||||
<span style="color: #bbbbbb"> </span>.height(iblktx.info().pixelHeight)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.height(iblktx.info().pixelHeight)
|
||||||
<span style="color: #bbbbbb"> </span>.levels(iblktx.getNumMipLevels())<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.levels(iblktx.getNumMipLevels())
|
||||||
<span style="color: #bbbbbb"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)
|
||||||
<span style="color: #bbbbbb"> </span>.format(Filament.Texture$InternalFormat.RGBA8)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.format(Filament.Texture$InternalFormat.RGBA8)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">for</span><span style="color: #bbbbbb"> </span>(<span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>level<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>;<span style="color: #bbbbbb"> </span>level<span style="color: #bbbbbb"> </span><span style="color: #666666"><</span><span style="color: #bbbbbb"> </span>iblktx.getNumMipLevels();<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span>level)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">for</span><span style="color: #BBB"> </span>(<span style="color: #008000; font-weight: bold">let</span><span style="color: #BBB"> </span>level<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #666">0</span>;<span style="color: #BBB"> </span>level<span style="color: #BBB"> </span><span style="color: #666"><</span><span style="color: #BBB"> </span>iblktx.getNumMipLevels();<span style="color: #BBB"> </span><span style="color: #666">++</span>level)<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>uint8array<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>iblktx.getCubeBlob(level).getBytes();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>uint8array<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>iblktx.getCubeBlob(level).getBytes();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>pixelbuffer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelBuffer(uint8array,<span style="color: #bbbbbb"> </span>format,<span style="color: #bbbbbb"> </span>datatype);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>pixelbuffer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelBuffer(uint8array,<span style="color: #BBB"> </span>format,<span style="color: #BBB"> </span>datatype);
|
||||||
<span style="color: #bbbbbb"> </span>ibltex.setImageCube(engine,<span style="color: #bbbbbb"> </span>level,<span style="color: #bbbbbb"> </span>pixelbuffer);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>ibltex.setImageCube(engine,<span style="color: #BBB"> </span>level,<span style="color: #BBB"> </span>pixelbuffer);
|
||||||
}<span style="color: #bbbbbb"></span>
|
}
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Parse the spherical harmonics metadata.</span><span style="color: #bbbbbb"></span>
|
<span style="color: #3D7B7B; font-style: italic">// Parse the spherical harmonics metadata.</span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>shstring<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>iblktx.getMetadata(<span style="color: #BA2121">'sh'</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>shstring<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>iblktx.getMetadata(<span style="color: #BA2121">'sh'</span>);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>shfloats<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>shstring.split(<span style="color: #A45A77">/\s/</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">9</span><span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>).map(<span style="color: #008000">parseFloat</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>shfloats<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>shstring.split(<span style="color: #A45A77">/\s/</span>,<span style="color: #BBB"> </span><span style="color: #666">9</span><span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">3</span>).map(<span style="color: #008000">parseFloat</span>);
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Build the IBL object and insert it into the scene.</span><span style="color: #bbbbbb"></span>
|
<span style="color: #3D7B7B; font-style: italic">// Build the IBL object and insert it into the scene.</span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>indirectLight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndirectLight.Builder()<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>indirectLight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndirectLight.Builder()
|
||||||
<span style="color: #bbbbbb"> </span>.reflections(ibltex)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.reflections(ibltex)
|
||||||
<span style="color: #bbbbbb"> </span>.irradianceSh(<span style="color: #666666">3</span>,<span style="color: #bbbbbb"> </span>shfloats)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.irradianceSh(<span style="color: #666">3</span>,<span style="color: #BBB"> </span>shfloats)
|
||||||
<span style="color: #bbbbbb"> </span>.intensity(<span style="color: #666666">50000.0</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.intensity(<span style="color: #666">50000.0</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine);
|
||||||
|
|
||||||
scene.setIndirectLight(indirectLight);<span style="color: #bbbbbb"></span>
|
scene.setIndirectLight(indirectLight);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Filament provides a JavaScript utility to make this simpler,
|
<p>Filament provides a JavaScript utility to make this simpler,
|
||||||
simply replace the <strong>create IBL</strong> comment with the following snippet.</p>
|
simply replace the <strong>create IBL</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>indirectLight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createIblFromKtx1(ibl_url);<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>indirectLight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createIblFromKtx1(ibl_url);
|
||||||
indirectLight.setIntensity(<span style="color: #666666">50000</span>);<span style="color: #bbbbbb"></span>
|
indirectLight.setIntensity(<span style="color: #666">50000</span>);
|
||||||
scene.setIndirectLight(indirectLight);<span style="color: #bbbbbb"></span>
|
scene.setIndirectLight(indirectLight);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Add background</h2>
|
<h2>Add background</h2>
|
||||||
<p>At this point you can run the demo and you should see a red plastic ball against a black background.
|
<p>At this point you can run the demo and you should see a red plastic ball against a black background.
|
||||||
Without a skybox, the reflections on the ball are not representative of its surroundings.
|
Without a skybox, the reflections on the ball are not representative of its surroundings.
|
||||||
Here's one way to create a texture for the skybox:</p>
|
Here's one way to create a texture for the skybox:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_package<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Buffer(Filament.assets[sky_url]);<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_package<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Buffer(Filament.assets[sky_url]);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>skyktx<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.Ktx1Bundle(sky_package);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>skyktx<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.Ktx1Bundle(sky_package);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>skytex<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Texture.Builder()<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>skytex<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Texture.Builder()
|
||||||
<span style="color: #bbbbbb"> </span>.width(skyktx.info().pixelWidth)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.width(skyktx.info().pixelWidth)
|
||||||
<span style="color: #bbbbbb"> </span>.height(skyktx.info().pixelHeight)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.height(skyktx.info().pixelHeight)
|
||||||
<span style="color: #bbbbbb"> </span>.levels(<span style="color: #666666">1</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.levels(<span style="color: #666">1</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.sampler(Filament.Texture$Sampler.SAMPLER_CUBEMAP)
|
||||||
<span style="color: #bbbbbb"> </span>.format(Filament.Texture$InternalFormat.RGBA8)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.format(Filament.Texture$InternalFormat.RGBA8)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>uint8array<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>skyktx.getCubeBlob(<span style="color: #666666">0</span>).getBytes();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>uint8array<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>skyktx.getCubeBlob(<span style="color: #666">0</span>).getBytes();
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>pixelbuffer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.PixelBuffer(uint8array,<span style="color: #bbbbbb"> </span>format,<span style="color: #bbbbbb"> </span>datatype);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>pixelbuffer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.PixelBuffer(uint8array,<span style="color: #BBB"> </span>format,<span style="color: #BBB"> </span>datatype);
|
||||||
skytex.setImageCube(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>pixelbuffer);<span style="color: #bbbbbb"></span>
|
skytex.setImageCube(engine,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>pixelbuffer);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Filament provides a Javascript utility to make this easier.
|
<p>Filament provides a Javascript utility to make this easier.
|
||||||
Replace <strong>create skybox</strong> with the following.</p>
|
Replace <strong>create skybox</strong> with the following.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>skybox<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createSkyFromKtx1(sky_url);<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>skybox<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createSkyFromKtx1(sky_url);
|
||||||
scene.setSkybox(skybox);<span style="color: #bbbbbb"></span>
|
scene.setSkybox(skybox);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>That's it, we now have a shiny red ball floating in an environment! The complete JavaScript file is
|
<p>That's it, we now have a shiny red ball floating in an environment! The complete JavaScript file is
|
||||||
available <a href="tutorial_redball.js">here</a>.</p>
|
available <a href="tutorial_redball.js">here</a>.</p>
|
||||||
<p>In the <a href="tutorial_suzanne.html">next tutorial</a>, we'll take a closer look at textures and interaction.</p>
|
<p>In the <a href="tutorial_suzanne.html">next tutorial</a>, we'll take a closer look at textures and interaction.</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+121
-121
@@ -8,58 +8,58 @@
|
|||||||
<div class="demo_frame"><iframe src="demo_suzanne.html"></iframe><a href="demo_suzanne.html">🔗</a></div>
|
<div class="demo_frame"><iframe src="demo_suzanne.html"></iframe><a href="demo_suzanne.html">🔗</a></div>
|
||||||
<p>This tutorial will describe how to create the <strong>suzanne</strong> demo, introducing you to compressed
|
<p>This tutorial will describe how to create the <strong>suzanne</strong> demo, introducing you to compressed
|
||||||
textures, mipmap generation, asynchronous texture loading, and trackball rotation.</p>
|
textures, mipmap generation, asynchronous texture loading, and trackball rotation.</p>
|
||||||
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a>, you'll need to use the command-line tools that can be found in
|
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a>, you'll need to use the command-line tools that can be found in
|
||||||
the appropriate <a href="//github.com/google/filament/releases">Filament release</a> for your development machine. In addition to <code>matc</code> and <code>cmgen</code>,
|
the appropriate <a href="//github.com/google/filament/releases">Filament release</a> for your development machine. In addition to <code>matc</code> and <code>cmgen</code>,
|
||||||
we'll also be using <code>filamesh</code> and <code>mipgen</code>.</p>
|
we'll also be using <code>filamesh</code> and <code>mipgen</code>.</p>
|
||||||
<h2>Create filamesh file</h2>
|
<h2>Create filamesh file</h2>
|
||||||
<p>Filament does not have an asset loading system, but it does provide a binary mesh format
|
<p>Filament does not have an asset loading system, but it does provide a binary mesh format
|
||||||
called <code>filamesh</code> for simple use cases. Let's create a compressed filamesh file for suzanne by
|
called <code>filamesh</code> for simple use cases. Let's create a compressed filamesh file for suzanne by
|
||||||
converting <a href="https://github.com/google/filament/blob/main/assets/models/monkey/monkey.obj">this OBJ file</a>:</p>
|
converting <a href="https://github.com/google/filament/blob/main/assets/models/monkey/monkey.obj">this OBJ file</a>:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>filamesh --compress monkey.obj suzanne.filamesh
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>filamesh<span style="color: #BBB"> </span>--compress<span style="color: #BBB"> </span>monkey.obj<span style="color: #BBB"> </span>suzanne.filamesh
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Create mipmapped textures</h2>
|
<h2>Create mipmapped textures</h2>
|
||||||
<p>Next, let's create mipmapped KTX files using filament's <code>mipgen</code> tool. We'll create compressed and
|
<p>Next, let's create mipmapped KTX files using filament's <code>mipgen</code> tool. We'll create compressed and
|
||||||
non-compressed variants for each texture, since not all platforms support the same compression
|
non-compressed variants for each texture, since not all platforms support the same compression
|
||||||
formats. First copy over the PNG files from the <a href="https://github.com/google/filament/blob/main/assets/models/monkey">monkey folder</a>, then do:</p>
|
formats. First copy over the PNG files from the <a href="https://github.com/google/filament/blob/main/assets/models/monkey">monkey folder</a>, then do:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic"># Create mipmaps for base color</span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic"># Create mipmaps for base color</span>
|
||||||
mipgen albedo.png albedo.ktx2
|
mipgen<span style="color: #BBB"> </span>albedo.png<span style="color: #BBB"> </span>albedo.ktx2
|
||||||
mipgen --compression<span style="color: #666666">=</span>uastc albedo.png albedo.ktx2
|
mipgen<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>albedo.png<span style="color: #BBB"> </span>albedo.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the normal map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the normal map and a compressed variant.</span>
|
||||||
mipgen --strip-alpha --kernel<span style="color: #666666">=</span>NORMALS --linear normal.png normal.ktx
|
mipgen<span style="color: #BBB"> </span>--strip-alpha<span style="color: #BBB"> </span>--kernel<span style="color: #666">=</span>NORMALS<span style="color: #BBB"> </span>--linear<span style="color: #BBB"> </span>normal.png<span style="color: #BBB"> </span>normal.ktx
|
||||||
mipgen --strip-alpha --kernel<span style="color: #666666">=</span>NORMALS --linear --compression<span style="color: #666666">=</span>uastc_normals <span style="color: #AA5D1F; font-weight: bold">\</span>
|
mipgen<span style="color: #BBB"> </span>--strip-alpha<span style="color: #BBB"> </span>--kernel<span style="color: #666">=</span>NORMALS<span style="color: #BBB"> </span>--linear<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc_normals<span style="color: #BBB"> </span><span style="color: #AA5D1F; font-weight: bold">\</span>
|
||||||
normal.png normal.ktx2
|
<span style="color: #BBB"> </span>normal.png<span style="color: #BBB"> </span>normal.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component roughness map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component roughness map and a compressed variant.</span>
|
||||||
mipgen --grayscale roughness.png roughness.ktx
|
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>roughness.png<span style="color: #BBB"> </span>roughness.ktx
|
||||||
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc roughness.png roughness.ktx2
|
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>roughness.png<span style="color: #BBB"> </span>roughness.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component metallic map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component metallic map and a compressed variant.</span>
|
||||||
mipgen --grayscale metallic.png metallic.ktx
|
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>metallic.png<span style="color: #BBB"> </span>metallic.ktx
|
||||||
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc metallic.png metallic.ktx2
|
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>metallic.png<span style="color: #BBB"> </span>metallic.ktx2
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component occlusion map and a compressed variant.</span>
|
<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component occlusion map and a compressed variant.</span>
|
||||||
mipgen --grayscale ao.png ao.ktx
|
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>ao.png<span style="color: #BBB"> </span>ao.ktx
|
||||||
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc ao.png ao.ktx2
|
mipgen<span style="color: #BBB"> </span>--grayscale<span style="color: #BBB"> </span>--compression<span style="color: #666">=</span>uastc<span style="color: #BBB"> </span>ao.png<span style="color: #BBB"> </span>ao.ktx2
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>For more information on mipgen's arguments and supported formats, do <code>mipgen --help</code>.</p>
|
<p>For more information on mipgen's arguments and supported formats, do <code>mipgen --help</code>.</p>
|
||||||
<p>In a production setting, you'd want to invoke these commands with a script or build system.</p>
|
<p>In a production setting, you'd want to invoke these commands with a script or build system.</p>
|
||||||
<h2>Bake environment map</h2>
|
<h2>Bake environment map</h2>
|
||||||
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a> we need to use Filament's <code>cmgen</code> tool to produce cubemap files.</p>
|
<p>Much like the <a href="tutorial_redball.html">previous tutorial</a> we need to use Filament's <code>cmgen</code> tool to produce cubemap files.</p>
|
||||||
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/venetian_crossroads_2k.hdr">venetian_crossroads_2k.hdr</a>, then invoke the following commands in your terminal.</p>
|
<p>Download <a href="//github.com/google/filament/blob/main/third_party/environments/venetian_crossroads_2k.hdr">venetian_crossroads_2k.hdr</a>, then invoke the following commands in your terminal.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=64</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=64</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
||||||
<span style="color: #008000">cd</span> venetian* ; mv venetian*_ibl.ktx venetian_crossroads_2k_skybox_tiny.ktx ; <span style="color: #008000">cd</span> -
|
<span style="color: #008000">cd</span><span style="color: #BBB"> </span>venetian*<span style="color: #BBB"> </span>;<span style="color: #BBB"> </span>mv<span style="color: #BBB"> </span>venetian*_ibl.ktx<span style="color: #BBB"> </span>venetian_crossroads_2k_skybox_tiny.ktx<span style="color: #BBB"> </span>;<span style="color: #BBB"> </span><span style="color: #008000">cd</span><span style="color: #BBB"> </span>-
|
||||||
|
|
||||||
cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
||||||
cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
||||||
cmgen -x . --format<span style="color: #666666">=</span>ktx --size<span style="color: #666666">=256</span> --extract-blur<span style="color: #666666">=0</span>.1 venetian_crossroads_2k.hdr
|
cmgen<span style="color: #BBB"> </span>-x<span style="color: #BBB"> </span>.<span style="color: #BBB"> </span>--format<span style="color: #666">=</span>ktx<span style="color: #BBB"> </span>--size<span style="color: #666">=256</span><span style="color: #BBB"> </span>--extract-blur<span style="color: #666">=0</span>.1<span style="color: #BBB"> </span>venetian_crossroads_2k.hdr
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Define textured material</h2>
|
<h2>Define textured material</h2>
|
||||||
<p>You might recall the <code>filamat</code> file we generated in the previous tutorial for red plastic. For this
|
<p>You might recall the <code>filamat</code> file we generated in the previous tutorial for red plastic. For this
|
||||||
demo, we'll create a material that uses textures for several parameters.</p>
|
demo, we'll create a material that uses textures for several parameters.</p>
|
||||||
<p>Create the following text file and call it <code>textured.mat</code>. Note that our material definition now
|
<p>Create the following text file and call it <code>textured.mat</code>. Note that our material definition now
|
||||||
requires a <code>uv0</code> attribute.</p>
|
requires a <code>uv0</code> attribute.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>material {
|
||||||
@@ -90,7 +90,7 @@ fragment {
|
|||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next, invoke <code>matc</code> as follows.</p>
|
<p>Next, invoke <code>matc</code> as follows.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc -a opengl -p mobile -o textured.filamat textured.mat
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>matc<span style="color: #BBB"> </span>-a<span style="color: #BBB"> </span>opengl<span style="color: #BBB"> </span>-p<span style="color: #BBB"> </span>mobile<span style="color: #BBB"> </span>-o<span style="color: #BBB"> </span>textured.filamat<span style="color: #BBB"> </span>textured.mat
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a material archive in your working directory. For the suzanne asset, the normal
|
<p>You should now have a material archive in your working directory. For the suzanne asset, the normal
|
||||||
@@ -100,65 +100,65 @@ materials, consult the official document describing the <a href="https://google.
|
|||||||
<p>Create a text file called <code>suzanne.html</code> and copy over the HTML that we used in the <a href="tutorial_redball.html">previous
|
<p>Create a text file called <code>suzanne.html</code> and copy over the HTML that we used in the <a href="tutorial_redball.html">previous
|
||||||
tutorial</a>. Change the last script tag from <code>redball.js</code> to <code>suzanne.js</code>. Next, create <code>suzanne.js</code>
|
tutorial</a>. Change the last script tag from <code>redball.js</code> to <code>suzanne.js</code>. Next, create <code>suzanne.js</code>
|
||||||
with the following content.</p>
|
with the following content.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// TODO: declare asset URLs</span><span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// TODO: declare asset URLs</span>
|
||||||
|
|
||||||
Filament.init([<span style="color: #bbbbbb"> </span>filamat_url,<span style="color: #bbbbbb"> </span>filamesh_url,<span style="color: #bbbbbb"> </span>sky_small_url,<span style="color: #bbbbbb"> </span>ibl_url<span style="color: #bbbbbb"> </span>],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
Filament.init([<span style="color: #BBB"> </span>filamat_url,<span style="color: #BBB"> </span>filamesh_url,<span style="color: #BBB"> </span>sky_small_url,<span style="color: #BBB"> </span>ibl_url<span style="color: #BBB"> </span>],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.app<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>App(<span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666666">0</span>]);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.app<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>App(<span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666">0</span>]);
|
||||||
});<span style="color: #bbbbbb"></span>
|
});
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">class</span><span style="color: #bbbbbb"> </span>App<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">class</span><span style="color: #BBB"> </span>App<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">constructor</span>(canvas)<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>canvas;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>canvas;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Engine.create(canvas);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Engine.create(canvas);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createScene();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createScene();
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>material<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createMaterial(filamat_url);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>material<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createMaterial(filamat_url);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>material.createInstance();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>material.createInstance();
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamesh<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.loadFilamesh(filamesh_url,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamesh<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.loadFilamesh(filamesh_url,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.suzanne<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>filamesh.renderable;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.suzanne<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>filamesh.renderable;
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sky box and IBL</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create sky box and IBL</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: initialize gltumble</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: initialize gltumble</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: fetch larger assets</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: fetch larger assets</span>
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSwapChain();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSwapChain();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createRenderer();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createRenderer();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createCamera(Filament.EntityManager.get().create());<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createCamera(Filament.EntityManager.get().create());
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createView();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createView();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>eye<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">4</span>],<span style="color: #bbbbbb"> </span>center<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>],<span style="color: #bbbbbb"> </span>up<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>eye<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">4</span>],<span style="color: #BBB"> </span>center<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>],<span style="color: #BBB"> </span>up<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>];
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #bbbbbb"> </span>center,<span style="color: #bbbbbb"> </span>up);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.lookAt(eye,<span style="color: #BBB"> </span>center,<span style="color: #BBB"> </span>up);
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize();
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>render()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: apply gltumble matrix</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: apply gltumble matrix</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span>resize()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>resize()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>dpr<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.devicePixelRatio;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>dpr<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.devicePixelRatio;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>width,<span style="color: #bbbbbb"> </span>height]);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>width,<span style="color: #BBB"> </span>height]);
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>aspect<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>height;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>aspect<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span>height;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>Fov<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Camera$Fov,<span style="color: #bbbbbb"> </span>fov<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>aspect<span style="color: #bbbbbb"> </span><span style="color: #666666"><</span><span style="color: #bbbbbb"> </span><span style="color: #666666">1</span><span style="color: #bbbbbb"> </span><span style="color: #666666">?</span><span style="color: #bbbbbb"> </span>Fov.HORIZONTAL<span style="color: #bbbbbb"> </span><span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>Fov.VERTICAL;<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>Fov<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Camera$Fov,<span style="color: #BBB"> </span>fov<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>aspect<span style="color: #BBB"> </span><span style="color: #666"><</span><span style="color: #BBB"> </span><span style="color: #666">1</span><span style="color: #BBB"> </span><span style="color: #666">?</span><span style="color: #BBB"> </span>Fov.HORIZONTAL<span style="color: #BBB"> </span><span style="color: #666">:</span><span style="color: #BBB"> </span>Fov.VERTICAL;
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666666">45</span>,<span style="color: #bbbbbb"> </span>aspect,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">10.0</span>,<span style="color: #bbbbbb"> </span>fov);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.camera.setProjectionFov(<span style="color: #666">45</span>,<span style="color: #BBB"> </span>aspect,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>,<span style="color: #BBB"> </span><span style="color: #666">10.0</span>,<span style="color: #BBB"> </span>fov);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
}<span style="color: #bbbbbb"></span>
|
}
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Our app will only require a subset of assets to be present for <code>App</code> construction. We'll download
|
<p>Our app will only require a subset of assets to be present for <code>App</code> construction. We'll download
|
||||||
the other assets after construction. By using a progressive loading strategy, we can reduce the
|
the other assets after construction. By using a progressive loading strategy, we can reduce the
|
||||||
perceived load time.</p>
|
perceived load time.</p>
|
||||||
<p>Next we need to supply the URLs for various assets. This is actually a bit tricky, because different
|
<p>Next we need to supply the URLs for various assets. This is actually a bit tricky, because different
|
||||||
@@ -171,85 +171,85 @@ string -- which might be empty.</p>
|
|||||||
<p>In our case, we know that our web server will have <code>astc</code> and <code>s3tc</code> variants for albedo, and <code>etc</code>
|
<p>In our case, we know that our web server will have <code>astc</code> and <code>s3tc</code> variants for albedo, and <code>etc</code>
|
||||||
variants for the other textures. The uncompressed variants (empty string) are always available as a
|
variants for the other textures. The uncompressed variants (empty string) are always available as a
|
||||||
last resort. Go ahead and replace the <strong>declare asset URLs</strong> comment with the following snippet.</p>
|
last resort. Go ahead and replace the <strong>declare asset URLs</strong> comment with the following snippet.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo_suffix<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'astc s3tc_srgb'</span>);<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>albedo_suffix<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'astc s3tc_srgb'</span>);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>texture_suffix<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'etc'</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>texture_suffix<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.getSupportedFormatSuffix(<span style="color: #BA2121">'etc'</span>);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>environ<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'venetian_crossroads_2k'</span><span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>environ<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'venetian_crossroads_2k'</span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ibl_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ibl_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_ibl.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_small_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox_tiny.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_small_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox_tiny.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sky_large_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sky_large_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">/</span><span style="color: #A45A77; font-weight: bold">${</span>environ<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">_skybox.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`albedo</span><span style="color: #A45A77; font-weight: bold">${</span>albedo_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>albedo_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`albedo</span><span style="color: #A45A77; font-weight: bold">${</span>albedo_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ao_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`ao</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ao_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`ao</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>metallic_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`metallic</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>metallic_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`metallic</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>normal_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`normal</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>normal_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`normal</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>roughness_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">`roughness</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>roughness_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">`roughness</span><span style="color: #A45A77; font-weight: bold">${</span>texture_suffix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">.ktx`</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamat_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'textured.filamat'</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamat_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'textured.filamat'</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>filamesh_url<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">'suzanne.filamesh'</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>filamesh_url<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #BA2121">'suzanne.filamesh'</span>;
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Create skybox and IBL</h2>
|
<h2>Create skybox and IBL</h2>
|
||||||
<p>Next, let's create the low-resolution skybox and IBL in the <code>App</code> constructor.</p>
|
<p>Next, let's create the low-resolution skybox and IBL in the <code>App</code> constructor.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_small_url);<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_small_url);
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.indirectLight<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createIblFromKtx1(ibl_url);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.indirectLight<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createIblFromKtx1(ibl_url);
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.indirectLight.setIntensity(<span style="color: #666666">100000</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.indirectLight.setIntensity(<span style="color: #666">100000</span>);
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.scene.setIndirectLight(<span style="color: #008000; font-weight: bold">this</span>.indirectLight);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.scene.setIndirectLight(<span style="color: #008000; font-weight: bold">this</span>.indirectLight);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>This allows users to see a reasonable background fairly quickly, before larger assets have finished
|
<p>This allows users to see a reasonable background fairly quickly, before larger assets have finished
|
||||||
loading in.</p>
|
loading in.</p>
|
||||||
<h2>Fetch assets asychronously</h2>
|
<h2>Fetch assets asychronously</h2>
|
||||||
<p>Next we'll invoke the <code>Filament.fetch</code> function from within the app constructor. This function is
|
<p>Next we'll invoke the <code>Filament.fetch</code> function from within the app constructor. This function is
|
||||||
very similar to <code>Filament.init</code>. It takes a list of asset URLs and a callback function that triggers
|
very similar to <code>Filament.init</code>. It takes a list of asset URLs and a callback function that triggers
|
||||||
when the assets have finished downloading.</p>
|
when the assets have finished downloading.</p>
|
||||||
<p>In our callback, we'll make several <code>setTextureParameter</code> calls on the material instance, then we'll
|
<p>In our callback, we'll make several <code>setTextureParameter</code> calls on the material instance, then we'll
|
||||||
recreate the skybox using a higher-resolution texture. As a last step we unhide the renderable that
|
recreate the skybox using a higher-resolution texture. As a last step we unhide the renderable that
|
||||||
was created in the app constructor.</p>
|
was created in the app constructor.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>Filament.fetch([sky_large_url,<span style="color: #bbbbbb"> </span>albedo_url,<span style="color: #bbbbbb"> </span>roughness_url,<span style="color: #bbbbbb"> </span>metallic_url,<span style="color: #bbbbbb"> </span>normal_url,<span style="color: #bbbbbb"> </span>ao_url],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>Filament.fetch([sky_large_url,<span style="color: #BBB"> </span>albedo_url,<span style="color: #BBB"> </span>roughness_url,<span style="color: #BBB"> </span>metallic_url,<span style="color: #BBB"> </span>normal_url,<span style="color: #BBB"> </span>ao_url],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(albedo_url,<span style="color: #bbbbbb"> </span>{srgb<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">true</span>});<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>albedo<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(albedo_url,<span style="color: #BBB"> </span>{srgb<span style="color: #666">:</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">true</span>});
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>roughness<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(roughness_url);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>roughness<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(roughness_url);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>metallic<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(metallic_url);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>metallic<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(metallic_url);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>normal<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(normal_url);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>normal<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(normal_url);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ao<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(ao_url);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>ao<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(ao_url);
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sampler<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.TextureSampler(<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>sampler<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Filament.TextureSampler(
|
||||||
<span style="color: #bbbbbb"> </span>Filament.MinFilter.LINEAR_MIPMAP_LINEAR,<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>Filament.MinFilter.LINEAR_MIPMAP_LINEAR,
|
||||||
<span style="color: #bbbbbb"> </span>Filament.MagFilter.LINEAR,<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>Filament.MagFilter.LINEAR,
|
||||||
<span style="color: #bbbbbb"> </span>Filament.WrapMode.CLAMP_TO_EDGE);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>Filament.WrapMode.CLAMP_TO_EDGE);
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'albedo'</span>,<span style="color: #bbbbbb"> </span>albedo,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'albedo'</span>,<span style="color: #BBB"> </span>albedo,<span style="color: #BBB"> </span>sampler);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #bbbbbb"> </span>roughness,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'roughness'</span>,<span style="color: #BBB"> </span>roughness,<span style="color: #BBB"> </span>sampler);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'metallic'</span>,<span style="color: #bbbbbb"> </span>metallic,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'metallic'</span>,<span style="color: #BBB"> </span>metallic,<span style="color: #BBB"> </span>sampler);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'normal'</span>,<span style="color: #bbbbbb"> </span>normal,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'normal'</span>,<span style="color: #BBB"> </span>normal,<span style="color: #BBB"> </span>sampler);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'ao'</span>,<span style="color: #bbbbbb"> </span>ao,<span style="color: #bbbbbb"> </span>sampler);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.matinstance.setTextureParameter(<span style="color: #BA2121">'ao'</span>,<span style="color: #BBB"> </span>ao,<span style="color: #BBB"> </span>sampler);
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// Replace low-res skybox with high-res skybox.</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// Replace low-res skybox with high-res skybox.</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.destroySkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.destroySkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_large_url);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.skybox<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createSkyFromKtx1(sky_large_url);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.setSkybox(<span style="color: #008000; font-weight: bold">this</span>.skybox);
|
||||||
|
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.suzanne);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.suzanne);
|
||||||
});<span style="color: #bbbbbb"></span>
|
});
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<h2>Introduce trackball rotation</h2>
|
<h2>Introduce trackball rotation</h2>
|
||||||
<p>Add the following script tag to your HTML file. This imports a small third-party library that
|
<p>Add the following script tag to your HTML file. This imports a small third-party library that
|
||||||
listens for drag events and computes a rotation matrix.</p>
|
listens for drag events and computes a rotation matrix.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"//unpkg.com/gltumble"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"//unpkg.com/gltumble"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next, replace the <strong>initialize gltumble</strong> and <strong>apply gltumble matrix</strong> comments with the following
|
<p>Next, replace the <strong>initialize gltumble</strong> and <strong>apply gltumble matrix</strong> comments with the following
|
||||||
two code snippets.</p>
|
two code snippets.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.trackball<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Trackball(canvas,<span style="color: #bbbbbb"> </span>{startSpin<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #666666">0.035</span>});<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.trackball<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>Trackball(canvas,<span style="color: #BBB"> </span>{startSpin<span style="color: #666">:</span><span style="color: #BBB"> </span><span style="color: #666">0.035</span>});
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>tcm<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>tcm<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>inst<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.suzanne);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>inst<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.suzanne);
|
||||||
tcm.setTransform(inst,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.trackball.getMatrix());<span style="color: #bbbbbb"></span>
|
tcm.setTransform(inst,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.trackball.getMatrix());
|
||||||
inst.<span style="color: #AA22FF; font-weight: bold">delete</span>();<span style="color: #bbbbbb"></span>
|
inst.<span style="color: #A2F; font-weight: bold">delete</span>();
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>That's it, we now have a fast-loading interactive demo. The complete JavaScript file is available
|
<p>That's it, we now have a fast-loading interactive demo. The complete JavaScript file is available
|
||||||
<a href="tutorial_suzanne.js">here</a>.</p>
|
<a href="tutorial_suzanne.js">here</a>.</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+110
-110
@@ -8,30 +8,30 @@
|
|||||||
<div class="demo_frame"><iframe src="demo_triangle.html"></iframe><a href="demo_triangle.html">🔗</a></div>
|
<div class="demo_frame"><iframe src="demo_triangle.html"></iframe><a href="demo_triangle.html">🔗</a></div>
|
||||||
<h2>Literate programming</h2>
|
<h2>Literate programming</h2>
|
||||||
<p>The markdown source for this tutorial is not only used to generate this
|
<p>The markdown source for this tutorial is not only used to generate this
|
||||||
web page, it's also used to generate the JavaScript for the above demo.
|
web page, it's also used to generate the JavaScript for the above demo.
|
||||||
We use a small Python script for weaving (generating HTML) and tangling
|
We use a small Python script for weaving (generating HTML) and tangling
|
||||||
(generating JS). In the code samples, you'll often see
|
(generating JS). In the code samples, you'll often see
|
||||||
<code>// TODO: <some task></code>. These are special markers that get replaced by
|
<code>// TODO: <some task></code>. These are special markers that get replaced by
|
||||||
subsequent code blocks.</p>
|
subsequent code blocks.</p>
|
||||||
<h2>Start your project</h2>
|
<h2>Start your project</h2>
|
||||||
<p>First, create a text file called <code>triangle.html</code> and fill it with the following HTML. This creates
|
<p>First, create a text file called <code>triangle.html</code> and fill it with the following HTML. This creates
|
||||||
a mobile-friendly page with a full-screen canvas.</p>
|
a mobile-friendly page with a full-screen canvas.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #9C6500"><!DOCTYPE html></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #9C6500"><!DOCTYPE html></span>
|
||||||
<<span style="color: #008000; font-weight: bold">html</span> <span style="color: #687822">lang</span><span style="color: #666666">=</span><span style="color: #BA2121">"en"</span>>
|
<<span style="color: #008000; font-weight: bold">html</span> <span style="color: #687822">lang</span><span style="color: #666">=</span><span style="color: #BA2121">"en"</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">head</span>>
|
<<span style="color: #008000; font-weight: bold">head</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">title</span>>Filament Tutorial</<span style="color: #008000; font-weight: bold">title</span>>
|
<<span style="color: #008000; font-weight: bold">title</span>>Filament Tutorial</<span style="color: #008000; font-weight: bold">title</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">charset</span><span style="color: #666666">=</span><span style="color: #BA2121">"utf-8"</span>>
|
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">charset</span><span style="color: #666">=</span><span style="color: #BA2121">"utf-8"</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">name</span><span style="color: #666666">=</span><span style="color: #BA2121">"viewport"</span> <span style="color: #687822">content</span><span style="color: #666666">=</span><span style="color: #BA2121">"width=device-width,user-scalable=no,initial-scale=1"</span>>
|
<<span style="color: #008000; font-weight: bold">meta</span> <span style="color: #687822">name</span><span style="color: #666">=</span><span style="color: #BA2121">"viewport"</span> <span style="color: #687822">content</span><span style="color: #666">=</span><span style="color: #BA2121">"width=device-width,user-scalable=no,initial-scale=1"</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">style</span>><span style="color: #bbbbbb"></span>
|
<<span style="color: #008000; font-weight: bold">style</span>>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">body</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">margin</span>:<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>;<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">overflow</span>:<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">hidden</span>;<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">body</span><span style="color: #BBB"> </span>{<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">margin</span>:<span style="color: #BBB"> </span><span style="color: #666">0</span>;<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">overflow</span>:<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">hidden</span>;<span style="color: #BBB"> </span>}
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">canvas</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>touch-action:<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">none</span>;<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">width</span>:<span style="color: #bbbbbb"> </span><span style="color: #666666">100</span><span style="color: #B00040">%</span>;<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">height</span>:<span style="color: #bbbbbb"> </span><span style="color: #666666">100</span><span style="color: #B00040">%</span>;<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">canvas</span><span style="color: #BBB"> </span>{<span style="color: #BBB"> </span>touch-action:<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">none</span>;<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">width</span>:<span style="color: #BBB"> </span><span style="color: #666">100</span><span style="color: #B00040">%</span>;<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">height</span>:<span style="color: #BBB"> </span><span style="color: #666">100</span><span style="color: #B00040">%</span>;<span style="color: #BBB"> </span>}
|
||||||
<span style="color: #bbbbbb"> </span></<span style="color: #008000; font-weight: bold">style</span>>
|
<span style="color: #BBB"> </span></<span style="color: #008000; font-weight: bold">style</span>>
|
||||||
</<span style="color: #008000; font-weight: bold">head</span>>
|
</<span style="color: #008000; font-weight: bold">head</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">body</span>>
|
<<span style="color: #008000; font-weight: bold">body</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">canvas</span>></<span style="color: #008000; font-weight: bold">canvas</span>>
|
<<span style="color: #008000; font-weight: bold">canvas</span>></<span style="color: #008000; font-weight: bold">canvas</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"filament.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"filament.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"//unpkg.com/gl-matrix@2.8.1"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"//unpkg.com/gl-matrix@2.8.1"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666666">=</span><span style="color: #BA2121">"triangle.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
<<span style="color: #008000; font-weight: bold">script</span> <span style="color: #687822">src</span><span style="color: #666">=</span><span style="color: #BA2121">"triangle.js"</span>></<span style="color: #008000; font-weight: bold">script</span>>
|
||||||
</<span style="color: #008000; font-weight: bold">body</span>>
|
</<span style="color: #008000; font-weight: bold">body</span>>
|
||||||
</<span style="color: #008000; font-weight: bold">html</span>>
|
</<span style="color: #008000; font-weight: bold">html</span>>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
@@ -48,63 +48,63 @@ a mobile-friendly page with a full-screen canvas.</p>
|
|||||||
<li><code>triangle.js</code> will contain your application code.</li>
|
<li><code>triangle.js</code> will contain your application code.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Go ahead and create <code>triangle.js</code> with the following content.</p>
|
<p>Go ahead and create <code>triangle.js</code> with the following content.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">class</span><span style="color: #bbbbbb"> </span>App<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">class</span><span style="color: #BBB"> </span>App<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">constructor</span>()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">constructor</span>()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create entities</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: create entities</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.render.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize.bind(<span style="color: #008000; font-weight: bold">this</span>);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.addEventListener(<span style="color: #BA2121">'resize'</span>,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.resize);
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
<span style="color: #bbbbbb"> </span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>render()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
<span style="color: #bbbbbb"> </span>resize()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>resize()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: adjust viewport and canvas</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: adjust viewport and canvas</span>
|
||||||
<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>}
|
||||||
}<span style="color: #bbbbbb"></span>
|
}
|
||||||
|
|
||||||
Filament.init([<span style="color: #BA2121">'triangle.filamat'</span>],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.app<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>App()<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"> </span>);<span style="color: #bbbbbb"></span>
|
Filament.init([<span style="color: #BA2121">'triangle.filamat'</span>],<span style="color: #BBB"> </span>()<span style="color: #BBB"> </span>=><span style="color: #BBB"> </span>{<span style="color: #BBB"> </span><span style="color: #008000">window</span>.app<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span>App()<span style="color: #BBB"> </span>}<span style="color: #BBB"> </span>);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The two calls to <code>bind()</code> allow us to pass instance methods as callbacks for animation and resize
|
<p>The two calls to <code>bind()</code> allow us to pass instance methods as callbacks for animation and resize
|
||||||
events.</p>
|
events.</p>
|
||||||
<p><code>Filament.init()</code> consumes two things: a list of asset URLs and a callback.</p>
|
<p><code>Filament.init()</code> consumes two things: a list of asset URLs and a callback.</p>
|
||||||
<p>The callback will be triggered only after all assets finish downloading and the Filament module has
|
<p>The callback will be triggered only after all assets finish downloading and the Filament module has
|
||||||
become ready. In our callback, we simply instantiated the <code>App</code> object, since we'll do most of the
|
become ready. In our callback, we simply instantiated the <code>App</code> object, since we'll do most of the
|
||||||
work in its constructor. We also set the app instance into a <code>Window</code> property to make it accessible
|
work in its constructor. We also set the app instance into a <code>Window</code> property to make it accessible
|
||||||
from the developer console.</p>
|
from the developer console.</p>
|
||||||
<p>Go ahead and download <a href="triangle.filamat">triangle.filamat</a> and place it in your project folder.
|
<p>Go ahead and download <a href="triangle.filamat">triangle.filamat</a> and place it in your project folder.
|
||||||
This is a <em>material package</em>, which is a binary file that contains shaders and other bits of data
|
This is a <em>material package</em>, which is a binary file that contains shaders and other bits of data
|
||||||
that define a PBR material. We'll learn more about material packages in the next tutorial.</p>
|
that define a PBR material. We'll learn more about material packages in the next tutorial.</p>
|
||||||
<h2>Spawn a local server</h2>
|
<h2>Spawn a local server</h2>
|
||||||
<p>Because of CORS restrictions, your web app cannot fetch the material package directly from the
|
<p>Because of CORS restrictions, your web app cannot fetch the material package directly from the
|
||||||
file system. One way around this is to create a temporary server using Python or node:</p>
|
file system. One way around this is to create a temporary server using Python or node:</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>python3 -m http.server <span style="color: #3D7B7B; font-style: italic"># Python 3</span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>python3<span style="color: #BBB"> </span>-m<span style="color: #BBB"> </span>http.server<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic"># Python 3</span>
|
||||||
python -m SimpleHTTPServer <span style="color: #3D7B7B; font-style: italic"># Python 2.7</span>
|
python<span style="color: #BBB"> </span>-m<span style="color: #BBB"> </span>SimpleHTTPServer<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic"># Python 2.7</span>
|
||||||
npx http-server -p <span style="color: #666666">8000</span> <span style="color: #3D7B7B; font-style: italic"># nodejs</span>
|
npx<span style="color: #BBB"> </span>http-server<span style="color: #BBB"> </span>-p<span style="color: #BBB"> </span><span style="color: #666">8000</span><span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic"># nodejs</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>To see if this works, navigate to <a href="http://localhost:8000">http://localhost:8000</a> and check if you
|
<p>To see if this works, navigate to <a href="http://localhost:8000">http://localhost:8000</a> and check if you
|
||||||
can load the page without any errors appearing in the developer console.</p>
|
can load the page without any errors appearing in the developer console.</p>
|
||||||
<p>Take care not to use Python's simple server in production since it does not serve WebAssembly files
|
<p>Take care not to use Python's simple server in production since it does not serve WebAssembly files
|
||||||
with the correct MIME type.</p>
|
with the correct MIME type.</p>
|
||||||
<h2>Create the Engine and Scene</h2>
|
<h2>Create the Engine and Scene</h2>
|
||||||
<p>We now have a basic skeleton that can respond to paint and resize events. Let's start adding
|
<p>We now have a basic skeleton that can respond to paint and resize events. Let's start adding
|
||||||
Filament objects to the app. Insert the following code into the top of the app constructor.</p>
|
Filament objects to the app. Insert the following code into the top of the app constructor.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666666">0</span>];<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.canvas<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">document</span>.getElementsByTagName(<span style="color: #BA2121">'canvas'</span>)[<span style="color: #666">0</span>];
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Engine.create(<span style="color: #008000; font-weight: bold">this</span>.canvas);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Engine.create(<span style="color: #008000; font-weight: bold">this</span>.canvas);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The above snippet creates the <code>Engine</code> by passing it a canvas DOM object. The engine needs the
|
<p>The above snippet creates the <code>Engine</code> by passing it a canvas DOM object. The engine needs the
|
||||||
canvas in order to create a WebGL 2.0 context in its contructor.</p>
|
canvas in order to create a WebGL 2.0 context in its contructor.</p>
|
||||||
<p>The engine is a factory for many Filament entities, including <code>Scene</code>, which is a flat container of
|
<p>The engine is a factory for many Filament entities, including <code>Scene</code>, which is a flat container of
|
||||||
entities. Let's go ahead and create a scene, then add a blank entity called <code>triangle</code> into the
|
entities. Let's go ahead and create a scene, then add a blank entity called <code>triangle</code> into the
|
||||||
scene.</p>
|
scene.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createScene();<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.scene<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createScene();
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.triangle<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.EntityManager.get().create();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.triangle<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.EntityManager.get().create();
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.triangle);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.scene.addEntity(<span style="color: #008000; font-weight: bold">this</span>.triangle);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Filament uses an <a href="//en.wikipedia.org/wiki/Entity-component-system">Entity-Component System</a>.
|
<p>Filament uses an <a href="//en.wikipedia.org/wiki/Entity-component-system">Entity-Component System</a>.
|
||||||
@@ -112,30 +112,30 @@ The triangle entity in the above snippet does not yet have an associated compone
|
|||||||
tutorial we will make it into a <em>renderable</em>. Renderables are entities that have associated draw
|
tutorial we will make it into a <em>renderable</em>. Renderables are entities that have associated draw
|
||||||
calls.</p>
|
calls.</p>
|
||||||
<h2>Construct typed arrays</h2>
|
<h2>Construct typed arrays</h2>
|
||||||
<p>Next we'll create two typed arrays: a positions array with XY coordinates for each vertex, and a
|
<p>Next we'll create two typed arrays: a positions array with XY coordinates for each vertex, and a
|
||||||
colors array with a 32-bit word for each vertex.</p>
|
colors array with a 32-bit word for each vertex.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>TRIANGLE_POSITIONS<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Float32Array</span>([<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>TRIANGLE_POSITIONS<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span><span style="color: #008000">Float32Array</span>([
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">2</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">2</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">2</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">2</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">4</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span><span style="color: #666666">4</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.cos(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">4</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),<span style="color: #BBB"> </span><span style="color: #008000">Math</span>.sin(<span style="color: #008000">Math</span>.PI<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span><span style="color: #666">4</span><span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">3</span>),
|
||||||
]);<span style="color: #bbbbbb"></span>
|
]);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>TRIANGLE_COLORS<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Uint32Array</span>([<span style="color: #666666">0xffff0000</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0xff00ff00</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0xff0000ff</span>]);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>TRIANGLE_COLORS<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span><span style="color: #008000">Uint32Array</span>([<span style="color: #666">0xffff0000</span>,<span style="color: #BBB"> </span><span style="color: #666">0xff00ff00</span>,<span style="color: #BBB"> </span><span style="color: #666">0xff0000ff</span>]);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next we'll use the positions and colors buffers to create a single <code>VertexBuffer</code> object.</p>
|
<p>Next we'll use the positions and colors buffers to create a single <code>VertexBuffer</code> object.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>VertexAttribute<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexAttribute;<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>VertexAttribute<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexAttribute;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>AttributeType<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer$AttributeType;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>AttributeType<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer$AttributeType;
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.vb<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.VertexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.vb<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.VertexBuffer.Builder()
|
||||||
<span style="color: #bbbbbb"> </span>.vertexCount(<span style="color: #666666">3</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.vertexCount(<span style="color: #666">3</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.bufferCount(<span style="color: #666666">2</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.bufferCount(<span style="color: #666">2</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>AttributeType.FLOAT2,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">8</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.attribute(VertexAttribute.POSITION,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>AttributeType.FLOAT2,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">8</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.attribute(VertexAttribute.COLOR,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>AttributeType.UBYTE4,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">4</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.attribute(VertexAttribute.COLOR,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>AttributeType.UBYTE4,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">4</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.normalized(VertexAttribute.COLOR)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.normalized(VertexAttribute.COLOR)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>TRIANGLE_POSITIONS);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>TRIANGLE_POSITIONS);
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span>TRIANGLE_COLORS);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.vb.setBufferAt(engine,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span>TRIANGLE_COLORS);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The above snippet first creates aliases for two enum types, then constructs the vertex buffer using
|
<p>The above snippet first creates aliases for two enum types, then constructs the vertex buffer using
|
||||||
@@ -147,74 +147,74 @@ self-documenting.</p>
|
|||||||
<p>Our app sets up two buffer slots in the vertex buffer, and each slot is associated with a single
|
<p>Our app sets up two buffer slots in the vertex buffer, and each slot is associated with a single
|
||||||
attribute. Alternatively, we could have interleaved or concatenated these attributes into a single
|
attribute. Alternatively, we could have interleaved or concatenated these attributes into a single
|
||||||
buffer slot.</p>
|
buffer slot.</p>
|
||||||
<p>Next we'll construct an index buffer. The index buffer for our triangle is trivial: it simply holds
|
<p>Next we'll construct an index buffer. The index buffer for our triangle is trivial: it simply holds
|
||||||
the integers 0,1,2.</p>
|
the integers 0,1,2.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.ib<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.IndexBuffer.Builder()<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.ib<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.IndexBuffer.Builder()
|
||||||
<span style="color: #bbbbbb"> </span>.indexCount(<span style="color: #666666">3</span>)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.indexCount(<span style="color: #666">3</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.bufferType(Filament.IndexBuffer$IndexType.USHORT)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.bufferType(Filament.IndexBuffer$IndexType.USHORT)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.ib.setBuffer(engine,<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Uint16Array</span>([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">2</span>]));<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.ib.setBuffer(engine,<span style="color: #BBB"> </span><span style="color: #A2F; font-weight: bold">new</span><span style="color: #BBB"> </span><span style="color: #008000">Uint16Array</span>([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">2</span>]));
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Note that constructing an index buffer is similar to constructing a vertex buffer, but it only has
|
<p>Note that constructing an index buffer is similar to constructing a vertex buffer, but it only has
|
||||||
one buffer slot, and it can only contain two types of data (USHORT or UINT).</p>
|
one buffer slot, and it can only contain two types of data (USHORT or UINT).</p>
|
||||||
<h2>Finish up initialization</h2>
|
<h2>Finish up initialization</h2>
|
||||||
<p>Next let's construct an actual <code>Material</code> from the material package that was downloaded (the
|
<p>Next let's construct an actual <code>Material</code> from the material package that was downloaded (the
|
||||||
material is an object; the package is just a binary blob), then extract the default
|
material is an object; the package is just a binary blob), then extract the default
|
||||||
<code>MaterialInstance</code> from the material object. Material instances have concrete values for their
|
<code>MaterialInstance</code> from the material object. Material instances have concrete values for their
|
||||||
parameters, and they can be bound to renderables. We'll learn more about material instances in the
|
parameters, and they can be bound to renderables. We'll learn more about material instances in the
|
||||||
next tutorial.</p>
|
next tutorial.</p>
|
||||||
<p>After extracting the material instance, we can finally create a renderable component for the
|
<p>After extracting the material instance, we can finally create a renderable component for the
|
||||||
triangle by setting up a bounding box and passing in the vertex and index buffers.</p>
|
triangle by setting up a bounding box and passing in the vertex and index buffers.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>mat<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createMaterial(<span style="color: #BA2121">'triangle.filamat'</span>);<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>mat<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createMaterial(<span style="color: #BA2121">'triangle.filamat'</span>);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>matinst<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>mat.getDefaultInstance();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>matinst<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>mat.getDefaultInstance();
|
||||||
Filament.RenderableManager.Builder(<span style="color: #666666">1</span>)<span style="color: #bbbbbb"></span>
|
Filament.RenderableManager.Builder(<span style="color: #666">1</span>)
|
||||||
<span style="color: #bbbbbb"> </span>.boundingBox({<span style="color: #bbbbbb"> </span>center<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>],<span style="color: #bbbbbb"> </span>halfExtent<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>]<span style="color: #bbbbbb"> </span>})<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.boundingBox({<span style="color: #BBB"> </span>center<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">-1</span>],<span style="color: #BBB"> </span>halfExtent<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>]<span style="color: #BBB"> </span>})
|
||||||
<span style="color: #bbbbbb"> </span>.material(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>matinst)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.material(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>matinst)
|
||||||
<span style="color: #bbbbbb"> </span>.geometry(<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>Filament.RenderableManager$PrimitiveType.TRIANGLES,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.vb,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.ib)<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.geometry(<span style="color: #666">0</span>,<span style="color: #BBB"> </span>Filament.RenderableManager$PrimitiveType.TRIANGLES,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.vb,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.ib)
|
||||||
<span style="color: #bbbbbb"> </span>.build(engine,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.triangle);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span>.build(engine,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.triangle);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Next let's wrap up the initialization routine by creating the swap chain, renderer, camera, and
|
<p>Next let's wrap up the initialization routine by creating the swap chain, renderer, camera, and
|
||||||
view.</p>
|
view.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createSwapChain();<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">this</span>.swapChain<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createSwapChain();
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createRenderer();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.renderer<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createRenderer();
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createCamera(Filament.EntityManager.get().create());<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.camera<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createCamera(Filament.EntityManager.get().create());
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>engine.createView();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.view<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>engine.createView();
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.view.setCamera(<span style="color: #008000; font-weight: bold">this</span>.camera);
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.view.setScene(<span style="color: #008000; font-weight: bold">this</span>.scene);
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Set up a blue-green background:</span><span style="color: #bbbbbb"></span>
|
<span style="color: #3D7B7B; font-style: italic">// Set up a blue-green background:</span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.renderer.setClearOptions({clearColor<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span>[<span style="color: #666666">0.0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0.2</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1.0</span>],<span style="color: #bbbbbb"> </span>clear<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">true</span>});<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.renderer.setClearOptions({clearColor<span style="color: #666">:</span><span style="color: #BBB"> </span>[<span style="color: #666">0.0</span>,<span style="color: #BBB"> </span><span style="color: #666">0.1</span>,<span style="color: #BBB"> </span><span style="color: #666">0.2</span>,<span style="color: #BBB"> </span><span style="color: #666">1.0</span>],<span style="color: #BBB"> </span>clear<span style="color: #666">:</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">true</span>});
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Adjust the initial viewport:</span><span style="color: #bbbbbb"></span>
|
<span style="color: #3D7B7B; font-style: italic">// Adjust the initial viewport:</span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.resize();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.resize();
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>At this point, we're done creating all Filament entities, and the code should run without errors.
|
<p>At this point, we're done creating all Filament entities, and the code should run without errors.
|
||||||
However the canvas is still blank!</p>
|
However the canvas is still blank!</p>
|
||||||
<h2>Render and resize handlers</h2>
|
<h2>Render and resize handlers</h2>
|
||||||
<p>Recall that our App class has a skeletal render method, which the browser calls every time it needs
|
<p>Recall that our App class has a skeletal render method, which the browser calls every time it needs
|
||||||
to repaint. Often this is 60 times a second.</p>
|
to repaint. Often this is 60 times a second.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>render()<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>render()<span style="color: #BBB"> </span>{
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span><span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #3D7B7B; font-style: italic">// TODO: render scene</span>
|
||||||
<span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);<span style="color: #bbbbbb"></span>
|
<span style="color: #BBB"> </span><span style="color: #008000">window</span>.requestAnimationFrame(<span style="color: #008000; font-weight: bold">this</span>.render);
|
||||||
}<span style="color: #bbbbbb"></span>
|
}
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>Let's flesh this out by rotating the triangle and invoking the Filament renderer. Add the following
|
<p>Let's flesh this out by rotating the triangle and invoking the Filament renderer. Add the following
|
||||||
code to the top of the render method.</p>
|
code to the top of the render method.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// Rotate the triangle.</span><span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">// Rotate the triangle.</span>
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>radians<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">Date</span>.now()<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span><span style="color: #666666">1000</span>;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>radians<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">Date</span>.now()<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span><span style="color: #666">1000</span>;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>transform<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>mat4.fromRotation(mat4.create(),<span style="color: #bbbbbb"> </span>radians,<span style="color: #bbbbbb"> </span>[<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>]);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>transform<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>mat4.fromRotation(mat4.create(),<span style="color: #BBB"> </span>radians,<span style="color: #BBB"> </span>[<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>]);
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>tcm<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>tcm<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.getTransformManager();
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>inst<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.triangle);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>inst<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>tcm.getInstance(<span style="color: #008000; font-weight: bold">this</span>.triangle);
|
||||||
tcm.setTransform(inst,<span style="color: #bbbbbb"> </span>transform);<span style="color: #bbbbbb"></span>
|
tcm.setTransform(inst,<span style="color: #BBB"> </span>transform);
|
||||||
inst.<span style="color: #AA22FF; font-weight: bold">delete</span>();<span style="color: #bbbbbb"></span>
|
inst.<span style="color: #A2F; font-weight: bold">delete</span>();
|
||||||
|
|
||||||
<span style="color: #3D7B7B; font-style: italic">// Render the frame.</span><span style="color: #bbbbbb"></span>
|
<span style="color: #3D7B7B; font-style: italic">// Render the frame.</span>
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.view);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.renderer.render(<span style="color: #008000; font-weight: bold">this</span>.swapChain,<span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.view);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>The first half of our render method obtains the transform component of the triangle entity and uses
|
<p>The first half of our render method obtains the transform component of the triangle entity and uses
|
||||||
@@ -225,19 +225,19 @@ that it wants to skip a frame, hence the <code>if</code> statement.</p>
|
|||||||
<p>One last step. Add the following code to the resize method. This adjusts the resolution of the
|
<p>One last step. Add the following code to the resize method. This adjusts the resolution of the
|
||||||
rendering surface when the window size changes, taking <code>devicePixelRatio</code> into account for high-DPI
|
rendering surface when the window size changes, taking <code>devicePixelRatio</code> into account for high-DPI
|
||||||
displays. It also adjusts the camera frustum accordingly.</p>
|
displays. It also adjusts the camera frustum accordingly.</p>
|
||||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>dpr<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.devicePixelRatio;<span style="color: #bbbbbb"></span>
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>dpr<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.devicePixelRatio;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.width<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerWidth<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #bbbbbb"> </span><span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>dpr;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000; font-weight: bold">this</span>.canvas.height<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span><span style="color: #008000">window</span>.innerHeight<span style="color: #BBB"> </span><span style="color: #666">*</span><span style="color: #BBB"> </span>dpr;
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span>width,<span style="color: #bbbbbb"> </span>height]);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.view.setViewport([<span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span>width,<span style="color: #BBB"> </span>height]);
|
||||||
|
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>aspect<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>width<span style="color: #bbbbbb"> </span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>height;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>aspect<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>width<span style="color: #BBB"> </span><span style="color: #666">/</span><span style="color: #BBB"> </span>height;
|
||||||
<span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>Projection<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span>Filament.Camera$Projection;<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">const</span><span style="color: #BBB"> </span>Projection<span style="color: #BBB"> </span><span style="color: #666">=</span><span style="color: #BBB"> </span>Filament.Camera$Projection;
|
||||||
<span style="color: #008000; font-weight: bold">this</span>.camera.setProjection(Projection.ORTHO,<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>aspect,<span style="color: #bbbbbb"> </span>aspect,<span style="color: #bbbbbb"> </span><span style="color: #666666">-1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">1</span>);<span style="color: #bbbbbb"></span>
|
<span style="color: #008000; font-weight: bold">this</span>.camera.setProjection(Projection.ORTHO,<span style="color: #BBB"> </span><span style="color: #666">-</span>aspect,<span style="color: #BBB"> </span>aspect,<span style="color: #BBB"> </span><span style="color: #666">-1</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>,<span style="color: #BBB"> </span><span style="color: #666">0</span>,<span style="color: #BBB"> </span><span style="color: #666">1</span>);
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>You should now have a spinning triangle! The completed JavaScript is available
|
<p>You should now have a spinning triangle! The completed JavaScript is available
|
||||||
<a href="tutorial_triangle.js">here</a>.</p>
|
<a href="tutorial_triangle.js">here</a>.</p>
|
||||||
<p>In the <a href="tutorial_redball.html">next tutorial</a>, we'll take a closer look at Filament materials and 3D rendering.</p>
|
<p>In the <a href="tutorial_redball.html">next tutorial</a>, we'll take a closer look at Filament materials and 3D rendering.</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -318,6 +318,13 @@ if (WIN32 AND FILAMENT_SUPPORTS_WEBGPU)
|
|||||||
target_compile_definitions(${TARGET} PRIVATE "WGPU_IMPLEMENTATION")
|
target_compile_definitions(${TARGET} PRIVATE "WGPU_IMPLEMENTATION")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# enable OpenGL init warnings for the optimized build
|
||||||
|
if(FILAMENT_ENABLE_INIT_GL_WARNINGS_FOR_OPTIMIZED_BUILD)
|
||||||
|
target_compile_definitions(${TARGET} PRIVATE "FILAMENT_ENABLE_INIT_GL_WARNINGS_FOR_OPTIMIZED_BUILD")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ==================================================================================================
|
# ==================================================================================================
|
||||||
# Expose a header-only target to minimize dependencies.
|
# Expose a header-only target to minimize dependencies.
|
||||||
# ==================================================================================================
|
# ==================================================================================================
|
||||||
|
|||||||
@@ -1455,6 +1455,11 @@ enum class Workaround : uint16_t {
|
|||||||
DISABLE_BLIT_INTO_TEXTURE_ARRAY,
|
DISABLE_BLIT_INTO_TEXTURE_ARRAY,
|
||||||
// Multiple workarounds needed for PowerVR GPUs
|
// Multiple workarounds needed for PowerVR GPUs
|
||||||
POWER_VR_SHADER_WORKAROUNDS,
|
POWER_VR_SHADER_WORKAROUNDS,
|
||||||
|
// Some browsers, such as Firefox on Mac, struggle with slow shader compile/link times when
|
||||||
|
// creating programs for the default material, leading to startup stutters. This workaround
|
||||||
|
// prevents these stutters by not precaching depth variants of the default material for those
|
||||||
|
// particular browsers.
|
||||||
|
DISABLE_DEPTH_PRECACHE_FOR_DEFAULT_MATERIAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
using StereoscopicType = backend::Platform::StereoscopicType;
|
using StereoscopicType = backend::Platform::StereoscopicType;
|
||||||
|
|||||||
@@ -50,6 +50,14 @@ void assertFramebufferStatus(utils::io::ostream& out, GLenum target, const char*
|
|||||||
# define CHECK_GL_FRAMEBUFFER_STATUS(out, target) { GLUtils::checkFramebufferStatus(out, target, __func__, __LINE__); }
|
# define CHECK_GL_FRAMEBUFFER_STATUS(out, target) { GLUtils::checkFramebufferStatus(out, target, __func__, __LINE__); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
# define CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(out) { GLUtils::assertGLError(out, __func__, __LINE__);}
|
||||||
|
#elif defined(FILAMENT_ENABLE_INIT_GL_WARNINGS_FOR_OPTIMIZED_BUILD)
|
||||||
|
# define CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(out) { GLUtils::checkGLError(out, __func__, __LINE__);}
|
||||||
|
#else
|
||||||
|
# define CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(out)
|
||||||
|
#endif
|
||||||
|
|
||||||
constexpr GLuint getComponentCount(ElementType const type) noexcept {
|
constexpr GLuint getComponentCount(ElementType const type) noexcept {
|
||||||
using ElementType = ElementType;
|
using ElementType = ElementType;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ bool OpenGLContext::queryOpenGLVersion(GLint* major, GLint* minor) noexcept {
|
|||||||
// OpenGL version
|
// OpenGL version
|
||||||
glGetIntegerv(GL_MAJOR_VERSION, major);
|
glGetIntegerv(GL_MAJOR_VERSION, major);
|
||||||
glGetIntegerv(GL_MINOR_VERSION, minor);
|
glGetIntegerv(GL_MINOR_VERSION, minor);
|
||||||
|
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
|
|
||||||
return (glGetError() == GL_NO_ERROR);
|
return (glGetError() == GL_NO_ERROR);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -109,6 +112,8 @@ OpenGLContext::OpenGLContext(OpenGLPlatform& platform,
|
|||||||
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &gets.max_3d_texture_size);
|
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &gets.max_3d_texture_size);
|
||||||
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &gets.max_array_texture_layers);
|
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &gets.max_array_texture_layers);
|
||||||
|
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
|
|
||||||
mFeatureLevel = resolveFeatureLevel(state.major, state.minor, ext, gets, bugs);
|
mFeatureLevel = resolveFeatureLevel(state.major, state.minor, ext, gets, bugs);
|
||||||
|
|
||||||
#ifdef BACKEND_OPENGL_VERSION_GLES
|
#ifdef BACKEND_OPENGL_VERSION_GLES
|
||||||
@@ -149,6 +154,7 @@ OpenGLContext::OpenGLContext(OpenGLPlatform& platform,
|
|||||||
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
|
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
|
||||||
&gets.uniform_buffer_offset_alignment);
|
&gets.uniform_buffer_offset_alignment);
|
||||||
#endif
|
#endif
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BACKEND_OPENGL_VERSION_GLES
|
#ifdef BACKEND_OPENGL_VERSION_GLES
|
||||||
@@ -235,6 +241,7 @@ OpenGLContext::OpenGLContext(OpenGLPlatform& platform,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
|
|
||||||
// in practice KHR_Debug has never been useful, and actually is confusing. We keep this
|
// in practice KHR_Debug has never been useful, and actually is confusing. We keep this
|
||||||
// only for our own debugging, in case we need it some day.
|
// only for our own debugging, in case we need it some day.
|
||||||
@@ -269,6 +276,7 @@ OpenGLContext::OpenGLContext(OpenGLPlatform& platform,
|
|||||||
glDebugMessageCallback(cb, nullptr);
|
glDebugMessageCallback(cb, nullptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
|
|
||||||
mTimerQueryFactory = TimerQueryFactory::init(platform, *this);
|
mTimerQueryFactory = TimerQueryFactory::init(platform, *this);
|
||||||
}
|
}
|
||||||
@@ -384,6 +392,8 @@ void OpenGLContext::setDefaultState() noexcept {
|
|||||||
glEnable(GL_CLIP_DISTANCE0);
|
glEnable(GL_CLIP_DISTANCE0);
|
||||||
glEnable(GL_CLIP_DISTANCE1);
|
glEnable(GL_CLIP_DISTANCE1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -600,6 +610,12 @@ void OpenGLContext::initBugs(Bugs* bugs, Extensions const& exts,
|
|||||||
// For Mozilla, the issue appears to be observed regardless of whether the renderer is
|
// For Mozilla, the issue appears to be observed regardless of whether the renderer is
|
||||||
// ANGLE or not. (b/376125497)
|
// ANGLE or not. (b/376125497)
|
||||||
bugs->rebind_buffer_after_deletion = true;
|
bugs->rebind_buffer_after_deletion = true;
|
||||||
|
|
||||||
|
// We disable depth precache for the default material on Mozilla FireFox. It struggles with
|
||||||
|
// slow shader compile/link times if the shader contains large arrays of uniform. Some depth
|
||||||
|
// program variants have skinning-related data, which incurs this slowness and end up
|
||||||
|
// causing an initial startup stalls. (b/392917621)
|
||||||
|
bugs->disable_depth_precache_for_default_material = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BACKEND_OPENGL_VERSION_GLES
|
#ifdef BACKEND_OPENGL_VERSION_GLES
|
||||||
@@ -755,6 +771,8 @@ void OpenGLContext::initExtensionsGLES(Extensions* ext, GLint major, GLint minor
|
|||||||
ext->EXT_discard_framebuffer = true;
|
ext->EXT_discard_framebuffer = true;
|
||||||
ext->OES_vertex_array_object = true;
|
ext->OES_vertex_array_object = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_VERSION_GLES
|
#endif // BACKEND_OPENGL_VERSION_GLES
|
||||||
@@ -825,6 +843,8 @@ void OpenGLContext::initExtensionsGL(Extensions* ext, GLint major, GLint minor)
|
|||||||
if (major > 4 || (major == 4 && minor >= 5)) {
|
if (major > 4 || (major == 4 && minor >= 5)) {
|
||||||
ext->EXT_clip_control = true;
|
ext->EXT_clip_control = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK_GL_INIT_ERROR_FOR_OPTIMIZED_BUILD(utils::slog.e)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_VERSION_GL
|
#endif // BACKEND_OPENGL_VERSION_GL
|
||||||
|
|||||||
@@ -328,6 +328,11 @@ public:
|
|||||||
// bugs or performance issues.
|
// bugs or performance issues.
|
||||||
bool force_feature_level0;
|
bool force_feature_level0;
|
||||||
|
|
||||||
|
// Some browsers, such as Firefox on Mac, struggle with slow shader compile/link times when
|
||||||
|
// creating programs for the default material, leading to startup stutters. This workaround
|
||||||
|
// prevents these stutters by not precaching depth variants of the default material for
|
||||||
|
// those particular browsers.
|
||||||
|
bool disable_depth_precache_for_default_material;
|
||||||
|
|
||||||
} bugs = {};
|
} bugs = {};
|
||||||
|
|
||||||
@@ -569,6 +574,9 @@ private:
|
|||||||
{ bugs.force_feature_level0,
|
{ bugs.force_feature_level0,
|
||||||
"force_feature_level0",
|
"force_feature_level0",
|
||||||
""},
|
""},
|
||||||
|
{ bugs.disable_depth_precache_for_default_material,
|
||||||
|
"disable_depth_precache_for_default_material",
|
||||||
|
""},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// this is chosen to minimize code size
|
// this is chosen to minimize code size
|
||||||
|
|||||||
@@ -2435,6 +2435,8 @@ bool OpenGLDriver::isWorkaroundNeeded(Workaround workaround) {
|
|||||||
return mContext.bugs.disable_blit_into_texture_array;
|
return mContext.bugs.disable_blit_into_texture_array;
|
||||||
case Workaround::POWER_VR_SHADER_WORKAROUNDS:
|
case Workaround::POWER_VR_SHADER_WORKAROUNDS:
|
||||||
return mContext.bugs.powervr_shader_workarounds;
|
return mContext.bugs.powervr_shader_workarounds;
|
||||||
|
case Workaround::DISABLE_DEPTH_PRECACHE_FOR_DEFAULT_MATERIAL:
|
||||||
|
return mContext.bugs.disable_depth_precache_for_default_material;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,7 +292,22 @@ void WebGPUDriver::endFrame(uint32_t frameId) {
|
|||||||
void WebGPUDriver::flush(int) {
|
void WebGPUDriver::flush(int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::finish(int) {
|
void WebGPUDriver::finish(int /* dummy */) {
|
||||||
|
if (mCommandEncoder != nullptr) {
|
||||||
|
// submit the command buffer thus far...
|
||||||
|
assert_invariant(mRenderPassEncoder == nullptr);
|
||||||
|
wgpu::CommandBufferDescriptor commandBufferDescriptor{
|
||||||
|
.label = "command_buffer",
|
||||||
|
};
|
||||||
|
mCommandBuffer = mCommandEncoder.Finish(&commandBufferDescriptor);
|
||||||
|
assert_invariant(mCommandBuffer);
|
||||||
|
mQueue.Submit(1, &mCommandBuffer);
|
||||||
|
mCommandBuffer = nullptr;
|
||||||
|
// create a new command buffer encoder to continue recording the next command for frame...
|
||||||
|
wgpu::CommandEncoderDescriptor commandEncoderDescriptor = { .label = "command_encoder" };
|
||||||
|
mCommandEncoder = mDevice.CreateCommandEncoder(&commandEncoderDescriptor);
|
||||||
|
assert_invariant(mCommandEncoder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::destroyRenderPrimitive(Handle<HwRenderPrimitive> rph) {
|
void WebGPUDriver::destroyRenderPrimitive(Handle<HwRenderPrimitive> rph) {
|
||||||
@@ -746,12 +761,7 @@ void WebGPUDriver::compilePrograms(CompilerPriorityQueue priority,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, const RenderPassParams& params) {
|
void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, const RenderPassParams& params) {
|
||||||
wgpu::CommandEncoderDescriptor commandEncoderDescriptor = {
|
|
||||||
.label = "command_encoder"
|
|
||||||
};
|
|
||||||
mCommandEncoder = mDevice.CreateCommandEncoder(&commandEncoderDescriptor);
|
|
||||||
assert_invariant(mCommandEncoder);
|
assert_invariant(mCommandEncoder);
|
||||||
|
|
||||||
// TODO: Remove this code once WebGPU pipeline is implemented
|
// TODO: Remove this code once WebGPU pipeline is implemented
|
||||||
static float red = 1.0f;
|
static float red = 1.0f;
|
||||||
if (red - 0.01 > 0) {
|
if (red - 0.01 > 0) {
|
||||||
@@ -781,14 +791,9 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, const RenderPassP
|
|||||||
params.viewport.width, params.viewport.height, params.depthRange.near, params.depthRange.far);
|
params.viewport.width, params.viewport.height, params.depthRange.near, params.depthRange.far);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::endRenderPass(int) {
|
void WebGPUDriver::endRenderPass(int /* dummy */) {
|
||||||
mRenderPassEncoder.End();
|
mRenderPassEncoder.End();
|
||||||
mRenderPassEncoder = nullptr;
|
mRenderPassEncoder = nullptr;
|
||||||
wgpu::CommandBufferDescriptor commandBufferDescriptor {
|
|
||||||
.label = "command_buffer",
|
|
||||||
};
|
|
||||||
mCommandBuffer = mCommandEncoder.Finish(&commandBufferDescriptor);
|
|
||||||
assert_invariant(mCommandBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::nextSubpass(int) {
|
void WebGPUDriver::nextSubpass(int) {
|
||||||
@@ -803,9 +808,19 @@ void WebGPUDriver::makeCurrent(Handle<HwSwapChain> drawSch, Handle<HwSwapChain>
|
|||||||
wgpu::Extent2D surfaceSize = mPlatform.getSurfaceExtent(mNativeWindow);
|
wgpu::Extent2D surfaceSize = mPlatform.getSurfaceExtent(mNativeWindow);
|
||||||
mTextureView = mSwapChain->getCurrentSurfaceTextureView(surfaceSize);
|
mTextureView = mSwapChain->getCurrentSurfaceTextureView(surfaceSize);
|
||||||
assert_invariant(mTextureView);
|
assert_invariant(mTextureView);
|
||||||
|
wgpu::CommandEncoderDescriptor commandEncoderDescriptor = {
|
||||||
|
.label = "command_encoder"
|
||||||
|
};
|
||||||
|
mCommandEncoder = mDevice.CreateCommandEncoder(&commandEncoderDescriptor);
|
||||||
|
assert_invariant(mCommandEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::commit(Handle<HwSwapChain> sch) {
|
void WebGPUDriver::commit(Handle<HwSwapChain> sch) {
|
||||||
|
wgpu::CommandBufferDescriptor commandBufferDescriptor{
|
||||||
|
.label = "command_buffer",
|
||||||
|
};
|
||||||
|
mCommandBuffer = mCommandEncoder.Finish(&commandBufferDescriptor);
|
||||||
|
assert_invariant(mCommandBuffer);
|
||||||
mCommandEncoder = nullptr;
|
mCommandEncoder = nullptr;
|
||||||
mQueue.Submit(1, &mCommandBuffer);
|
mQueue.Submit(1, &mCommandBuffer);
|
||||||
mCommandBuffer = nullptr;
|
mCommandBuffer = nullptr;
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
#include "backend/Handle.h"
|
#include "backend/Handle.h"
|
||||||
#include "backend/DriverApiForward.h"
|
#include "backend/DriverApiForward.h"
|
||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
@@ -71,6 +74,7 @@ private:
|
|||||||
|
|
||||||
template <typename HandleType>
|
template <typename HandleType>
|
||||||
filament::backend::Handle<HandleType> Cleanup::add(filament::backend::Handle<HandleType> handle) {
|
filament::backend::Handle<HandleType> Cleanup::add(filament::backend::Handle<HandleType> handle) {
|
||||||
|
EXPECT_THAT(handle, ::testing::IsTrue()) << "Added a null handle to clean up.";
|
||||||
addInternal(handle);
|
addInternal(handle);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ Shader::Shader(DriverApi& api, Cleanup& cleanup, ShaderConfig config) : mCleanup
|
|||||||
// This assumes that the uniforms will all be in a single descriptor set at index 1.
|
// This assumes that the uniforms will all be in a single descriptor set at index 1.
|
||||||
// If there are shaders with uniforms in other sets then ShaderConfig will need to be expanded
|
// If there are shaders with uniforms in other sets then ShaderConfig will need to be expanded
|
||||||
// to accommodate that.
|
// to accommodate that.
|
||||||
size_t kDescriptorSetIndex = 1;
|
size_t kDescriptorSetIndex = 0;
|
||||||
filamat::DescriptorSets descriptors;
|
filamat::DescriptorSets descriptors;
|
||||||
descriptors[kDescriptorSetIndex] = filamat::DescriptorSetInfo(config.uniforms.size());
|
descriptors[kDescriptorSetIndex] = filamat::DescriptorSetInfo(config.uniforms.size());
|
||||||
for (unsigned char i = 0; i < config.uniforms.size(); ++i) {
|
for (unsigned char i = 0; i < config.uniforms.size(); ++i) {
|
||||||
@@ -52,7 +52,7 @@ Shader::Shader(DriverApi& api, Cleanup& cleanup, ShaderConfig config) : mCleanup
|
|||||||
config.uniforms[i].name,
|
config.uniforms[i].name,
|
||||||
config.uniforms[i].type.value_or(DescriptorType::UNIFORM_BUFFER), i };
|
config.uniforms[i].type.value_or(DescriptorType::UNIFORM_BUFFER), i };
|
||||||
}
|
}
|
||||||
prog.descriptorBindings(1, bindingsInfo);
|
prog.descriptorBindings(0, bindingsInfo);
|
||||||
mProgram = cleanup.add(api.createProgram(std::move(prog)));
|
mProgram = cleanup.add(api.createProgram(std::move(prog)));
|
||||||
|
|
||||||
if (!kLayouts.empty()) {
|
if (!kLayouts.empty()) {
|
||||||
@@ -66,10 +66,15 @@ filament::backend::DescriptorSetHandle Shader::createDescriptorSet(DriverApi& ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
filament::backend::ProgramHandle Shader::getProgram() const {
|
filament::backend::ProgramHandle Shader::getProgram() const {
|
||||||
|
assert(mProgram);
|
||||||
|
EXPECT_THAT(mProgram, ::testing::IsTrue())
|
||||||
|
<< "Shader program accessed despite being null.";
|
||||||
return mProgram;
|
return mProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
filament::backend::DescriptorSetLayoutHandle Shader::getDescriptorSetLayout() const {
|
filament::backend::DescriptorSetLayoutHandle Shader::getDescriptorSetLayout() const {
|
||||||
|
EXPECT_THAT(mDescriptorSetLayout, ::testing::IsTrue())
|
||||||
|
<< "Shader descriptor set layout accessed despite being null.";
|
||||||
return mDescriptorSetLayout;
|
return mDescriptorSetLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ ResolvedUniformBindingConfig UniformBindingConfig::resolve() {
|
|||||||
.dataSize = resolvedDataSize,
|
.dataSize = resolvedDataSize,
|
||||||
.bufferSize = bufferSize.value_or(resolvedDataSize),
|
.bufferSize = bufferSize.value_or(resolvedDataSize),
|
||||||
.byteOffset = byteOffset.value_or(0),
|
.byteOffset = byteOffset.value_or(0),
|
||||||
.set = set.value_or(1),
|
.set = set.value_or(0),
|
||||||
.binding = binding.value_or(0),
|
.binding = binding.value_or(0),
|
||||||
.descriptorSet = descriptorSet
|
.descriptorSet = descriptorSet
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ std::optional<std::string> GetGlslUniform(ShaderUniformType type) {
|
|||||||
}
|
}
|
||||||
case ShaderUniformType::Simple: {
|
case ShaderUniformType::Simple: {
|
||||||
return R"(
|
return R"(
|
||||||
layout(binding = 0, set = 1) uniform Params {
|
layout(binding = 0, set = 0) uniform Params {
|
||||||
highp vec4 color;
|
highp vec4 color;
|
||||||
// Use scaleMinusOne instead of scale so that a 0 initialized value is a good default
|
// Use scaleMinusOne instead of scale so that a 0 initialized value is a good default
|
||||||
highp vec4 scaleMinusOne;
|
highp vec4 scaleMinusOne;
|
||||||
@@ -148,7 +148,7 @@ layout(binding = 0, set = 1) uniform Params {
|
|||||||
}
|
}
|
||||||
case ShaderUniformType::SimpleWithPadding: {
|
case ShaderUniformType::SimpleWithPadding: {
|
||||||
return R"(
|
return R"(
|
||||||
layout(binding = 0, set = 1) uniform Params {
|
layout(binding = 0, set = 0) uniform Params {
|
||||||
highp vec4 padding[4]; // offset of 64 bytes
|
highp vec4 padding[4]; // offset of 64 bytes
|
||||||
|
|
||||||
highp vec4 color;
|
highp vec4 color;
|
||||||
@@ -160,7 +160,7 @@ layout(binding = 0, set = 1) uniform Params {
|
|||||||
}
|
}
|
||||||
case ShaderUniformType::Sampler: {
|
case ShaderUniformType::Sampler: {
|
||||||
return R"(
|
return R"(
|
||||||
layout(location = 0, set = 1) uniform sampler2D test_tex;
|
layout(location = 0, set = 0) uniform sampler2D test_tex;
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "BackendTest.h"
|
#include "BackendTest.h"
|
||||||
|
|
||||||
// skipEnvironment must be a test::SkipEnvironment
|
// skipEnvironment must be a test::SkipEnvironment or something that can be passed to the type's
|
||||||
|
// constructor
|
||||||
// rationale must be a string
|
// rationale must be a string
|
||||||
#define SKIP_IF(skipEnvironment, rationale) \
|
#define SKIP_IF(skipEnvironment, rationale) \
|
||||||
do { \
|
do { \
|
||||||
@@ -31,6 +32,17 @@ do {
|
|||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
#define FAIL_IF(skipEnvironment, rationale) \
|
||||||
|
do { \
|
||||||
|
SkipEnvironment skip(skipEnvironment); \
|
||||||
|
if (skip.matches()) { \
|
||||||
|
GTEST_FAIL() \
|
||||||
|
<< "Failing test as the " << skip.describe() << "\n" \
|
||||||
|
<< " This test should be able to succeed but it needs to fail early because" \
|
||||||
|
<< rationale; \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
struct SkipEnvironment {
|
struct SkipEnvironment {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "SharedShaders.h"
|
#include "SharedShaders.h"
|
||||||
|
#include "Skip.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <utils/Hash.h>
|
#include <utils/Hash.h>
|
||||||
@@ -309,7 +310,7 @@ TEST_F(BlitTest, ColorResolve) {
|
|||||||
|
|
||||||
PipelineState state = {};
|
PipelineState state = {};
|
||||||
state.program = shader.getProgram();
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
state.pipelineLayout.setLayout[0] = { shader.getDescriptorSetLayout() };
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
@@ -489,6 +490,7 @@ TEST_F(BlitTest, BlitRegion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BlitTest, BlitRegionToSwapChain) {
|
TEST_F(BlitTest, BlitRegionToSwapChain) {
|
||||||
|
FAIL_IF(Backend::VULKAN, "Crashes due to not finding color attachment");
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
mCleanup.addPostCall([&]() { executeCommands(); });
|
mCleanup.addPostCall([&]() { executeCommands(); });
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
|||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = shader.getProgram();
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
state.pipelineLayout.setLayout[0] = { shader.getDescriptorSetLayout() };
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
@@ -199,8 +199,8 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
|
|||||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||||
params.viewport.height = 512;
|
params.viewport.height = 512;
|
||||||
params.viewport.width = 512;
|
params.viewport.width = 512;
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
renderTriangle({ { shader.getDescriptorSetLayout() } }, renderTarget, swapChain,
|
||||||
renderTarget, swapChain, shader.getProgram(), params);
|
shader.getProgram(), params);
|
||||||
|
|
||||||
// Upload uniforms for the second triangle. To test partial buffer updates, we'll only update
|
// Upload uniforms for the second triangle. To test partial buffer updates, we'll only update
|
||||||
// color.b, color.a, scaleMinusOne, offset.x, and offset.y.
|
// color.b, color.a, scaleMinusOne, offset.x, and offset.y.
|
||||||
@@ -218,7 +218,7 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
|
|||||||
|
|
||||||
params.flags.clear = TargetBufferFlags::NONE;
|
params.flags.clear = TargetBufferFlags::NONE;
|
||||||
params.flags.discardStart = TargetBufferFlags::NONE;
|
params.flags.discardStart = TargetBufferFlags::NONE;
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
renderTriangle({{ shader.getDescriptorSetLayout() }},
|
||||||
renderTarget, swapChain, shader.getProgram(), params);
|
renderTarget, swapChain, shader.getProgram(), params);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ layout(location = 0) out vec4 fragColor;
|
|||||||
|
|
||||||
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
||||||
// This parameter is ignored for other backends.
|
// This parameter is ignored for other backends.
|
||||||
layout(binding = 0, set = 1) uniform sampler2D test_tex;
|
layout(binding = 0, set = 0) uniform sampler2D test_tex;
|
||||||
|
|
||||||
layout(binding = 1, set = 1) uniform Params {
|
layout(binding = 1, set = 0) uniform Params {
|
||||||
highp float fbWidth;
|
highp float fbWidth;
|
||||||
highp float fbHeight;
|
highp float fbHeight;
|
||||||
highp float sourceLevel;
|
highp float sourceLevel;
|
||||||
@@ -167,7 +167,7 @@ TEST_F(BackendTest, FeedbackLoops) {
|
|||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
state.program = shader.getProgram();
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
state.pipelineLayout.setLayout[0] = { shader.getDescriptorSetLayout() };
|
||||||
|
|
||||||
api.makeCurrent(swapChain, swapChain);
|
api.makeCurrent(swapChain, swapChain);
|
||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "Lifetimes.h"
|
#include "Lifetimes.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "SharedShaders.h"
|
#include "SharedShaders.h"
|
||||||
|
#include "Skip.h"
|
||||||
|
|
||||||
#include <backend/DriverEnums.h>
|
#include <backend/DriverEnums.h>
|
||||||
#include <backend/Handle.h>
|
#include <backend/Handle.h>
|
||||||
@@ -46,7 +47,7 @@ layout(location = 0) out vec4 fragColor;
|
|||||||
|
|
||||||
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
||||||
// This parameter is ignored for other backends.
|
// This parameter is ignored for other backends.
|
||||||
layout(location = 0, set = 1) uniform {samplerType} test_tex;
|
layout(location = 0, set = 0) uniform {samplerType} test_tex;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 fbsize = vec2(512);
|
vec2 fbsize = vec2(512);
|
||||||
@@ -64,7 +65,7 @@ std::string fragmentUpdateImage3DTemplate (R"(#version 450 core
|
|||||||
layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
|
||||||
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
||||||
layout(location = 0, set = 1) uniform {samplerType} test_tex;
|
layout(location = 0, set = 0) uniform {samplerType} test_tex;
|
||||||
|
|
||||||
float getLayer(in sampler3D s) { return 2.5f / 4.0f; }
|
float getLayer(in sampler3D s) { return 2.5f / 4.0f; }
|
||||||
float getLayer(in sampler2DArray s) { return 2.0f; }
|
float getLayer(in sampler2DArray s) { return 2.0f; }
|
||||||
@@ -85,7 +86,7 @@ std::string fragmentUpdateImageMip (R"(#version 450 core
|
|||||||
layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
|
||||||
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
||||||
layout(location = 0, set = 1) uniform sampler2D test_tex;
|
layout(location = 0, set = 0) uniform sampler2D test_tex;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 fbsize = vec2(512);
|
vec2 fbsize = vec2(512);
|
||||||
@@ -211,6 +212,7 @@ static SamplerFormat getSamplerFormat(TextureFormat textureFormat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LoadImageTest, UpdateImage2D) {
|
TEST_F(LoadImageTest, UpdateImage2D) {
|
||||||
|
FAIL_IF(Backend::VULKAN, "Multiple test cases crash");
|
||||||
|
|
||||||
// All of these test cases should result in the same rendered image, and thus the same hash.
|
// All of these test cases should result in the same rendered image, and thus the same hash.
|
||||||
static const uint32_t expectedHash = 3644679986;
|
static const uint32_t expectedHash = 3644679986;
|
||||||
@@ -334,9 +336,9 @@ TEST_F(LoadImageTest, UpdateImage2D) {
|
|||||||
.filterMag = SamplerMagFilter::NEAREST,
|
.filterMag = SamplerMagFilter::NEAREST,
|
||||||
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST });
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 0, {});
|
||||||
|
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
renderTriangle({{ shader.getDescriptorSetLayout() }},
|
||||||
defaultRenderTarget, swapChain, shader.getProgram());
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
||||||
@@ -409,9 +411,9 @@ TEST_F(LoadImageTest, UpdateImageSRGB) {
|
|||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||||
});
|
});
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 0, {});
|
||||||
|
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
renderTriangle({{ shader.getDescriptorSetLayout() }},
|
||||||
defaultRenderTarget, swapChain, shader.getProgram());
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
||||||
@@ -468,9 +470,9 @@ TEST_F(LoadImageTest, UpdateImageMipLevel) {
|
|||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||||
});
|
});
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 0, {});
|
||||||
|
|
||||||
renderTriangle({{ DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() }},
|
renderTriangle({{ shader.getDescriptorSetLayout() }},
|
||||||
defaultRenderTarget, swapChain, shader.getProgram());
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
||||||
@@ -539,9 +541,9 @@ TEST_F(LoadImageTest, UpdateImage3D) {
|
|||||||
{ .filterMag = SamplerMagFilter::LINEAR,
|
{ .filterMag = SamplerMagFilter::LINEAR,
|
||||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST });
|
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST });
|
||||||
|
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 0, {});
|
||||||
|
|
||||||
renderTriangle({ { DescriptorSetLayoutHandle{}, shader.getDescriptorSetLayout() } },
|
renderTriangle({ { shader.getDescriptorSetLayout() } },
|
||||||
defaultRenderTarget, swapChain, shader.getProgram());
|
defaultRenderTarget, swapChain, shader.getProgram());
|
||||||
|
|
||||||
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
EXPECT_IMAGE(defaultRenderTarget, getExpectations(),
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ std::string fragmentTexturedLod (R"(#version 450 core
|
|||||||
layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec4 fragColor;
|
||||||
layout(location = 0) in vec2 uv;
|
layout(location = 0) in vec2 uv;
|
||||||
|
|
||||||
layout(location = 0, set = 1) uniform sampler2D backend_test_sib_tex;
|
layout(location = 0, set = 0) uniform sampler2D backend_test_sib_tex;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = textureLod(backend_test_sib_tex, uv, 1);
|
fragColor = textureLod(backend_test_sib_tex, uv, 1);
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ void main() {
|
|||||||
|
|
||||||
TEST_F(BackendTest, PushConstants) {
|
TEST_F(BackendTest, PushConstants) {
|
||||||
SKIP_IF(Backend::OPENGL, "Push constants not supported on OpenGL");
|
SKIP_IF(Backend::OPENGL, "Push constants not supported on OpenGL");
|
||||||
|
FAIL_IF(Backend::VULKAN, "Crashing due to no program set when setting push constants");
|
||||||
|
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ Shader createShader(DriverApi& api, Cleanup& cleanup, Backend backend) {
|
|||||||
// Rendering an external image without setting any data should not crash.
|
// Rendering an external image without setting any data should not crash.
|
||||||
TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
||||||
SKIP_IF(Backend::METAL, "External images aren't supported in metal");
|
SKIP_IF(Backend::METAL, "External images aren't supported in metal");
|
||||||
|
SKIP_IF(Backend::VULKAN, "External images aren't supported in vulkan");
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
Cleanup cleanup(api);
|
Cleanup cleanup(api);
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
|||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = shader.getProgram();
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
state.pipelineLayout.setLayout[0] = { shader.getDescriptorSetLayout() };
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
@@ -94,7 +95,7 @@ TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
|||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
|
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {});
|
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {});
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 0, {});
|
||||||
|
|
||||||
// Render a triangle.
|
// Render a triangle.
|
||||||
api.beginRenderPass(defaultRenderTarget, params);
|
api.beginRenderPass(defaultRenderTarget, params);
|
||||||
@@ -114,6 +115,7 @@ TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
|||||||
|
|
||||||
TEST_F(BackendTest, RenderExternalImage) {
|
TEST_F(BackendTest, RenderExternalImage) {
|
||||||
SKIP_IF(Backend::METAL, "External images aren't supported in metal");
|
SKIP_IF(Backend::METAL, "External images aren't supported in metal");
|
||||||
|
SKIP_IF(Backend::VULKAN, "External images aren't supported in vulkan");
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
Cleanup cleanup(api);
|
Cleanup cleanup(api);
|
||||||
|
|
||||||
@@ -186,7 +188,7 @@ TEST_F(BackendTest, RenderExternalImage) {
|
|||||||
|
|
||||||
PipelineState state;
|
PipelineState state;
|
||||||
state.program = shader.getProgram();
|
state.program = shader.getProgram();
|
||||||
state.pipelineLayout.setLayout[1] = { shader.getDescriptorSetLayout() };
|
state.pipelineLayout.setLayout[0] = { shader.getDescriptorSetLayout() };
|
||||||
state.rasterState.colorWrite = true;
|
state.rasterState.colorWrite = true;
|
||||||
state.rasterState.depthWrite = false;
|
state.rasterState.depthWrite = false;
|
||||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||||
@@ -197,7 +199,7 @@ TEST_F(BackendTest, RenderExternalImage) {
|
|||||||
api.beginFrame(0, 0, 0);
|
api.beginFrame(0, 0, 0);
|
||||||
|
|
||||||
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {});
|
api.updateDescriptorSetTexture(descriptorSet, 0, texture, {});
|
||||||
api.bindDescriptorSet(descriptorSet, 1, {});
|
api.bindDescriptorSet(descriptorSet, 0, {});
|
||||||
|
|
||||||
// Render a triangle.
|
// Render a triangle.
|
||||||
api.beginRenderPass(defaultRenderTarget, params);
|
api.beginRenderPass(defaultRenderTarget, params);
|
||||||
|
|||||||
@@ -1098,12 +1098,16 @@ void FMaterial::processPushConstants(FEngine&, MaterialParser const* parser) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FMaterial::precacheDepthVariants(FEngine const& engine) {
|
void FMaterial::precacheDepthVariants(FEngine& engine) {
|
||||||
|
|
||||||
|
bool const disableDepthPrecacheForDefaultMaterial = engine.getDriverApi().isWorkaroundNeeded(
|
||||||
|
Workaround::DISABLE_DEPTH_PRECACHE_FOR_DEFAULT_MATERIAL);
|
||||||
|
|
||||||
// pre-cache all depth variants inside the default material. Note that this should be
|
// pre-cache all depth variants inside the default material. Note that this should be
|
||||||
// entirely optional; if we remove this pre-caching, these variants will be populated
|
// entirely optional; if we remove this pre-caching, these variants will be populated
|
||||||
// later, when/if needed by createAndCacheProgram(). Doing it now potentially uses more
|
// later, when/if needed by createAndCacheProgram(). Doing it now potentially uses more
|
||||||
// memory and increases init time, but reduces hiccups during the first frame.
|
// memory and increases init time, but reduces hiccups during the first frame.
|
||||||
if (UTILS_UNLIKELY(mIsDefaultMaterial)) {
|
if (UTILS_UNLIKELY(mIsDefaultMaterial && !disableDepthPrecacheForDefaultMaterial)) {
|
||||||
const bool stereoSupported = mEngine.getDriverApi().isStereoSupported();
|
const bool stereoSupported = mEngine.getDriverApi().isStereoSupported();
|
||||||
auto const allDepthVariants = VariantUtils::getDepthVariants();
|
auto const allDepthVariants = VariantUtils::getDepthVariants();
|
||||||
for (auto const variant: allDepthVariants) {
|
for (auto const variant: allDepthVariants) {
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ private:
|
|||||||
|
|
||||||
void processPushConstants(FEngine& engine, MaterialParser const* parser);
|
void processPushConstants(FEngine& engine, MaterialParser const* parser);
|
||||||
|
|
||||||
void precacheDepthVariants(FEngine const& engine);
|
void precacheDepthVariants(FEngine& engine);
|
||||||
|
|
||||||
void processDescriptorSets(FEngine& engine, MaterialParser const* parser);
|
void processDescriptorSets(FEngine& engine, MaterialParser const* parser);
|
||||||
|
|
||||||
|
|||||||
@@ -824,6 +824,9 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) {
|
|||||||
variant.setDirectionalLighting(view.hasDirectionalLighting());
|
variant.setDirectionalLighting(view.hasDirectionalLighting());
|
||||||
variant.setDynamicLighting(view.hasDynamicLighting());
|
variant.setDynamicLighting(view.hasDynamicLighting());
|
||||||
variant.setFog(view.hasFog());
|
variant.setFog(view.hasFog());
|
||||||
|
// The VSM bit has a different meaning for STANDARD_VARIANT (as opposed to DEPTH_VARIANT),
|
||||||
|
// In the STANDARD_VARIANT case, we are *using* the shadow-map, and the VSM only decides which
|
||||||
|
// type of sampler is used (samplerShadow or sampler2D).
|
||||||
variant.setVsm(view.hasShadowing() && view.getShadowType() != ShadowType::PCF);
|
variant.setVsm(view.hasShadowing() && view.getShadowType() != ShadowType::PCF);
|
||||||
variant.setStereo(view.hasStereo());
|
variant.setStereo(view.hasStereo());
|
||||||
|
|
||||||
@@ -841,7 +844,11 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) {
|
|||||||
|
|
||||||
if (view.needsShadowMap()) {
|
if (view.needsShadowMap()) {
|
||||||
Variant shadowVariant(Variant::DEPTH_VARIANT);
|
Variant shadowVariant(Variant::DEPTH_VARIANT);
|
||||||
|
// The VSM bit has a different meaning for DEPTH_VARIANT (as opposed to STANDARD_VARIANT),
|
||||||
|
// In the DEPTH_VARIANT case, we are *generating* the shadow-map, and some computations
|
||||||
|
// are handled differently. In addition, the color buffer is used.
|
||||||
shadowVariant.setVsm(view.getShadowType() == ShadowType::VSM);
|
shadowVariant.setVsm(view.getShadowType() == ShadowType::VSM);
|
||||||
|
|
||||||
auto shadows = view.renderShadowMaps(engine, fg, cameraInfo, mShaderUserTime,
|
auto shadows = view.renderShadowMaps(engine, fg, cameraInfo, mShaderUserTime,
|
||||||
RenderPassBuilder{ commandArena }
|
RenderPassBuilder{ commandArena }
|
||||||
.renderFlags(renderFlags)
|
.renderFlags(renderFlags)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
Pod::Spec.new do |spec|
|
Pod::Spec.new do |spec|
|
||||||
spec.name = "Filament"
|
spec.name = "Filament"
|
||||||
spec.version = "1.59.3"
|
spec.version = "1.59.4"
|
||||||
spec.license = { :type => "Apache 2.0", :file => "LICENSE" }
|
spec.license = { :type => "Apache 2.0", :file => "LICENSE" }
|
||||||
spec.homepage = "https://google.github.io/filament"
|
spec.homepage = "https://google.github.io/filament"
|
||||||
spec.authors = "Google LLC."
|
spec.authors = "Google LLC."
|
||||||
spec.summary = "Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WASM/WebGL."
|
spec.summary = "Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WASM/WebGL."
|
||||||
spec.platform = :ios, "11.0"
|
spec.platform = :ios, "11.0"
|
||||||
spec.source = { :http => "https://github.com/google/filament/releases/download/v1.59.3/filament-v1.59.3-ios.tgz" }
|
spec.source = { :http => "https://github.com/google/filament/releases/download/v1.59.4/filament-v1.59.4-ios.tgz" }
|
||||||
|
|
||||||
# Fix linking error with Xcode 12; we do not yet support the simulator on Apple silicon.
|
# Fix linking error with Xcode 12; we do not yet support the simulator on Apple silicon.
|
||||||
spec.pod_target_xcconfig = {
|
spec.pod_target_xcconfig = {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ struct Variant {
|
|||||||
// DEP: Depth only
|
// DEP: Depth only
|
||||||
// FOG: Fog
|
// FOG: Fog
|
||||||
// PCK: Picking (depth variant only)
|
// PCK: Picking (depth variant only)
|
||||||
// VSM: Variance shadow maps
|
// VSM: Variance shadow maps (depth) / sampler type (standard)
|
||||||
// STE: Instanced stereo rendering
|
// STE: Instanced stereo rendering
|
||||||
//
|
//
|
||||||
// X: either 1 or 0
|
// X: either 1 or 0
|
||||||
@@ -75,7 +75,8 @@ struct Variant {
|
|||||||
// | STE | VSM | PCK | 1 | SKN | 0 | 0 | 0 | 16 - 4 = 12
|
// | STE | VSM | PCK | 1 | SKN | 0 | 0 | 0 | 16 - 4 = 12
|
||||||
// +-----+-----+-----+-----+-----+-----+-----+-----+
|
// +-----+-----+-----+-----+-----+-----+-----+-----+
|
||||||
// Vertex depth X X 0 1 X 0 0 0
|
// Vertex depth X X 0 1 X 0 0 0
|
||||||
// Fragment depth 0 X X 1 0 0 0 0
|
// Fragment depth 0 0 X 1 0 0 0 0
|
||||||
|
// Fragment depth 0 1 0 1 0 0 0 0
|
||||||
// Reserved X 1 1 1 X 0 0 0 [ -4]
|
// Reserved X 1 1 1 X 0 0 0 [ -4]
|
||||||
//
|
//
|
||||||
// 96 variants used, 160 reserved (256 - 96)
|
// 96 variants used, 160 reserved (256 - 96)
|
||||||
@@ -95,7 +96,7 @@ struct Variant {
|
|||||||
static constexpr type_t DEP = 0x10; // depth only variants
|
static constexpr type_t DEP = 0x10; // depth only variants
|
||||||
static constexpr type_t FOG = 0x20; // fog (standard)
|
static constexpr type_t FOG = 0x20; // fog (standard)
|
||||||
static constexpr type_t PCK = 0x20; // picking (depth)
|
static constexpr type_t PCK = 0x20; // picking (depth)
|
||||||
static constexpr type_t VSM = 0x40; // variance shadow maps
|
static constexpr type_t VSM = 0x40; // variance shadow maps / sampler type
|
||||||
static constexpr type_t STE = 0x80; // instanced stereo
|
static constexpr type_t STE = 0x80; // instanced stereo
|
||||||
|
|
||||||
// special variants (variants that use the reserved space)
|
// special variants (variants that use the reserved space)
|
||||||
@@ -113,21 +114,21 @@ struct Variant {
|
|||||||
static constexpr type_t UNLIT_MASK = STE | SKN | FOG;
|
static constexpr type_t UNLIT_MASK = STE | SKN | FOG;
|
||||||
|
|
||||||
// returns raw variant bits
|
// returns raw variant bits
|
||||||
inline bool hasDirectionalLighting() const noexcept { return key & DIR; }
|
bool hasDirectionalLighting() const noexcept { return key & DIR; }
|
||||||
inline bool hasDynamicLighting() const noexcept { return key & DYN; }
|
bool hasDynamicLighting() const noexcept { return key & DYN; }
|
||||||
inline bool hasSkinningOrMorphing() const noexcept { return key & SKN; }
|
bool hasSkinningOrMorphing() const noexcept { return key & SKN; }
|
||||||
inline bool hasStereo() const noexcept { return key & STE; }
|
bool hasStereo() const noexcept { return key & STE; }
|
||||||
|
|
||||||
inline void setDirectionalLighting(bool v) noexcept { set(v, DIR); }
|
void setDirectionalLighting(bool v) noexcept { set(v, DIR); }
|
||||||
inline void setDynamicLighting(bool v) noexcept { set(v, DYN); }
|
void setDynamicLighting(bool v) noexcept { set(v, DYN); }
|
||||||
inline void setShadowReceiver(bool v) noexcept { set(v, SRE); }
|
void setShadowReceiver(bool v) noexcept { set(v, SRE); }
|
||||||
inline void setSkinning(bool v) noexcept { set(v, SKN); }
|
void setSkinning(bool v) noexcept { set(v, SKN); }
|
||||||
inline void setFog(bool v) noexcept { set(v, FOG); }
|
void setFog(bool v) noexcept { set(v, FOG); }
|
||||||
inline void setPicking(bool v) noexcept { set(v, PCK); }
|
void setPicking(bool v) noexcept { set(v, PCK); }
|
||||||
inline void setVsm(bool v) noexcept { set(v, VSM); }
|
void setVsm(bool v) noexcept { set(v, VSM); }
|
||||||
inline void setStereo(bool v) noexcept { set(v, STE); }
|
void setStereo(bool v) noexcept { set(v, STE); }
|
||||||
|
|
||||||
inline static constexpr bool isValidDepthVariant(Variant variant) noexcept {
|
static constexpr bool isValidDepthVariant(Variant variant) noexcept {
|
||||||
// Can't have VSM and PICKING together with DEPTH variants
|
// Can't have VSM and PICKING together with DEPTH variants
|
||||||
constexpr type_t RESERVED_MASK = VSM | PCK | DEP | SRE | DYN | DIR;
|
constexpr type_t RESERVED_MASK = VSM | PCK | DEP | SRE | DYN | DIR;
|
||||||
constexpr type_t RESERVED_VALUE = VSM | PCK | DEP;
|
constexpr type_t RESERVED_VALUE = VSM | PCK | DEP;
|
||||||
@@ -135,7 +136,7 @@ struct Variant {
|
|||||||
((variant.key & RESERVED_MASK) != RESERVED_VALUE);
|
((variant.key & RESERVED_MASK) != RESERVED_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isValidStandardVariant(Variant variant) noexcept {
|
static constexpr bool isValidStandardVariant(Variant variant) noexcept {
|
||||||
// can't have shadow receiver if we don't have any lighting
|
// can't have shadow receiver if we don't have any lighting
|
||||||
constexpr type_t RESERVED0_MASK = VSM | FOG | SRE | DYN | DIR;
|
constexpr type_t RESERVED0_MASK = VSM | FOG | SRE | DYN | DIR;
|
||||||
constexpr type_t RESERVED0_VALUE = VSM | FOG | SRE;
|
constexpr type_t RESERVED0_VALUE = VSM | FOG | SRE;
|
||||||
@@ -154,11 +155,11 @@ struct Variant {
|
|||||||
((variant.key & RESERVED2_MASK) != RESERVED2_VALUE);
|
((variant.key & RESERVED2_MASK) != RESERVED2_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isVertexVariant(Variant variant) noexcept {
|
static constexpr bool isVertexVariant(Variant variant) noexcept {
|
||||||
return filterVariantVertex(variant) == variant;
|
return filterVariantVertex(variant) == variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isFragmentVariant(Variant variant) noexcept {
|
static constexpr bool isFragmentVariant(Variant variant) noexcept {
|
||||||
return filterVariantFragment(variant) == variant;
|
return filterVariantFragment(variant) == variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,32 +171,32 @@ struct Variant {
|
|||||||
return isValidStandardVariant(variant) || isValidDepthVariant(variant);
|
return isValidStandardVariant(variant) || isValidDepthVariant(variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isSSRVariant(Variant variant) noexcept {
|
static constexpr bool isSSRVariant(Variant variant) noexcept {
|
||||||
return (variant.key & (STE | VSM | DEP | SRE | DYN | DIR)) == (VSM | SRE);
|
return (variant.key & (STE | VSM | DEP | SRE | DYN | DIR)) == (VSM | SRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isVSMVariant(Variant variant) noexcept {
|
static constexpr bool isVSMVariant(Variant variant) noexcept {
|
||||||
return !isSSRVariant(variant) && ((variant.key & VSM) == VSM);
|
return !isSSRVariant(variant) && ((variant.key & VSM) == VSM);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isShadowReceiverVariant(Variant variant) noexcept {
|
static constexpr bool isShadowReceiverVariant(Variant variant) noexcept {
|
||||||
return !isSSRVariant(variant) && ((variant.key & SRE) == SRE);
|
return !isSSRVariant(variant) && ((variant.key & SRE) == SRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isFogVariant(Variant variant) noexcept {
|
static constexpr bool isFogVariant(Variant variant) noexcept {
|
||||||
return (variant.key & (FOG | DEP)) == FOG;
|
return (variant.key & (FOG | DEP)) == FOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isPickingVariant(Variant variant) noexcept {
|
static constexpr bool isPickingVariant(Variant variant) noexcept {
|
||||||
return (variant.key & (PCK | DEP)) == (PCK | DEP);
|
return (variant.key & (PCK | DEP)) == (PCK | DEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr bool isStereoVariant(Variant variant) noexcept {
|
static constexpr bool isStereoVariant(Variant variant) noexcept {
|
||||||
return (variant.key & STE) == STE;
|
return (variant.key & STE) == STE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Variant filterVariantVertex(Variant variant) noexcept {
|
static constexpr Variant filterVariantVertex(Variant variant) noexcept {
|
||||||
// filter out vertex variants that are not needed. For e.g. fog doesn't affect the
|
// Filter out vertex variants that are not needed. For e.g. fog doesn't affect the
|
||||||
// vertex shader.
|
// vertex shader.
|
||||||
if ((variant.key & STANDARD_MASK) == STANDARD_VARIANT) {
|
if ((variant.key & STANDARD_MASK) == STANDARD_VARIANT) {
|
||||||
if (isSSRVariant(variant)) {
|
if (isSSRVariant(variant)) {
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ bool ApiHandler::handleGetApiShader(struct mg_connection* conn,
|
|||||||
std::string_view const essl1("essl1");
|
std::string_view const essl1("essl1");
|
||||||
std::string_view const msl("msl");
|
std::string_view const msl("msl");
|
||||||
std::string_view const spirv("spirv");
|
std::string_view const spirv("spirv");
|
||||||
|
std::string_view const wgsl("wgsl");
|
||||||
size_t const qlength = strlen(request->query_string);
|
size_t const qlength = strlen(request->query_string);
|
||||||
|
|
||||||
char type[6] = {};
|
char type[6] = {};
|
||||||
@@ -102,11 +103,13 @@ bool ApiHandler::handleGetApiShader(struct mg_connection* conn,
|
|||||||
char glindex[4] = {};
|
char glindex[4] = {};
|
||||||
char vkindex[4] = {};
|
char vkindex[4] = {};
|
||||||
char metalindex[4] = {};
|
char metalindex[4] = {};
|
||||||
|
char wgpuindex[4] = {};
|
||||||
mg_get_var(request->query_string, qlength, "glindex", glindex, sizeof(glindex));
|
mg_get_var(request->query_string, qlength, "glindex", glindex, sizeof(glindex));
|
||||||
mg_get_var(request->query_string, qlength, "vkindex", vkindex, sizeof(vkindex));
|
mg_get_var(request->query_string, qlength, "vkindex", vkindex, sizeof(vkindex));
|
||||||
mg_get_var(request->query_string, qlength, "metalindex", metalindex, sizeof(metalindex));
|
mg_get_var(request->query_string, qlength, "metalindex", metalindex, sizeof(metalindex));
|
||||||
|
mg_get_var(request->query_string, qlength, "wgpuindex", wgpuindex, sizeof(wgpuindex));
|
||||||
|
|
||||||
if (!glindex[0] && !vkindex[0] && !metalindex[0]) {
|
if (!glindex[0] && !vkindex[0] && !metalindex[0] && !wgpuindex[0]) {
|
||||||
return error(__LINE__, uri);
|
return error(__LINE__, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +221,37 @@ bool ApiHandler::handleGetApiShader(struct mg_connection* conn,
|
|||||||
|
|
||||||
return softError("Only MSL is supported.");
|
return softError("Only MSL is supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wgpuindex[0]) {
|
||||||
|
ShaderExtractor extractor(ShaderLanguage::WGSL, result->package, result->packageSize);
|
||||||
|
if (!extractor.parse()) {
|
||||||
|
return error(__LINE__, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
FixedCapacityVector<ShaderInfo> info(getShaderCount(package, ChunkType::MaterialWgsl));
|
||||||
|
if (!getShaderInfo(package, info.data(), ChunkType::MaterialWgsl)) {
|
||||||
|
return error(__LINE__, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
int const shaderIndex = std::stoi(wgpuindex);
|
||||||
|
if (shaderIndex >= info.size()) {
|
||||||
|
return error(__LINE__, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const& item = info[shaderIndex];
|
||||||
|
filaflat::ShaderContent content;
|
||||||
|
extractor.getShader(item.shaderModel, item.variant, item.pipelineStage, content);
|
||||||
|
|
||||||
|
if (language == wgsl) {
|
||||||
|
std::string const shader = mFormatter.format((char const*) content.data());
|
||||||
|
mg_printf(conn, kSuccessHeader.data(), "application/txt");
|
||||||
|
mg_write(conn, shader.c_str(), shader.size());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return softError("Only WGSL is supported.");
|
||||||
|
}
|
||||||
|
|
||||||
return error(__LINE__, uri);
|
return error(__LINE__, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,6 +181,18 @@ static bool printMetalInfo(ostream& json, const ChunkContainer& container) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool printWGPUInfo(ostream& json, const ChunkContainer& container) {
|
||||||
|
std::vector<ShaderInfo> info;
|
||||||
|
info.resize(getShaderCount(container, ChunkType::MaterialWgsl));
|
||||||
|
if (!getShaderInfo(container, info.data(), ChunkType::MaterialWgsl)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
json << "\"webgpu\": [\n";
|
||||||
|
printShaderInfo(json, info, container);
|
||||||
|
json << "],\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool JsonWriter::writeMaterialInfo(const filaflat::ChunkContainer& container) {
|
bool JsonWriter::writeMaterialInfo(const filaflat::ChunkContainer& container) {
|
||||||
ostringstream json;
|
ostringstream json;
|
||||||
if (!printMaterial(json, container)) {
|
if (!printMaterial(json, container)) {
|
||||||
@@ -201,6 +213,9 @@ bool JsonWriter::writeMaterialInfo(const filaflat::ChunkContainer& container) {
|
|||||||
if (!printMetalInfo(json, container)) {
|
if (!printMetalInfo(json, container)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!printWGPUInfo(json, container)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
json << "\"required_attributes\": [\n";
|
json << "\"required_attributes\": [\n";
|
||||||
uint32_t requiredAttributes;
|
uint32_t requiredAttributes;
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ async function fetchShaderCode(matid, backend, language, index) {
|
|||||||
case "metal":
|
case "metal":
|
||||||
query = `type=${language}&metalindex=${index}`;
|
query = `type=${language}&metalindex=${index}`;
|
||||||
break;
|
break;
|
||||||
|
case "webgpu":
|
||||||
|
query = `type=${language}&wgpuindex=${index}`;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return await _fetchText(`api/shader?matid=${matid}&${query}`);
|
return await _fetchText(`api/shader?matid=${matid}&${query}`);
|
||||||
}
|
}
|
||||||
@@ -88,6 +91,7 @@ function rebuildMaterial(materialId, backend, shaderIndex, editedText) {
|
|||||||
break;
|
break;
|
||||||
case "vulkan": api = 2; break;
|
case "vulkan": api = 2; break;
|
||||||
case "metal": api = 3; break;
|
case "metal": api = 3; break;
|
||||||
|
case "webgpu": api = 4; break;
|
||||||
}
|
}
|
||||||
return new Promise((ok, fail) => {
|
return new Promise((ok, fail) => {
|
||||||
const req = new XMLHttpRequest();
|
const req = new XMLHttpRequest();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { LitElement, html, css, unsafeCSS, nothing } from "https://unpkg.com/lit@2.8.0?module";
|
import { LitElement, html, css, unsafeCSS, nothing } from "https://cdn.jsdelivr.net/gh/lit/dist@3/all/lit-all.min.js";
|
||||||
|
|
||||||
const kUntitledPlaceholder = "untitled";
|
const kUntitledPlaceholder = "untitled";
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ const LANGUAGE_CHOICES = {
|
|||||||
'essl1': ['essl3', 'essl1'],
|
'essl1': ['essl3', 'essl1'],
|
||||||
'vulkan': ['glsl', 'spirv'],
|
'vulkan': ['glsl', 'spirv'],
|
||||||
'metal': ['msl'],
|
'metal': ['msl'],
|
||||||
|
'webgpu': ['wgsl'],
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_LANGUAGE_FOR_BACKEND = {
|
const DEFAULT_LANGUAGE_FOR_BACKEND = {
|
||||||
@@ -31,6 +32,7 @@ const DEFAULT_LANGUAGE_FOR_BACKEND = {
|
|||||||
'essl1': 'essl1',
|
'essl1': 'essl1',
|
||||||
'vulkan': 'glsl',
|
'vulkan': 'glsl',
|
||||||
'metal': 'msl',
|
'metal': 'msl',
|
||||||
|
'webgpu': 'wgsl',
|
||||||
};
|
};
|
||||||
|
|
||||||
const BACKENDS = Object.keys(LANGUAGE_CHOICES);
|
const BACKENDS = Object.keys(LANGUAGE_CHOICES);
|
||||||
|
|||||||
Vendored
+3
-3
@@ -1176,10 +1176,10 @@ export interface View$DynamicResolutionOptions {
|
|||||||
/**
|
/**
|
||||||
* Upscaling quality
|
* Upscaling quality
|
||||||
* LOW: bilinear filtered blit. Fastest, poor quality
|
* LOW: bilinear filtered blit. Fastest, poor quality
|
||||||
* MEDIUM: AMD FidelityFX FSR1 w/ mobile optimizations
|
* MEDIUM: Qualcomm Snapdragon Game Super Resolution (SGSR) 1.0
|
||||||
* HIGH: AMD FidelityFX FSR1 w/ mobile optimizations
|
* HIGH: AMD FidelityFX FSR1 w/ mobile optimizations
|
||||||
* ULTRA: AMD FidelityFX FSR1
|
* ULTRA: AMD FidelityFX FSR1
|
||||||
* FSR1 require a well anti-aliased (MSAA or TAA), noise free scene.
|
* FSR1 and SGSR require a well anti-aliased (MSAA or TAA), noise free scene. Avoid FXAA and dithering.
|
||||||
*
|
*
|
||||||
* The default upscaling quality is set to LOW.
|
* The default upscaling quality is set to LOW.
|
||||||
*/
|
*/
|
||||||
@@ -1675,7 +1675,7 @@ export enum View$TemporalAntiAliasingOptions$JitterPattern {
|
|||||||
*/
|
*/
|
||||||
export interface View$TemporalAntiAliasingOptions {
|
export interface View$TemporalAntiAliasingOptions {
|
||||||
/**
|
/**
|
||||||
* reconstruction filter width typically between 0.2 (sharper, aliased) and 1.5 (smoother)
|
* reconstruction filter width typically between 1 (sharper) and 2 (smoother)
|
||||||
*/
|
*/
|
||||||
filterWidth?: number;
|
filterWidth?: number;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "filament",
|
"name": "filament",
|
||||||
"version": "1.59.3",
|
"version": "1.59.4",
|
||||||
"description": "Real-time physically based rendering engine",
|
"description": "Real-time physically based rendering engine",
|
||||||
"main": "filament.js",
|
"main": "filament.js",
|
||||||
"module": "filament.js",
|
"module": "filament.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user