Skip to content

Commit

Permalink
LUTPass: Remove WebGL 1 fallback. (#27941)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Mar 19, 2024
1 parent c96c6bd commit 061b452
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 116 deletions.
15 changes: 0 additions & 15 deletions examples/jsm/loaders/LUT3dlLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import {
ClampToEdgeWrapping,
DataTexture,
Data3DTexture,
FileLoader,
FloatType,
Expand Down Expand Up @@ -144,19 +143,6 @@ export class LUT3dlLoader extends Loader {

}

const texture = new DataTexture();
texture.image.data = data;
texture.image.width = size;
texture.image.height = size * size;
texture.format = RGBAFormat;
texture.type = this.type;
texture.magFilter = LinearFilter;
texture.minFilter = LinearFilter;
texture.wrapS = ClampToEdgeWrapping;
texture.wrapT = ClampToEdgeWrapping;
texture.generateMipmaps = false;
texture.needsUpdate = true;

const texture3D = new Data3DTexture();
texture3D.image.data = data;
texture3D.image.width = size;
Expand All @@ -174,7 +160,6 @@ export class LUT3dlLoader extends Loader {

return {
size,
texture,
texture3D,
};

Expand Down
14 changes: 0 additions & 14 deletions examples/jsm/loaders/LUTCubeLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import {
ClampToEdgeWrapping,
DataTexture,
Data3DTexture,
FileLoader,
FloatType,
Expand Down Expand Up @@ -127,18 +126,6 @@ export class LUTCubeLoader extends Loader {

}

const texture = new DataTexture();
texture.image.data = data;
texture.image.width = size;
texture.image.height = size * size;
texture.type = this.type;
texture.magFilter = LinearFilter;
texture.minFilter = LinearFilter;
texture.wrapS = ClampToEdgeWrapping;
texture.wrapT = ClampToEdgeWrapping;
texture.generateMipmaps = false;
texture.needsUpdate = true;

const texture3D = new Data3DTexture();
texture3D.image.data = data;
texture3D.image.width = size;
Expand All @@ -158,7 +145,6 @@ export class LUTCubeLoader extends Loader {
size,
domainMin,
domainMax,
texture,
texture3D,
};

Expand Down
14 changes: 0 additions & 14 deletions examples/jsm/loaders/LUTImageLoader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Loader,
TextureLoader,
DataTexture,
Data3DTexture,
RGBAFormat,
UnsignedByteType,
Expand Down Expand Up @@ -124,18 +123,6 @@ export class LUTImageLoader extends Loader {
parse( dataArray, size ) {

const data = new Uint8Array( dataArray );
const texture = new DataTexture();
texture.image.data = data;
texture.image.width = size;
texture.image.height = size * size;
texture.format = RGBAFormat;
texture.type = UnsignedByteType;
texture.magFilter = LinearFilter;
texture.minFilter = LinearFilter;
texture.wrapS = ClampToEdgeWrapping;
texture.wrapT = ClampToEdgeWrapping;
texture.generateMipmaps = false;
texture.needsUpdate = true;

const texture3D = new Data3DTexture();
texture3D.image.data = data;
Expand All @@ -154,7 +141,6 @@ export class LUTImageLoader extends Loader {

return {
size,
texture,
texture3D,
};

Expand Down
76 changes: 6 additions & 70 deletions examples/jsm/postprocessing/LUTPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ const LUTShader = {

name: 'LUTShader',

defines: {
USE_3DTEXTURE: 1,
},

uniforms: {
lut3d: { value: null },

lut: { value: null },
lutSize: { value: 0 },
Expand All @@ -34,45 +29,9 @@ const LUTShader = {
fragmentShader: /* glsl */`
uniform float lutSize;
#if USE_3DTEXTURE
precision highp sampler3D;
uniform sampler3D lut3d;
#else
uniform sampler2D lut;
vec3 lutLookup( sampler2D tex, float size, vec3 rgb ) {
float sliceHeight = 1.0 / size;
float yPixelHeight = 1.0 / ( size * size );
// Get the slices on either side of the sample
float slice = rgb.b * size;
float interp = fract( slice );
float slice0 = slice - interp;
float centeredInterp = interp - 0.5;
float slice1 = slice0 + sign( centeredInterp );
// Pull y sample in by half a pixel in each direction to avoid color
// bleeding from adjacent slices.
float greenOffset = clamp( rgb.g * sliceHeight, yPixelHeight * 0.5, sliceHeight - yPixelHeight * 0.5 );
vec2 uv0 = vec2(
rgb.r,
slice0 * sliceHeight + greenOffset
);
vec2 uv1 = vec2(
rgb.r,
slice1 * sliceHeight + greenOffset
);
vec3 sample0 = texture2D( tex, uv0 ).rgb;
vec3 sample1 = texture2D( tex, uv1 ).rgb;
return mix( sample0, sample1, abs( centeredInterp ) );
}
#endif
precision highp sampler3D;
uniform sampler3D lut;
varying vec2 vUv;
uniform float intensity;
Expand All @@ -88,15 +47,8 @@ const LUTShader = {
float halfPixelWidth = 0.5 / lutSize;
vec3 uvw = vec3( halfPixelWidth ) + val.rgb * ( 1.0 - pixelWidth );
#if USE_3DTEXTURE
lutVal = vec4( texture( lut3d, uvw ).rgb, val.a );
#else
lutVal = vec4( lutLookup( lut, lutSize, uvw ), val.a );
#endif
lutVal = vec4( texture( lut, uvw ).rgb, val.a );
gl_FragColor = vec4( mix( val, lutVal, intensity ) );
Expand All @@ -111,31 +63,15 @@ class LUTPass extends ShaderPass {
set lut( v ) {

const material = this.material;

if ( v !== this.lut ) {

material.uniforms.lut3d.value = null;
material.uniforms.lut.value = null;

if ( v ) {

const is3dTextureDefine = v.isData3DTexture ? 1 : 0;
if ( is3dTextureDefine !== material.defines.USE_3DTEXTURE ) {

material.defines.USE_3DTEXTURE = is3dTextureDefine;
material.needsUpdate = true;

}

material.uniforms.lutSize.value = v.image.width;
if ( v.isData3DTexture ) {

material.uniforms.lut3d.value = v;

} else {

material.uniforms.lut.value = v;

}
material.uniforms.lut.value = v;

}

Expand All @@ -145,7 +81,7 @@ class LUTPass extends ShaderPass {

get lut() {

return this.material.uniforms.lut.value || this.material.uniforms.lut3d.value;
return this.material.uniforms.lut.value;

}

Expand Down
5 changes: 2 additions & 3 deletions examples/webgl_postprocessing_3dlut.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
const params = {
enabled: true,
lut: 'Bourbon 64.CUBE',
intensity: 1,
use2DLut: false,
intensity: 1
};

const lutMap = {
Expand Down Expand Up @@ -184,7 +183,7 @@
if ( lutMap[ params.lut ] ) {

const lut = lutMap[ params.lut ];
lutPass.lut = params.use2DLut ? lut.texture : lut.texture3D;
lutPass.lut = lut.texture3D;

}

Expand Down

0 comments on commit 061b452

Please sign in to comment.