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

WebGPURenderer: support Nodes buffer() in GLSLNodeBuilder and WebGLSLBackend #26988

Merged
merged 1 commit into from
Oct 19, 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
8 changes: 4 additions & 4 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class WebGLBackend extends Backend {
const bindingData = this.get( binding );
const index = bindingData.index;

if ( binding.isUniformsGroup ) {
if ( binding.isUniformsGroup || binding.isUniformBuffer ) {

gl.bindBufferBase( gl.UNIFORM_BUFFER, index, bindingData.bufferGPU );

Expand Down Expand Up @@ -628,7 +628,7 @@ class WebGLBackend extends Backend {
const bindingData = this.get( binding );
const index = bindingData.index;

if ( binding.isUniformsGroup ) {
if ( binding.isUniformsGroup || binding.isUniformBuffer ) {

const location = gl.getUniformBlockIndex( programGPU, binding.name );
gl.uniformBlockBinding( programGPU, location, index );
Expand Down Expand Up @@ -735,7 +735,7 @@ class WebGLBackend extends Backend {

for ( const binding of bindings ) {

if ( binding.isUniformsGroup ) {
if ( binding.isUniformsGroup || binding.isUniformBuffer ) {

const bufferGPU = gl.createBuffer();
const data = binding.buffer;
Expand Down Expand Up @@ -769,7 +769,7 @@ class WebGLBackend extends Backend {

const gl = this.gl;

if ( binding.isUniformsGroup ) {
if ( binding.isUniformsGroup || binding.isUniformBuffer ) {

const bindingData = this.get( binding );
const bufferGPU = bindingData.bufferGPU;
Expand Down
22 changes: 22 additions & 0 deletions examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MathNode, GLSLNodeParser, NodeBuilder, NodeMaterial, FunctionNode } from '../../../nodes/Nodes.js';

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

Expand Down Expand Up @@ -156,6 +157,15 @@ ${ flowData.code }

snippet = `samplerCube ${uniform.name};`;

} else if ( uniform.type === 'buffer' ) {

const bufferNode = uniform.node;
const bufferType = this.getType( bufferNode.bufferType );
const bufferCount = bufferNode.bufferCount;

const bufferCountSnippet = bufferCount > 0 ? bufferCount : '';
snippet = `${bufferNode.name} {\n\t${bufferType} ${uniform.name}[${bufferCountSnippet}];\n};\n`;

} else {

const vectorType = this.getVectorType( uniform.type );
Expand Down Expand Up @@ -511,6 +521,18 @@ void main() {

this.bindings[ shaderStage ].push( uniformGPU );

} else if ( type === 'buffer' ) {

node.name = `NodeBuffer_${node.id}`;

const buffer = new UniformBuffer( node.name, node.value );

uniformNode.name = `buffer${node.id}`;

this.bindings[ shaderStage ].push( buffer );

uniformGPU = buffer;

} else {

let uniformsGroup = this.uniformsGroup[ shaderStage ];
Expand Down