Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions docs/api/en/constants/Textures.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,18 @@ <h2>BPTC Compressed Texture Format</h2>
[link:https://www.khronos.org/registry/webgl/extensions/EXT_texture_compression_bptc/ EXT_texture_compression_bptc] extension. <br /><br />
</p>

<h2>Texture Comparison functions</h2>
<code>
THREE.NeverCompare
THREE.LessCompare
THREE.EqualCompare
THREE.LessEqualCompare
THREE.GreaterCompare
THREE.NotEqualCompare
THREE.GreaterEqualCompare
THREE.AlwaysCompare
</code>

<h2>Internal Formats</h2>
<code>
'ALPHA'
Expand Down
7 changes: 7 additions & 0 deletions docs/api/en/textures/DepthTexture.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ <h3>[page:Texture.generateMipmaps .generateMipmaps]</h3>
<h3>[property:Boolean isDepthTexture]</h3>
<p>Read-only flag to check if a given object is of type [name].</p>

<h3>[property:String compareFunction]</h3>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a string?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@WestLangley WestLangley May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an integer, correct?. Also, the default should be specified in the docs.

Edit: It's null or an integer; hence, a number.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't any default value as otherwise it would involve that the compare function is enabled by default.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is null. And the docs should explain the consequences of a null value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed via 43c701c.

<p>
This is used to define the comparison function used when comparing texels in the depth texture to the value in the depth buffer.<br /><br/>

See the [page:Textures texture constants] page for details of other functions.
</p>

<h2>Methods</h2>

<p>See the base [page:Texture Texture] class for common methods.</p>
Expand Down
9 changes: 9 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ export const NotEqualStencilFunc = 517;
export const GreaterEqualStencilFunc = 518;
export const AlwaysStencilFunc = 519;

export const NeverCompare = 512;
export const LessCompare = 513;
export const EqualCompare = 514;
export const LessEqualCompare = 515;
export const GreaterCompare = 516;
export const NotEqualCompare = 517;
export const GreaterEqualCompare = 518;
export const AlwaysCompare = 519;

export const StaticDrawUsage = 35044;
export const DynamicDrawUsage = 35048;
export const StreamDrawUsage = 35040;
Expand Down
20 changes: 19 additions & 1 deletion src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, UnsignedByteType, _SRGBAFormat, NoColorSpace, LinearSRGBColorSpace, SRGBColorSpace } from '../../constants.js';
import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, UnsignedByteType, _SRGBAFormat, NoColorSpace, LinearSRGBColorSpace, SRGBColorSpace, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare } from '../../constants.js';
import * as MathUtils from '../../math/MathUtils.js';
import { ImageUtils } from '../../extras/ImageUtils.js';
import { createElementNS } from '../../utils.js';
Expand Down Expand Up @@ -526,6 +526,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
[ LinearMipmapLinearFilter ]: _gl.LINEAR_MIPMAP_LINEAR
};

const compareToGL = {
[ NeverCompare ]: _gl.NEVER,
[ AlwaysCompare ]: _gl.ALWAYS,
[ LessCompare ]: _gl.LESS,
[ LessEqualCompare ]: _gl.LEQUAL,
[ EqualCompare ]: _gl.EQUAL,
[ GreaterEqualCompare ]: _gl.GEQUAL,
[ GreaterCompare ]: _gl.GREATER,
[ NotEqualCompare ]: _gl.NOTEQUAL
};

function setTextureParameters( textureType, texture, supportsMips ) {

if ( supportsMips ) {
Expand Down Expand Up @@ -570,6 +581,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

if ( texture.compareFunction ) {

_gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE );
_gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_FUNC, compareToGL[ texture.compareFunction ] );

}

if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {

const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
Expand Down
22 changes: 22 additions & 0 deletions src/textures/DepthTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,31 @@ class DepthTexture extends Texture {
this.flipY = false;
this.generateMipmaps = false;

this.compareFunction = null;

}


copy( source ) {

this.compareFunction = source.compareFunction;

super.copy( source );

return this;

}

toJSON( meta ) {

const data = super.toJSON( meta );

if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction;

return data;

}

}

export { DepthTexture };