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

add IS_VERTEX and IS_FRAGMENT to shader defines #11050

Closed
wants to merge 1 commit into from

Conversation

pailhead
Copy link
Contributor

Allows for adding stuff to commons chunk for example.

#10750

Allows for adding stuff to commons chunk for example.

mrdoob#10750
@pailhead pailhead mentioned this pull request Mar 23, 2017
@mrdoob
Copy link
Owner

mrdoob commented Mar 26, 2017

If I remember correctly, you're not supposed to add anything before the precision line.

@pailhead
Copy link
Contributor Author

You are right, I messed something up and added this thing twice. Still good to have per that other discussion?

@mrdoob
Copy link
Owner

mrdoob commented Mar 26, 2017

Hmm, I cannot think of any specific use case for this right now, but I suspect it is indeed something handy to have.

@WestLangley
Copy link
Collaborator

Hmm, I cannot think of any specific use case for this right now, but I suspect it is indeed something handy to have.

It can't be handy if a use-case cannot be identified. :)

What is the compelling use-case?

@pailhead
Copy link
Contributor Author

pailhead commented Mar 26, 2017

Cant link to the comment in the review in the other thread. Mrdoob suggested some glsl should be in the commons chunk but it exists in both very and frag. Say you want to add attribute float u_should_exist_in_all_shaders you can't use commons.

@pailhead
Copy link
Contributor Author

Just to make this idea seem less idiotic, it is now becoming more obvious what was the use case for this.

common.glsl seemed like the most appropriate place to append code that should be in global scope. It is guaranteed to be in every shader, we would have access to the functions. The reason why it doesn't work is because the same chunk ends up in both vert and frag shaders.

Basically it was supposed to do what % global_vertex % and % global_fragment % should do in:

#11475

@pailhead pailhead closed this Jun 20, 2017
@pailhead pailhead reopened this Jan 20, 2018
@pailhead
Copy link
Contributor Author

Using the onBeforeCompile, i think i would really like this feature.

@mrdoob
Copy link
Owner

mrdoob commented Jan 20, 2018

Could you elaborate?

@pailhead
Copy link
Contributor Author

pailhead commented Jan 20, 2018

const myGLSL = 'attribute vec3 aMyAttribute;\n`

myMaterial.onBeforeCompile( shader=>{
  shader.vertexShader = myGLSL + shader.vertexShader // messes up extensions and such?
  
  shader.vertexShader = shader.vertexShader.replace( '#include <what>`, "?" + myGLSL  )
})

Actually now having written it like this it's not so much of a problem. I was thinking of something like

float sharedFunction( float i ) {}

#ifdef IS_VERTEX
attribute vec3 aMyAttr;
#endif
const myGlobalReplaceChunk = THREE.ShaderChunk.global + myGLSL

It could be like the first super mini step towards the properly named hooks etc. but maybe not worth it. Looking for void main and just appending above it might be good enough, not sure what would be the best pattern.

@pailhead pailhead closed this Jan 20, 2018
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