Jump to content

GLSL Shader Question (Post Process Pass Varying Woes)


Pryme8
 Share

Recommended Posts

https://www.babylonjs-playground.com/#NAG06Y#70

"Error: Varyings with the same name but different type, or statically used varyings in fragment shader are not declared in vertex shader: nUV"

Not sure why I am getting this error, the two fragments in question are at the top of the file.
Here is the desired result:
https://www.babylonjs-playground.com/#NAG06Y#71

The thing is normally just adding a varying two both of the fragments makes it work, gotta be missing something simple.

Link to comment
Share on other sites

Only thing I could see is the nUv.xxx.  shader compiler seems to not want to allow that - maybe incorrectly thinks it's a vec3?
https://www.babylonjs-playground.com/#NAG06Y#74
edit: no, i was wrong :)

Interestingly a different message in Firefox.
Error: Varying `nUV` has static-use in the frag shader, but is undeclared in the vert shader.
https://dxr.mozilla.org/mozilla-beta/source/dom/canvas/WebGLShaderValidator.cpp#363

Link to comment
Share on other sites

55 minutes ago, Pryme8 said:

should use the vertex shader that is matching in name to the fragment

You are right.  I checked my projects and I have many different shaders using "varying vec2 vUV;".  I think I had already commented out your post process, so that's why the effect was compiling for me.  Looks like maybe something in the post process is clobbering your shader code or removing the varyings?  Would be nice if there was a way to see the full shader program, because what you have looks OK to me.  I really want to see where the voodoo is here...

Link to comment
Share on other sites

https://github.com/BabylonJS/Babylon.js/blob/master/src/PostProcess/babylon.passPostProcess.ts

I think this is the culprit.

the super defaults to "pass" 


*EDIT* 

Nevermind found it:
 

https://github.com/BabylonJS/Babylon.js/blob/master/src/PostProcess/babylon.postProcess.ts#L243

  * @param vertexUrl The url of the vertex shader to be used. (default: "postprocess")

 

Link to comment
Share on other sites

So:)

You cannot reuse the same fragment for a material and a postprocess: https://www.babylonjs-playground.com/#NAG06Y#83

The postprocess assumes that you only provide the fragment shader (the associated vertex shader is provided by babylon.js: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/postprocess.vertex.fx)

So as you do not provide the vertex shader, you cannot add varyings in your fragment.

Link to comment
Share on other sites

Nope, it was using the nUV vec2 that was declared in the main loop not the varying.
https://www.babylonjs-playground.com/#NAG06Y#88

Here is my "working" setup which does not allow me to define any varyings
https://www.babylonjs-playground.com/#NAG06Y#96
And then here is the post Process with a custom vertex defined in it constructor, which seems to break it all
https://www.babylonjs-playground.com/#NAG06Y#97

I have also tried your above suggestion, with not reusing but that did not fix it as well.

Can anyone tell me what #97 is saying in the spector report?  

Link to comment
Share on other sites

I mean honestly its not important, cause the work around is to just define the nUV var that I want in the main loop or as a define so Im not to pressed.

But it would be cool to work out some of this for future/more dynamic problems.

Link to comment
Share on other sites

Well even in your #97 you are sharing the same fragment between Postprocess and material and as I mentioned before this is not possible.

 

Postprocesses have a already defined vertex shader that you can't change so fragment shader used with postprocesses CANNOT add varyings

Link to comment
Share on other sites

11 minutes ago, dbawel said:

I've called and left messages, but haven't heard from you in a while.

I'm impossible to get a hold of these days.  I leave my phone at home as to not get distracted by life. Email is the best method brother ^_^.

 

Link to comment
Share on other sites

So this is "solved"
The reason for the error that I was experiencing while trying to define a custom varying was that I was referencing an attribute that effectively would never be bound because that data does not exist in the postPass due to there not being geometry and only really being in screenspace coordinates.  Which essentially make the positions attribute a vec2 in the postPass and I was trying to bind to the wrong attribute.

-> lost of headache over something that honestly does not matter... smh,  cause honestly how much more performance am I getting out of using the attribute vs defining it in the main for a single frame being processed....  It was more a matter of principal.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...