Skip to content

Commit

Permalink
WebGLBackend: Morph Texture (#27218)
Browse files Browse the repository at this point in the history
* WebGLBackend: Morph Texture

* screenshot
  • Loading branch information
sunag committed Nov 20, 2023
1 parent 245750c commit c20ed03
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/jsm/renderers/webgl/WebGLBackend.js
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
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 );

}

}

return nodeType;

}

getAttributes( shaderStage ) {

let snippet = '';
Expand Down
7 changes: 3 additions & 4 deletions examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js
@@ -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.

0 comments on commit c20ed03

Please sign in to comment.