Skip to content

Commit

Permalink
Material: Remove alphaHashScale
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Jun 8, 2023
1 parent d6dffff commit 80c40c4
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 35 deletions.
9 changes: 4 additions & 5 deletions examples/webgl_materials_alphahash.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
const params = {
alpha: 0.4,
alphaHash: true,
alphaHashScale: 0.1,
taa: true,
sampleLevel: 2,
};
Expand Down Expand Up @@ -139,8 +138,8 @@

const controls = new OrbitControls( camera, renderer.domElement );
controls.addEventListener( 'change', () => ( needsUpdate = true ) );
controls.minDistance = 5;
controls.maxDistance = 15;
controls.minDistance = 0.5;
controls.maxDistance = 100;
controls.update();

//
Expand All @@ -149,7 +148,6 @@

gui.add( params, 'alpha', 0, 1 ).onChange( onMaterialUpdate );
gui.add( params, 'alphaHash' ).onChange( onMaterialUpdate );
gui.add( params, 'alphaHashScale', 0.0, 2.0 ).onChange( onMaterialUpdate );

const taaFolder = gui.addFolder('Temporal Anti-Aliasing');

Expand Down Expand Up @@ -194,7 +192,6 @@

object.material.opacity = params.alpha;
object.material.alphaHash = params.alphaHash;
object.material.alphaHashScale = params.alphaHashScale;
object.material.transparent = !params.alphaHash;
object.material.depthWrite = params.alphaHash;

Expand All @@ -212,6 +209,8 @@

requestAnimationFrame( animate );

// group.rotation.y += 0.01;

if ( needsUpdate ) {

taaRenderPass.accumulate = false;
Expand Down
1 change: 0 additions & 1 deletion src/loaders/MaterialLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class MaterialLoader extends Loader {
if ( json.transparent !== undefined ) material.transparent = json.transparent;
if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash;
if ( json.alphaHashScale !== undefined ) material.alphaHashScale = json.alphaHashScale;
if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
Expand Down
3 changes: 0 additions & 3 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Material extends EventDispatcher {
this.opacity = 1;
this.transparent = false;
this.alphaHash = false;
this.alphaHashScale = 1;

this.blendSrc = SrcAlphaFactor;
this.blendDst = OneMinusSrcAlphaFactor;
Expand Down Expand Up @@ -356,7 +355,6 @@ class Material extends EventDispatcher {

if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
if ( this.alphaHash === true ) data.alphaHash = this.alphaHash;
if ( this.alphaHashScale !== 0 ) data.alphaHashScale = this.alphaHashScale;
if ( this.alphaToCoverage === true ) data.alphaToCoverage = this.alphaToCoverage;
if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
if ( this.forceSinglePass === true ) data.forceSinglePass = this.forceSinglePass;
Expand Down Expand Up @@ -479,7 +477,6 @@ class Material extends EventDispatcher {

this.alphaTest = source.alphaTest;
this.alphaHash = source.alphaHash;
this.alphaHashScale = source.alphaHashScale;
this.alphaToCoverage = source.alphaToCoverage;
this.premultipliedAlpha = source.premultipliedAlpha;
this.forceSinglePass = source.forceSinglePass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default /* glsl */`
#ifdef USE_ALPHAHASH
if ( diffuseColor.a < getAlphaHashThreshold( vPosition, alphaHashScale ) ) discard;
if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
#endif
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default /* glsl */`
* See: https://casual-effects.com/research/Wyman2017Hashed/index.html
*/
uniform float alphaHashScale;
const float ALPHA_HASH_SCALE = 0.05; // Derived from trials only, and may be changed.
float hash2D( vec2 value ) {
Expand All @@ -19,14 +19,14 @@ export default /* glsl */`
}
float getAlphaHashThreshold( vec3 position, float hashScale ) {
float getAlphaHashThreshold( vec3 position ) {
// Find the discretized derivatives of our coordinates
float maxDeriv = max(
length( dFdx( position.xyz ) ),
length( dFdy( position.xyz ) )
);
float pixScale = 1.0 / ( hashScale * maxDeriv );
float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
// Find two nearest log-discretized noise scales
vec2 pixScales = vec2(
Expand Down
5 changes: 1 addition & 4 deletions src/renderers/shaders/UniformsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const UniformsLib = {
alphaMapTransform: { value: /*@__PURE__*/ new Matrix3() },

alphaTest: { value: 0 },
alphaHashScale: { value: 1.0 }

},

Expand Down Expand Up @@ -208,7 +207,6 @@ const UniformsLib = {
alphaMap: { value: null },
alphaMapTransform: { value: /*@__PURE__*/ new Matrix3() },
alphaTest: { value: 0 },
alphaHashScale: { value: 1.0 },
uvTransform: { value: /*@__PURE__*/ new Matrix3() }

},
Expand All @@ -223,8 +221,7 @@ const UniformsLib = {
mapTransform: { value: /*@__PURE__*/ new Matrix3() },
alphaMap: { value: null },
alphaMapTransform: { value: /*@__PURE__*/ new Matrix3() },
alphaTest: { value: 0 },
alphaHashScale: { value: 1.0 }
alphaTest: { value: 0 }

}

Expand Down
18 changes: 0 additions & 18 deletions src/renderers/webgl/WebGLMaterials.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,6 @@ function WebGLMaterials( renderer, properties ) {

}

if ( material.alphaHash ) {

uniforms.alphaHashScale.value = material.alphaHashScale;

}

const envMap = properties.get( material ).envMap;

if ( envMap ) {
Expand Down Expand Up @@ -305,12 +299,6 @@ function WebGLMaterials( renderer, properties ) {

}

if ( material.alphaHash ) {

uniforms.alphaHashScale.value = material.alphaHashScale;

}

}

function refreshUniformsSprites( uniforms, material ) {
Expand Down Expand Up @@ -341,12 +329,6 @@ function WebGLMaterials( renderer, properties ) {

}

if ( material.alphaHash ) {

uniforms.alphaHashScale.value = material.alphaHashScale;

}

}

function refreshUniformsPhong( uniforms, material ) {
Expand Down

0 comments on commit 80c40c4

Please sign in to comment.