Advanced Effects

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Advanced Effects

Post by Mel »

Wait... are you looking for the rays from the "camera position" to each screen pixel? In NDC that's the simplest! :), just get the inverse of the projection matrix, and transform the screen coordinates back to view space, that gives the ray directions you're looking for

look at this, just figure that the arrow is pointing left instead of right ;)

Image
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Aha! The light shines forth! Thanks!

If we could have vectors (our rays) with Distance/Length of each being the
"Depth Sample" pixel (+ or - Cam_Pos), then we'd have something like "World Position" to work from.. Cool!

So if we have "World Normals", "Depth", and "Diffuse Color" in our G buffer we wouldn't even
need the "RGB Encoded Position".. :lol:

Mel.. You got some links to example code or something?
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Advanced Effects

Post by devsh »

Or you could just pass FarUpperRight and FarLowerLeft view space coordinates of the view frustum and do

Code: Select all

vec3 worldPos = mix(FarLowerLeft,FarUpperRight,UV.xy)*linearDepth;
where UV.xy = NDC.xy*0.5+vec2(0.5)

To get world space, you have to pass all 4 far corners and camera position, and use 4 mix operations
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Brilliant! This lead me to these two locations..

http://www.songho.ca/opengl/gl_transform.html (has two cool ZIPPED little Tools to visualize Matrices)

https://www.opengl.org/discussion_board ... oordinates

Working on it..

I'm also currently trying to understand where ZERO Degrees are and in which direction it rotates in Irrlicht XZ and ZY Planes.

But.. If I could get these "Radius or Direction" straight from Normalized Device Coordinates (NDC) then perhaps Asin and Theta could be bypassed
and Fragment POsition XYZ could be calculated as relative to Camera Position..

Still a bit unclear..
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Just realized we can render Tangents and Bi-Normals to G Buffer too..
Extra Bonus..
(I hope more than 4 images to Shaders have priority for Irrlicht 9)
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Question..

I create a camera..

I set the Position to 0.0, 0.0, 0.0.

I set the Target to 0.0, 0.0, 1.0.

I "move" the camera to 0.0, 0.0, 10 (using the key-map assigned)..

The Target AFTER this move is NOT 0.0, 0.0, 11..

Why does "Target" NOT remain RELATIVE to POSITION?

I'm definitely missing something here..

Image
CuteAlien
Admin
Posts: 9927
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Advanced Effects

Post by CuteAlien »

You often need to change camera position and target separate which would be tricky if one automatically updates the other (didn't read whole thread, so I hope your question in last post was about Irrlicht camera functions...)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Yes, Irrlicht Camera. Thanks. I see that NDC is probably the way to go to get a decent Fragpos, but
I'd like to see if my crazy Sin Cos method had a chance of working..
(it may have had less Instructions than the NDC way which seems to depend on quite a few matrix Ops)

Clue..

Extract from the DOC..

Code: Select all

 
virtual void irr::scene::ICameraSceneNode::bindTargetAndRotation    (   bool    bound   )   [pure virtual]
 
Binds the camera scene node's rotation to its target position and vice vera, or unbinds them.
When bound, calling

Code: Select all

 setRotation()
will update the camera's target position to be along its +Z axis,
and likewise calling

Code: Select all

 setTarget() 
will update its rotation so that its +Z axis will point at the target point.
FPS camera use this binding by default; other cameras do not.

Parameters:
bound True to bind the camera's scene node rotation and targetting, false to unbind them.
See also:

Code: Select all

 getTargetAndRotationBinding() 
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Funny thing..
While the Target does unexpected things, my acquired Theta's always seem to be correct
with a slight jitter at the 6'th decimal point to the right. (which is fine by me)
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

It's amazing how quickly one can make assumptions about an engine when you've been using a different one!
All of this Theta stuff was totally unnecessary as in Irrlicht they can be read from the matrices!

But, If anyone had ever wondered about getting XZ and ZY Thetas (angles in degrees and human readable form) for
what ever reason then this is how I spent my day barking up the wrong tree..

This code simply brings those planar Thetas if you wanted a cannon pointing at a target or something..
It now has no bearing on getting Fragment Pos XYZ,
which I now know concerns TheCamera->getViewFrustum()->getFarLeftUp(); etc etc.. (thanks! Devsh, Mel and Cute Alien)

This might be interesting though even if just for chuckles..

Code: Select all

 
 CameraPosition = TheDevice->getSceneManager()->getActiveCamera()->getAbsolutePosition();
 CameraTarget = TheDevice->getSceneManager()->getActiveCamera()->getTarget();
 // COULD PERHAPS BE DONE IN SHADERS BUT ALSO TESTED HERE (for GUI output)..
 CamDeltaX = CameraTarget.X - CameraPosition.X;
 CamDeltaY = CameraTarget.Y - CameraPosition.Y;
 CamDeltaZ = CameraTarget.Z - CameraPosition.Z;
 
 CamRadXZ = sqrt( ( CamDeltaX * CamDeltaX) + ( CamDeltaZ * CamDeltaZ));
 CamRadZY = sqrt( ( CamDeltaZ * CamDeltaZ) + ( CamDeltaY * CamDeltaY));
 
 // This Theta remains correct in terms of how Irrlicht deals with the Quadrants (dark and unclear)..
 // They are correct however..
 CamThetaXZ = asin (CamDeltaX / CamRadXZ) / 0.0174532;
 CamThetaZY = asin (CamDeltaZ / CamRadZY) / 0.0174532;
 
 // How The Thetas (as orthographically viewed on the XZ and ZY Planes) are "Fixed" depends on a few decisions..
 if (CamDeltaX <  0.0  && CamDeltaZ >  0.0 ) {CamThetaXZ = 360.0 + CamThetaXZ;}
 if (CamDeltaX >  0.0  && CamDeltaZ <  0.0 ) {CamThetaXZ = 180.0 - CamThetaXZ;}
 if (CamDeltaX <  0.0  && CamDeltaZ <  0.0 ) {CamThetaXZ = 180.0 - CamThetaXZ;}
 
 if (CamDeltaY <  0.0  && CamDeltaZ >  0.0 ) {CamThetaZY = 180.0 - CamThetaZY;}
 if (CamDeltaY >  0.0  && CamDeltaZ <  0.0 ) {CamThetaZY = 360.0 + CamThetaZY;}
 if (CamDeltaY <  0.0  && CamDeltaZ <  0.0 ) {CamThetaZY = 180.0 - CamThetaZY;}
 
 CamTargVectorX = 1.0 * sin (CamThetaXZ * 0.0174532);
 CamTargVectorY = 1.0 * cos (CamThetaZY * 0.0174532);
 CamTargVectorZ = 1.0 * cos (CamThetaXZ * 0.0174532);
 
 // At the end of the day this should always be 1.0 
 TargVectorLenTest = sqrt ((CamTargVectorX * CamTargVectorX) + ( CamTargVectorY * CamTargVectorY) + (CamTargVectorZ * CamTargVectorZ));
 
 // Normalise the Vector..
 
 CamTargVectorNORMEDX = CamTargVectorX;
 CamTargVectorNORMEDY = CamTargVectorY;
 CamTargVectorNORMEDZ = CamTargVectorZ;
 
 CamTargVectorNORMEDX /= TargVectorLenTest;
 CamTargVectorNORMEDY /= TargVectorLenTest;
 CamTargVectorNORMEDZ /= TargVectorLenTest;
 
 TargVectorLenTest = sqrt ((CamTargVectorNORMEDX * CamTargVectorNORMEDX)
                           + ( CamTargVectorNORMEDY * CamTargVectorNORMEDY)
                           + (CamTargVectorNORMEDZ * CamTargVectorNORMEDZ));
 
Image
Last edited by Vectrotek on Wed Jan 25, 2017 1:35 pm, edited 1 time in total.
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

O.K. That's that..

Now for the real cool stuff..
Acquire "Fragment Position" based on "Opposing Far Plane Corners", "Camera Position", "Matched Depth Matters", "UV Probing" and "Pre-Rendered 8 or 24 bit Depth", ala NDC!
(sound right?)

Let's see..
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

I see this is not the first time this discussion had occurred..
http://irrlicht.sourceforge.net/forum/v ... hp?t=42374
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Can't say I'm not trying..

Tried to set up a little hypothetical situation..
(Clearly I'm having a hard time understanding NDC Normalized Device Coords)

Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Then..

Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Advanced Effects

Post by Vectrotek »

Now this render tells me I'm doing something right..

But it's not "Dead Right"..

Image
Post Reply