Skip to content

Conversation

mbredif
Copy link
Contributor

@mbredif mbredif commented Jun 22, 2018

Allowing slashes in the filenames of shader chunk includes would allow to use the same pattern as in C++ includes : you could scope the name of the shader by the name of the library that provides the chunk

in the custom shader:

#include <mylib/mychunk>

in the custom ShaderMaterial:

var MyShaderChunk = {};
MyShaderChunk['mylib/mychunk'] = '// some glsl code';
Object.assign(THREE.ShaderChunk, MyShaderChunk);

As an extension, the call to Object.assign could be wrapped in a more elegant function that optionnally prepends the path prefix :

THREE.ShaderChunk.install = function install(chunks, path) {
    if (!path) return Object.assign(this, chunks);
    Object.keys(chunks).forEach((key) => {
        this[path + key] = chunks[key];
    });
};
var MyShaderChunk = {};
MyShaderChunk.mychunk = '// some glsl code';
THREE.ShaderChunk.install(MyShaderChunk, 'mylib/');

@mrdoob mrdoob added this to the r95 milestone Jul 2, 2018
@mrdoob mrdoob merged commit ce9e859 into mrdoob:dev Jul 2, 2018
@mrdoob
Copy link
Owner

mrdoob commented Jul 2, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants