[2.1] World position in PBS vs Unlit shader Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
gabbsson
Halfling
Posts: 65
Joined: Wed Aug 08, 2018 9:03 am
x 13

[2.1] World position in PBS vs Unlit shader

Post by gabbsson »

Hello!

I've come to reaiize that my clipping code only works in PBS shader, seemingly because the world position is different in the Unlit shader.
I pass my clipping planes the exact same way in both (HlmsListener), even tried with a hardcoded plane so that shouldn't be the issue.

For PBS it works just as expected, its a static in-world plane (objects that move will be clipped if they pass it etc).
For Unlit the best i can get is something that is static "on the camera". I.e it moves with the camera movement.

The big difference I can find is that PBS has a world matrix which is used to calculate the world position.
Unlit instead has a matrix for the entire worldViewProj matrix and then to get the world pos it multiplies that by an inverse viewProj matrix.
The Unlit shader contains some "example" code for calculating the worldPos and using it in a gl_ClipDistance case, I have simply extended that.

I still haven't learned how to properly debug GLSL etc.. everything runs it just doesn't clip the way I would expect.
My suspicion is that something is funky with the inverse matrix.

So my question is:
Have i missed setting some property or similar in the Hlms?
Is there a different way to go about this?
Do I have to send my own world matrix?

EDIT:

I should add that I set the hlms_global_clip_planes which one of the properties that makes sure invViewProj is added to the shader from the StructsUnlit_piece_all.any

So it would seem likely that simply setting that property is not enough, and I need to make sure that matrix is actually set in the code?

EDIT:

Further investigation (which I should have done before posting the first time hehe) shows that the HlmsUnlit only writes the inverse matrix if the camera "isReflected". Not really sure what do do with this information in regards to a solution, but that seems to be the problem at least..
As far as I know the camera is not reflected by default?

Cheers!
hedphelym
Gremlin
Posts: 180
Joined: Tue Nov 25, 2008 10:58 am
Location: Kristiansand, Norway
x 23
Contact:

Re: [2.1] World position in PBS vs Unlit shader

Post by hedphelym »

I do not have a answer to your question, but I have a tip.
For debugging use Renderdoc - https://renderdoc.org/
It lets you debug very easily, every step of your frame, and shaders + variables inside there and so on.
Works very well with Ogre 2.1. It's a lifesaver when it comes to debugging shaders.
gabbsson
Halfling
Posts: 65
Joined: Wed Aug 08, 2018 9:03 am
x 13

Re: [2.1] World position in PBS vs Unlit shader

Post by gabbsson »

hedphelym wrote: Thu Jun 27, 2019 12:35 pm I do not have a answer to your question, but I have a tip.
For debugging use Renderdoc - https://renderdoc.org/
It lets you debug very easily, every step of your frame, and shaders + variables inside there and so on.
Works very well with Ogre 2.1. It's a lifesaver when it comes to debugging shaders.
Thanks! I've seen posts that mention it but I've never started using it.
I guess its overdue I give it a try, even if it probably wont do more than confirm my suspicion about the matrix not being assigned.
Will check it out!
gabbsson
Halfling
Posts: 65
Joined: Wed Aug 08, 2018 9:03 am
x 13

Re: [2.1] World position in PBS vs Unlit shader

Post by gabbsson »

I ended up manually sending the world matrix (_getParentNodeFullTransform) into the vertex shader.
Seems to be working as intended.
Post Reply