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

WebGLBackend: Morph Texture #27218

Merged
merged 2 commits into from
Nov 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,13 @@ class WebGLBackend extends Backend {

}

if ( attributeData.isFloat ) {
if ( attributeData.isInteger ) {

gl.vertexAttribPointer( i, attribute.itemSize, attributeData.type, false, stride, offset );
gl.vertexAttribIPointer( i, attribute.itemSize, attributeData.type, stride, offset );

} else {

gl.vertexAttribIPointer( i, attribute.itemSize, attributeData.type, stride, offset );
gl.vertexAttribPointer( i, attribute.itemSize, attributeData.type, attribute.normalized, stride, offset );

}

Expand Down
26 changes: 26 additions & 0 deletions examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';

import { NodeSampledTexture, NodeSampledCubeTexture } from '../../common/nodes/NodeSampledTexture.js';

import { IntType } from 'three';

const glslMethods = {
[ MathNode.ATAN2 ]: 'atan',
textureDimensions: 'textureSize'
Expand Down Expand Up @@ -253,6 +255,30 @@ ${ flowData.code }

}

getTypeFromAttribute( attribute ) {

let nodeType = super.getTypeFromAttribute( attribute );

if ( /^[iu]/.test( nodeType ) && attribute.gpuType !== IntType ) {

let dataAttribute = attribute;

if ( attribute.isInterleavedBufferAttribute ) dataAttribute = attribute.data;

const array = dataAttribute.array;

if ( ( array instanceof Uint32Array || array instanceof Int32Array ) === false ) {

nodeType = nodeType.slice( 1 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Something like this.getTypeFromLength( this.getTypeLength( nodeType ) ) may be more reliable? /ping @sunag

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this specific case I think it is not necessary because of the conditional: /^[iu]/.test( nodeType )


}

}

return nodeType;

}

getAttributes( shaderStage ) {

let snippet = '';
Expand Down
7 changes: 3 additions & 4 deletions examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IntType } from 'three';

class WebGLAttributeUtils {

constructor( backend ) {
Expand Down Expand Up @@ -36,19 +38,16 @@ class WebGLAttributeUtils {
//attribute.onUploadCallback();

let type;
let isFloat = false;

if ( array instanceof Float32Array ) {

type = gl.FLOAT;
isFloat = true;

} else if ( array instanceof Uint16Array ) {

if ( attribute.isFloat16BufferAttribute ) {

type = gl.HALF_FLOAT;
isFloat = true;

} else {

Expand Down Expand Up @@ -91,7 +90,7 @@ class WebGLAttributeUtils {
type,
bytesPerElement: array.BYTES_PER_ELEMENT,
version: attribute.version,
isFloat
isInteger: type === gl.INT || type === gl.UNSIGNED_INT || attribute.gpuType === IntType
} );

}
Expand Down
Binary file modified examples/screenshots/webgl_morphtargets_face.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.