Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a texture mapping allowing us to combine sampler uniforms #4636

Merged
merged 5 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/graphics/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -1233,3 +1233,4 @@ semanticToLocation[SEMANTIC_ATTR15] = 15;
export const CHUNKAPI_1_51 = '1.51';
export const CHUNKAPI_1_55 = '1.55';
export const CHUNKAPI_1_56 = '1.56';
export const CHUNKAPI_1_57 = '1.57';
33 changes: 21 additions & 12 deletions src/graphics/program-lib/chunks/chunk-validation.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { CHUNKAPI_1_51, CHUNKAPI_1_55, CHUNKAPI_1_56 } from '../../constants.js';
import { CHUNKAPI_1_51, CHUNKAPI_1_55, CHUNKAPI_1_56, CHUNKAPI_1_57 } from '../../constants.js';
import { Debug } from '../../../core/debug.js';
import { shaderChunks } from './chunks.js';

const chunkVersions = {
// frontend
aoPS: CHUNKAPI_1_51,
clearCoatNormalPS: CHUNKAPI_1_55,
diffusePS: CHUNKAPI_1_55,
diffuseDetailMapPS: CHUNKAPI_1_55,
emissivePS: CHUNKAPI_1_55,
aoPS: CHUNKAPI_1_57,
clearCoatPS: CHUNKAPI_1_57,
clearCoatGlossPS: CHUNKAPI_1_57,
clearCoatNormalPS: CHUNKAPI_1_57,
diffusePS: CHUNKAPI_1_57,
diffuseDetailMapPS: CHUNKAPI_1_57,
emissivePS: CHUNKAPI_1_57,
lightmapDirPS: CHUNKAPI_1_55,
lightmapSinglePS: CHUNKAPI_1_55,
metalnessPS: CHUNKAPI_1_55,
specularPS: CHUNKAPI_1_55,
normalMapPS: CHUNKAPI_1_55,
normalDetailMapPS: CHUNKAPI_1_55,
reflectionEnvPS: CHUNKAPI_1_56,
metalnessPS: CHUNKAPI_1_57,
normalMapPS: CHUNKAPI_1_57,
normalDetailMapPS: CHUNKAPI_1_57,
opacityPS: CHUNKAPI_1_57,
parallaxPS: CHUNKAPI_1_57,
sheenPS: CHUNKAPI_1_57,
sheenGlossPS: CHUNKAPI_1_57,
specularPS: CHUNKAPI_1_57,
specularityFactorPS: CHUNKAPI_1_57,
thicknessPS: CHUNKAPI_1_57,
transmissionPS: CHUNKAPI_1_57,

// backend
clusteredLightPS: CHUNKAPI_1_55,
Expand All @@ -27,7 +35,8 @@ const chunkVersions = {
lightSpecularBlinnPS: CHUNKAPI_1_55,
lightSpecularPhongPS: CHUNKAPI_1_55,
normalVertexPS: CHUNKAPI_1_55,
startPS: CHUNKAPI_1_55
startPS: CHUNKAPI_1_55,
reflectionEnvPS: CHUNKAPI_1_56
};

// removed
Expand Down
5 changes: 1 addition & 4 deletions src/graphics/program-lib/chunks/standard/frag/ao.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
export default /* glsl */`
#ifdef MAPTEXTURE
uniform sampler2D texture_aoMap;
#endif

void getAO() {
dAo = 1.0;

#ifdef MAPTEXTURE
dAo *= texture2DBias(texture_aoMap, $UV, textureBias).$CH;
dAo *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/clearCoat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform float material_clearCoat;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_clearCoatMap;
#endif

void getClearCoat() {
ccSpecularity = 1.0;

Expand All @@ -15,7 +11,7 @@ void getClearCoat() {
#endif

#ifdef MAPTEXTURE
ccSpecularity *= texture2DBias(texture_clearCoatMap, $UV, textureBias).$CH;
ccSpecularity *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform float material_clearCoatGlossiness;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_clearCoatGlossMap;
#endif

void getClearCoatGlossiness() {
ccGlossiness = 1.0;

Expand All @@ -15,7 +11,7 @@ void getClearCoatGlossiness() {
#endif

#ifdef MAPTEXTURE
ccGlossiness *= texture2DBias(texture_clearCoatGlossMap, $UV, textureBias).$CH;
ccGlossiness *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export default /* glsl */`
#ifdef MAPTEXTURE
uniform sampler2D texture_clearCoatNormalMap;
uniform float material_clearCoatBumpiness;
#endif

void getClearCoatNormal() {
#ifdef MAPTEXTURE
vec3 normalMap = unpackNormal(texture2DBias(texture_clearCoatNormalMap, $UV, textureBias));
vec3 normalMap = unpackNormal(texture2DBias($SAMPLER, $UV, textureBias));
normalMap = mix(vec3(0.0, 0.0, 1.0), normalMap, material_clearCoatBumpiness);
ccNormalW = normalize(dTBN * normalMap);
#else
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/diffuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform vec3 material_diffuse;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_diffuseMap;
#endif

void getAlbedo() {
dAlbedo = vec3(1.0);

Expand All @@ -15,7 +11,7 @@ void getAlbedo() {
#endif

#ifdef MAPTEXTURE
vec3 albedoBase = gammaCorrectInput(texture2DBias(texture_diffuseMap, $UV, textureBias).$CH);
vec3 albedoBase = $DECODE(texture2DBias($SAMPLER, $UV, textureBias).$CH);
dAlbedo *= addAlbedoDetail(albedoBase);
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
export default /* glsl */`
#ifdef MAPTEXTURE
uniform sampler2D texture_diffuseDetailMap;
#endif

vec3 addAlbedoDetail(vec3 albedo) {
#ifdef MAPTEXTURE
vec3 albedoDetail = gammaCorrectInput(texture2DBias(texture_diffuseDetailMap, $UV, textureBias).$CH);
vec3 albedoDetail = $DECODE(texture2DBias($SAMPLER, $UV, textureBias).$CH);
return detailMode_$DETAILMODE(albedo, albedoDetail);
#else
return albedo;
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/emissive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ uniform vec3 material_emissive;
uniform float material_emissiveIntensity;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_emissiveMap;
#endif

void getEmission() {
dEmission = vec3(1.0);

Expand All @@ -23,7 +19,7 @@ void getEmission() {
#endif

#ifdef MAPTEXTURE
dEmission *= $DECODE(texture2DBias(texture_emissiveMap, $UV, textureBias)).$CH;
dEmission *= $DECODE(texture2DBias($SAMPLER, $UV, textureBias)).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/gloss.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform float material_shininess;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_glossMap;
#endif

void getGlossiness() {
dGlossiness = 1.0;

Expand All @@ -15,7 +11,7 @@ void getGlossiness() {
#endif

#ifdef MAPTEXTURE
dGlossiness *= texture2DBias(texture_glossMap, $UV, textureBias).$CH;
dGlossiness *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/iridescence.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform float material_iridescence;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_iridescenceMap;
#endif

void getIridescence() {
float iridescence = 1.0;

Expand All @@ -15,7 +11,7 @@ void getIridescence() {
#endif

#ifdef MAPTEXTURE
iridescence *= texture2DBias(texture_iridescenceMap, $UV, textureBias).$CH;
iridescence *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

dIridescence = iridescence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ export default /* glsl */`
uniform float material_iridescenceThicknessMax;

#ifdef MAPTEXTURE
uniform sampler2D texture_iridescenceThicknessMap;
uniform float material_iridescenceThicknessMin;
#endif

void getIridescenceThickness() {

#ifdef MAPTEXTURE
float blend = texture2DBias(texture_iridescenceThicknessMap, $UV, textureBias).$CH;
float blend = texture2DBias($SAMPLER, $UV, textureBias).$CH;
float iridescenceThickness = mix(material_iridescenceThicknessMin, material_iridescenceThicknessMax, blend);
#else
float iridescenceThickness = material_iridescenceThicknessMax;
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/metalness.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform float material_metalness;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_metalnessMap;
#endif

void getMetalness() {
float metalness = 1.0;

Expand All @@ -15,7 +11,7 @@ void getMetalness() {
#endif

#ifdef MAPTEXTURE
metalness *= texture2DBias(texture_metalnessMap, $UV, textureBias).$CH;
metalness *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default /* glsl */`
#ifdef MAPTEXTURE
uniform sampler2D texture_normalDetailMap;
uniform float material_normalDetailMapBumpiness;

vec3 blendNormals(vec3 n1, vec3 n2) {
Expand All @@ -13,7 +12,7 @@ vec3 blendNormals(vec3 n1, vec3 n2) {

vec3 addNormalDetail(vec3 normalMap) {
#ifdef MAPTEXTURE
vec3 normalDetailMap = unpackNormal(texture2DBias(texture_normalDetailMap, $UV, textureBias));
vec3 normalDetailMap = unpackNormal(texture2DBias($SAMPLER, $UV, textureBias));
normalDetailMap = mix(vec3(0.0, 0.0, 1.0), normalDetailMap, material_normalDetailMapBumpiness);
return blendNormals(normalMap, normalDetailMap);
#else
Expand Down
3 changes: 1 addition & 2 deletions src/graphics/program-lib/chunks/standard/frag/normalMap.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export default /* glsl */`
#ifdef MAPTEXTURE
uniform sampler2D texture_normalMap;
uniform float material_bumpiness;
#endif

void getNormal() {
#ifdef MAPTEXTURE
vec3 normalMap = unpackNormal(texture2DBias(texture_normalMap, $UV, textureBias));
vec3 normalMap = unpackNormal(texture2DBias($SAMPLER, $UV, textureBias));
normalMap = mix(vec3(0.0, 0.0, 1.0), normalMap, material_bumpiness);
dNormalW = normalize(dTBN * addNormalDetail(normalMap));
#else
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/opacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform float material_opacity;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_opacityMap;
#endif

void getOpacity() {
dAlpha = 1.0;

Expand All @@ -15,7 +11,7 @@ void getOpacity() {
#endif

#ifdef MAPTEXTURE
dAlpha *= texture2DBias(texture_opacityMap, $UV, textureBias).$CH;
dAlpha *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
3 changes: 1 addition & 2 deletions src/graphics/program-lib/chunks/standard/frag/parallax.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export default /* glsl */`
uniform sampler2D texture_heightMap;
uniform float material_heightMapFactor;

void getParallax() {
float parallaxScale = material_heightMapFactor;

float height = texture2DBias(texture_heightMap, $UV, textureBias).$CH;
float height = texture2DBias($SAMPLER, $UV, textureBias).$CH;
height = height * parallaxScale - parallaxScale*0.5;
vec3 viewDirT = dViewDirW * dTBN;

Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/sheen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ export default /* glsl */`
uniform vec3 material_sheen;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_sheenMap;
#endif

void getSheen() {
vec3 sheenColor = vec3(1, 1, 1);

Expand All @@ -16,7 +12,7 @@ void getSheen() {
#endif

#ifdef MAPTEXTURE
sheenColor *= $DECODE(texture2DBias(texture_sheenMap, $UV, textureBias)).$CH;
sheenColor *= $DECODE(texture2DBias($SAMPLER, $UV, textureBias)).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/sheenGloss.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export default /* glsl */`
uniform float material_sheenGlossiness;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_sheenGlossinessMap;
#endif

void getSheenGlossiness() {
float sheenGlossiness = 1.0;

Expand All @@ -15,7 +11,7 @@ void getSheenGlossiness() {
#endif

#ifdef MAPTEXTURE
sheenGlossiness *= texture2DBias(texture_sheenGlossinessMap, $UV, textureBias).$CH;
sheenGlossiness *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
6 changes: 1 addition & 5 deletions src/graphics/program-lib/chunks/standard/frag/specular.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ export default /* glsl */`
uniform vec3 material_specular;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_specularMap;
#endif

void getSpecularity() {
vec3 specularColor = vec3(1,1,1);

Expand All @@ -16,7 +12,7 @@ void getSpecularity() {
#endif

#ifdef MAPTEXTURE
specularColor *= $DECODE(texture2DBias(texture_specularMap, $UV, textureBias)).$CH;
specularColor *= $DECODE(texture2DBias($SAMPLER, $UV, textureBias)).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ export default /* glsl */`
uniform float material_specularityFactor;
#endif

#ifdef MAPTEXTURE
uniform sampler2D texture_specularityFactorMap;
#endif

void getSpecularityFactor() {
float specularityFactor = 1.0;

Expand All @@ -16,7 +12,7 @@ void getSpecularityFactor() {
#endif

#ifdef MAPTEXTURE
specularityFactor *= texture2DBias(texture_specularityFactorMap, $UV, textureBias).$CH;
specularityFactor *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif

#ifdef MAPVERTEX
Expand Down
Loading