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

Extend WebGL to support multiple shaders per program? #1175

Open
matthijsgroen opened this issue Feb 16, 2018 · 3 comments
Open

Extend WebGL to support multiple shaders per program? #1175

matthijsgroen opened this issue Feb 16, 2018 · 3 comments
Assignees

Comments

@matthijsgroen
Copy link
Member

_makeProgram: function(shader) {
var gl = this.context;
var fragmentShader = this._compileShader(shader.fragmentCode, gl.FRAGMENT_SHADER);
var vertexShader = this._compileShader(shader.vertexCode, gl.VERTEX_SHADER);
var shaderProgram = gl.createProgram();
gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
throw ("Could not initialise shaders");
}
shaderProgram.viewport = gl.getUniformLocation(shaderProgram, "uViewport");
return shaderProgram;
},

I'm investigating if I could extend the Particles component with WebGL support. Of examples seen elsewhere, the trick is to create a texture buffer, and have one shader shuffling values around in the buffer, and another shader rendering points based on values of that texture. (this is at least my understanding of it). But currently only a single vertex and fragment shader can be linked to a webgl program.

(See: https://github.com/nopjia/webgl-particles/blob/master/app/js/graphics.js#L310)

Also what I see online (in the repo of @nopjia, but also in examples on the mozilla site) is that after the linking of the programs, shaders are detached and deleted. Crafty does not do this. Is this intended? I do not possess enough knowledge about WebGL to know the impact of keeping it (or removing it for that matter!)

@starwed
Copy link
Member

starwed commented Feb 26, 2018

It should be possible for a WebGL entity to just define their own program, without using the built in helper methods -- IIRC they just need to define the setViewportUniforms, renderBatch, and switchTo methods. I'm not sure, but that might let you use the sort of multishader approach you're talking about.

Also what I see online (in the repo of @nopjia, but also in examples on the mozilla site) is that after the linking of the programs, shaders are detached and deleted. Crafty does not do this. Is this intended? I do not possess enough knowledge about WebGL to know the impact of keeping it (or removing it for that matter!)

Quite possibly they can be detached/deleted without issue once linked; I can look into that. (Although feel free to just add the code for that and report back if there are any issues! :) )

@matthijsgroen
Copy link
Member Author

I have implemented a particle emitter last week using WebGL, it is almost stable. When it is, I would like to contribute it here, but I think should get some extra pair of 👀 before merging.

@matthijsgroen matthijsgroen self-assigned this Dec 6, 2019
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

No branches or pull requests

2 participants