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