@luma.gl/shadertools 9.0.21 → 9.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +102 -90
- package/dist/dist.min.js +127 -130
- package/dist/index.cjs +94 -79
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +49 -52
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +10 -29
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +14 -11
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.js +25 -0
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +8 -14
- package/dist/modules/lighting/phong-material/phong-material.js +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +7 -1
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +1 -1
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
- package/src/modules/lighting/pbr-material/pbr-material.ts +25 -52
- package/src/modules/lighting/pbr-material/pbr-projection.ts +41 -0
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
- package/src/modules/lighting/phong-material/phong-material.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +0 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +0 -2
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +0 -48
- package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +0 -69
package/dist/index.cjs
CHANGED
|
@@ -1820,7 +1820,7 @@ var gouraudMaterial = {
|
|
|
1820
1820
|
if (uniforms.specularColor) {
|
|
1821
1821
|
uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
|
|
1822
1822
|
}
|
|
1823
|
-
return { ...gouraudMaterial.defaultUniforms, ...
|
|
1823
|
+
return { ...gouraudMaterial.defaultUniforms, ...uniforms };
|
|
1824
1824
|
}
|
|
1825
1825
|
};
|
|
1826
1826
|
|
|
@@ -1851,38 +1851,32 @@ var phongMaterial = {
|
|
|
1851
1851
|
if (uniforms.specularColor) {
|
|
1852
1852
|
uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
|
|
1853
1853
|
}
|
|
1854
|
-
return { ...phongMaterial.defaultUniforms, ...
|
|
1854
|
+
return { ...phongMaterial.defaultUniforms, ...uniforms };
|
|
1855
1855
|
}
|
|
1856
1856
|
};
|
|
1857
1857
|
|
|
1858
1858
|
// dist/modules/lighting/pbr-material/pbr-vertex-glsl.js
|
|
1859
|
-
var vs2 = `
|
|
1860
|
-
|
|
1861
|
-
mat4 u_ModelMatrix;
|
|
1862
|
-
mat4 u_NormalMatrix;
|
|
1863
|
-
vec3 u_Camera;
|
|
1864
|
-
}
|
|
1865
|
-
varying vec3 pbr_vPosition;
|
|
1866
|
-
varying vec2 pbr_vUV;
|
|
1859
|
+
var vs2 = `out vec3 pbr_vPosition;
|
|
1860
|
+
out vec2 pbr_vUV;
|
|
1867
1861
|
#ifdef HAS_NORMALS
|
|
1868
1862
|
# ifdef HAS_TANGENTS
|
|
1869
|
-
|
|
1863
|
+
out mat3 pbr_vTBN;
|
|
1870
1864
|
# else
|
|
1871
|
-
|
|
1865
|
+
out vec3 pbr_vNormal;
|
|
1872
1866
|
# endif
|
|
1873
1867
|
#endif
|
|
1874
1868
|
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
1875
1869
|
{
|
|
1876
|
-
vec4 pos =
|
|
1870
|
+
vec4 pos = pbrProjection.modelMatrix * position;
|
|
1877
1871
|
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
1878
1872
|
#ifdef HAS_NORMALS
|
|
1879
1873
|
#ifdef HAS_TANGENTS
|
|
1880
|
-
vec3 normalW = normalize(vec3(
|
|
1881
|
-
vec3 tangentW = normalize(vec3(
|
|
1874
|
+
vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
1875
|
+
vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
1882
1876
|
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
1883
1877
|
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
1884
1878
|
#else
|
|
1885
|
-
pbr_vNormal = normalize(vec3(
|
|
1879
|
+
pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
1886
1880
|
#endif
|
|
1887
1881
|
#endif
|
|
1888
1882
|
#ifdef HAS_UV
|
|
@@ -1895,10 +1889,7 @@ pbr_vUV = vec2(0.,0.);
|
|
|
1895
1889
|
|
|
1896
1890
|
// dist/modules/lighting/pbr-material/pbr-fragment-glsl.js
|
|
1897
1891
|
var fs3 = `precision highp float;
|
|
1898
|
-
uniform
|
|
1899
|
-
uniform vec3 u_Camera;
|
|
1900
|
-
};
|
|
1901
|
-
uniform pbrMaterial {
|
|
1892
|
+
uniform pbrMaterialUniforms {
|
|
1902
1893
|
bool unlit;
|
|
1903
1894
|
bool baseColorMapEnabled;
|
|
1904
1895
|
vec4 baseColorFactor;
|
|
@@ -1916,34 +1907,34 @@ bool IBLenabled;
|
|
|
1916
1907
|
vec2 scaleIBLAmbient;
|
|
1917
1908
|
vec4 scaleDiffBaseMR;
|
|
1918
1909
|
vec4 scaleFGDSpec;
|
|
1919
|
-
}
|
|
1910
|
+
} pbrMaterial;
|
|
1920
1911
|
#ifdef HAS_BASECOLORMAP
|
|
1921
|
-
uniform sampler2D
|
|
1912
|
+
uniform sampler2D pbr_baseColorSampler;
|
|
1922
1913
|
#endif
|
|
1923
1914
|
#ifdef HAS_NORMALMAP
|
|
1924
|
-
uniform sampler2D
|
|
1915
|
+
uniform sampler2D pbr_normalSampler;
|
|
1925
1916
|
#endif
|
|
1926
1917
|
#ifdef HAS_EMISSIVEMAP
|
|
1927
|
-
uniform sampler2D
|
|
1918
|
+
uniform sampler2D pbr_emissiveSampler;
|
|
1928
1919
|
#endif
|
|
1929
1920
|
#ifdef HAS_METALROUGHNESSMAP
|
|
1930
|
-
uniform sampler2D
|
|
1921
|
+
uniform sampler2D pbr_metallicRoughnessSampler;
|
|
1931
1922
|
#endif
|
|
1932
1923
|
#ifdef HAS_OCCLUSIONMAP
|
|
1933
|
-
uniform sampler2D
|
|
1924
|
+
uniform sampler2D pbr_occlusionSampler;
|
|
1934
1925
|
#endif
|
|
1935
1926
|
#ifdef USE_IBL
|
|
1936
|
-
uniform samplerCube
|
|
1937
|
-
uniform samplerCube
|
|
1938
|
-
uniform sampler2D
|
|
1927
|
+
uniform samplerCube pbr_diffuseEnvSampler;
|
|
1928
|
+
uniform samplerCube pbr_specularEnvSampler;
|
|
1929
|
+
uniform sampler2D pbr_brdfLUT;
|
|
1939
1930
|
#endif
|
|
1940
|
-
|
|
1941
|
-
|
|
1931
|
+
in vec3 pbr_vPosition;
|
|
1932
|
+
in vec2 pbr_vUV;
|
|
1942
1933
|
#ifdef HAS_NORMALS
|
|
1943
1934
|
#ifdef HAS_TANGENTS
|
|
1944
|
-
|
|
1935
|
+
in mat3 pbr_vTBN;
|
|
1945
1936
|
#else
|
|
1946
|
-
|
|
1937
|
+
in vec3 pbr_vNormal;
|
|
1947
1938
|
#endif
|
|
1948
1939
|
#endif
|
|
1949
1940
|
struct PBRInfo {
|
|
@@ -1998,8 +1989,8 @@ mat3 tbn = mat3(t, b, ng);
|
|
|
1998
1989
|
mat3 tbn = pbr_vTBN;
|
|
1999
1990
|
#endif
|
|
2000
1991
|
#ifdef HAS_NORMALMAP
|
|
2001
|
-
vec3 n =
|
|
2002
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(
|
|
1992
|
+
vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
|
|
1993
|
+
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
2003
1994
|
#else
|
|
2004
1995
|
vec3 n = normalize(tbn[2].xyz);
|
|
2005
1996
|
#endif
|
|
@@ -2010,18 +2001,18 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
|
|
|
2010
2001
|
{
|
|
2011
2002
|
float mipCount = 9.0;
|
|
2012
2003
|
float lod = (pbrInfo.perceptualRoughness * mipCount);
|
|
2013
|
-
vec3 brdf = SRGBtoLINEAR(
|
|
2004
|
+
vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
|
|
2014
2005
|
vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
|
|
2015
|
-
vec3 diffuseLight = SRGBtoLINEAR(
|
|
2006
|
+
vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
|
|
2016
2007
|
#ifdef USE_TEX_LOD
|
|
2017
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
2008
|
+
vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
|
|
2018
2009
|
#else
|
|
2019
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
2010
|
+
vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
|
|
2020
2011
|
#endif
|
|
2021
2012
|
vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
|
|
2022
2013
|
vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
|
|
2023
|
-
diffuse *=
|
|
2024
|
-
specular *=
|
|
2014
|
+
diffuse *= pbrMaterial.scaleIBLAmbient.x;
|
|
2015
|
+
specular *= pbrMaterial.scaleIBLAmbient.y;
|
|
2025
2016
|
return diffuse + specular;
|
|
2026
2017
|
}
|
|
2027
2018
|
#endif
|
|
@@ -2081,24 +2072,24 @@ return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
|
|
|
2081
2072
|
vec4 pbr_filterColor(vec4 colorUnused)
|
|
2082
2073
|
{
|
|
2083
2074
|
#ifdef HAS_BASECOLORMAP
|
|
2084
|
-
vec4 baseColor = SRGBtoLINEAR(
|
|
2075
|
+
vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
|
|
2085
2076
|
#else
|
|
2086
|
-
vec4 baseColor =
|
|
2077
|
+
vec4 baseColor = pbrMaterial.baseColorFactor;
|
|
2087
2078
|
#endif
|
|
2088
2079
|
#ifdef ALPHA_CUTOFF
|
|
2089
|
-
if (baseColor.a <
|
|
2080
|
+
if (baseColor.a < pbrMaterial.alphaCutoff) {
|
|
2090
2081
|
discard;
|
|
2091
2082
|
}
|
|
2092
2083
|
#endif
|
|
2093
2084
|
vec3 color = vec3(0, 0, 0);
|
|
2094
|
-
if(
|
|
2085
|
+
if(pbrMaterial.unlit){
|
|
2095
2086
|
color.rgb = baseColor.rgb;
|
|
2096
2087
|
}
|
|
2097
2088
|
else{
|
|
2098
|
-
float perceptualRoughness =
|
|
2099
|
-
float metallic =
|
|
2089
|
+
float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
|
|
2090
|
+
float metallic = pbrMaterial.metallicRoughnessValues.x;
|
|
2100
2091
|
#ifdef HAS_METALROUGHNESSMAP
|
|
2101
|
-
vec4 mrSample =
|
|
2092
|
+
vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
|
|
2102
2093
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
2103
2094
|
metallic = mrSample.b * metallic;
|
|
2104
2095
|
#endif
|
|
@@ -2114,7 +2105,7 @@ float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
|
2114
2105
|
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
2115
2106
|
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
2116
2107
|
vec3 n = getNormal();
|
|
2117
|
-
vec3 v = normalize(
|
|
2108
|
+
vec3 v = normalize(pbrProjection.camera - pbr_vPosition);
|
|
2118
2109
|
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
2119
2110
|
vec3 reflection = -normalize(reflect(v, n));
|
|
2120
2111
|
PBRInfo pbrInfo = PBRInfo(
|
|
@@ -2135,64 +2126,88 @@ v
|
|
|
2135
2126
|
);
|
|
2136
2127
|
#ifdef USE_LIGHTS
|
|
2137
2128
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
2138
|
-
color += calculateFinalColor(pbrInfo,
|
|
2139
|
-
for(int i = 0; i <
|
|
2140
|
-
if (i <
|
|
2141
|
-
PBRInfo_setDirectionalLight(pbrInfo,
|
|
2142
|
-
color += calculateFinalColor(pbrInfo,
|
|
2129
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
2130
|
+
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
2131
|
+
if (i < lighting.directionalLightCount) {
|
|
2132
|
+
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
2133
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
2143
2134
|
}
|
|
2144
2135
|
}
|
|
2145
|
-
for(int i = 0; i <
|
|
2146
|
-
if (i <
|
|
2147
|
-
PBRInfo_setPointLight(pbrInfo,
|
|
2148
|
-
float attenuation = getPointLightAttenuation(
|
|
2149
|
-
color += calculateFinalColor(pbrInfo,
|
|
2136
|
+
for(int i = 0; i < lighting.pointLightCount; i++) {
|
|
2137
|
+
if (i < lighting.pointLightCount) {
|
|
2138
|
+
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
2139
|
+
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
2140
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
2150
2141
|
}
|
|
2151
2142
|
}
|
|
2152
2143
|
#endif
|
|
2153
2144
|
#ifdef USE_IBL
|
|
2154
|
-
if (
|
|
2145
|
+
if (pbrMaterial.IBLenabled) {
|
|
2155
2146
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
2156
2147
|
}
|
|
2157
2148
|
#endif
|
|
2158
2149
|
#ifdef HAS_OCCLUSIONMAP
|
|
2159
|
-
if (
|
|
2160
|
-
float ao =
|
|
2161
|
-
color = mix(color, color * ao,
|
|
2150
|
+
if (pbrMaterial.occlusionMapEnabled) {
|
|
2151
|
+
float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
|
|
2152
|
+
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
2162
2153
|
}
|
|
2163
2154
|
#endif
|
|
2164
2155
|
#ifdef HAS_EMISSIVEMAP
|
|
2165
|
-
if (
|
|
2166
|
-
vec3 emissive = SRGBtoLINEAR(
|
|
2156
|
+
if (pbrMaterial.emissiveMapEnabled) {
|
|
2157
|
+
vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
|
|
2167
2158
|
color += emissive;
|
|
2168
2159
|
}
|
|
2169
2160
|
#endif
|
|
2170
2161
|
#ifdef PBR_DEBUG
|
|
2171
|
-
color = mix(color, baseColor.rgb,
|
|
2172
|
-
color = mix(color, vec3(metallic),
|
|
2173
|
-
color = mix(color, vec3(perceptualRoughness),
|
|
2162
|
+
color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
|
|
2163
|
+
color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
|
|
2164
|
+
color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
|
|
2174
2165
|
#endif
|
|
2175
2166
|
}
|
|
2176
2167
|
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
2177
2168
|
}
|
|
2178
2169
|
`;
|
|
2179
2170
|
|
|
2171
|
+
// dist/modules/lighting/pbr-material/pbr-projection.js
|
|
2172
|
+
var uniformBlock = `uniform pbrProjectionUniforms {
|
|
2173
|
+
mat4 modelViewProjectionMatrix;
|
|
2174
|
+
mat4 modelMatrix;
|
|
2175
|
+
mat4 normalMatrix;
|
|
2176
|
+
vec3 camera;
|
|
2177
|
+
} pbrProjection;
|
|
2178
|
+
`;
|
|
2179
|
+
var pbrProjection = {
|
|
2180
|
+
name: "pbrProjection",
|
|
2181
|
+
vs: uniformBlock,
|
|
2182
|
+
fs: uniformBlock,
|
|
2183
|
+
// TODO why is this needed?
|
|
2184
|
+
getUniforms: (props) => props,
|
|
2185
|
+
uniformTypes: {
|
|
2186
|
+
modelViewProjectionMatrix: "mat4x4<f32>",
|
|
2187
|
+
modelMatrix: "mat4x4<f32>",
|
|
2188
|
+
normalMatrix: "mat4x4<f32>",
|
|
2189
|
+
camera: "vec3<i32>"
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
2192
|
+
|
|
2180
2193
|
// dist/modules/lighting/pbr-material/pbr-material.js
|
|
2181
2194
|
var pbrMaterial = {
|
|
2182
|
-
name: "
|
|
2195
|
+
name: "pbrMaterial",
|
|
2183
2196
|
vs: vs2,
|
|
2184
2197
|
fs: fs3,
|
|
2185
2198
|
defines: {
|
|
2186
|
-
LIGHTING_FRAGMENT: 1
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2199
|
+
LIGHTING_FRAGMENT: 1
|
|
2200
|
+
// TODO defining these as 0 breaks shader
|
|
2201
|
+
// HAS_NORMALMAP: 0
|
|
2202
|
+
// HAS_EMISSIVEMAP: 0,
|
|
2203
|
+
// HAS_OCCLUSIONMAP: 0,
|
|
2204
|
+
// HAS_BASECOLORMAP: 0,
|
|
2205
|
+
// HAS_METALROUGHNESSMAP: 0,
|
|
2206
|
+
// ALPHA_CUTOFF: 0
|
|
2207
|
+
// USE_IBL: 0
|
|
2208
|
+
// PBR_DEBUG: 0
|
|
2195
2209
|
},
|
|
2210
|
+
getUniforms: (props) => props,
|
|
2196
2211
|
uniformTypes: {
|
|
2197
2212
|
// Material is unlit
|
|
2198
2213
|
unlit: "i32",
|
|
@@ -2222,7 +2237,7 @@ var pbrMaterial = {
|
|
|
2222
2237
|
scaleDiffBaseMR: "vec4<f32>",
|
|
2223
2238
|
scaleFGDSpec: "vec4<f32>"
|
|
2224
2239
|
},
|
|
2225
|
-
dependencies: [lighting]
|
|
2240
|
+
dependencies: [lighting, pbrProjection]
|
|
2226
2241
|
};
|
|
2227
2242
|
|
|
2228
2243
|
// dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.js
|