Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Tres Burritos
Sep 3, 2009

Yeah, I know FF and Chrome for sure support float textures on all the hardware that I own, including some lovely lovely laptops with linux.

edit: yeah, scroll down to "WebGL Extensions" here

Adbot
ADBOT LOVES YOU

Redmark
Dec 11, 2012

This one's for you, Morph.
-Evo 2013
I actually did try using the OES_texture_float extension but it was broken on both Chrome and Firefox for me. I can't be certain that it wasn't partly my fault but there are definitely issues with the implementation on at least some OS/driver/GPU combinations, some of them severe. Now I'm just trying to stick to the spec as much as possible.

Jewel
May 2, 2009

I found this again in my new emails, and I'd completely forgotten I'd actually signed up to get digests (I kept thinking it was cubebrush and marking emails as read I think?) and there's not much here but the tutorials that are here are pretty good, so I thought I'd share https://flippednormals.com

There's some in the free section but it looks like they just need a ton more users in general, I haven't really heard it mentioned anywhere though :(

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
Are there any good resources to get a good basic understanding of how modern GPUs (and GPUs in general) operate at a hardware level? So far all I've done is practical OpenGL, but I want to get a better understanding of how the underlying hardware works.

I have a fairly decent (although basic) understanding of Von Neumann architecture and standard CPU instruction sets/memory, so preferably I'd like something that assumes some understanding of computer architecture.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Ryg has some excellent posts on this.

https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/

https://fgiesen.wordpress.com/2013/02/17/optimizing-sw-occlusion-culling-index/

I also know quite a bit of both architecture and history, so I can help answer questions if you have any.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
That looks perfect. Thanks!

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...
https://developer.nvidia.com/content/life-triangle-nvidias-logical-pipeline

Luigi Thirty
Apr 30, 2006

Emergency confection port.

I'm working on a 3D renderer in DOS even though I don't have a math background because I'm a psychopath. I have perspective rendering of model vertices down but something's up with my normal calculations so visibility is messed up. The normal calculation was fine when I was just doing orthographic projection. Can anyone give me a hand with these calculations?

Here's a cube:



It's rendering triangles that should be invisible (the top of the cube) and maxing out their light intensity to white no matter the viewing angle. I'm not sure what's going on with this. I did put the code up on Github if anyone wants to peek. Here's the relevant function in framebuffer.cpp:


Any thoughts? :(


e: I'm a moron, you transform the normal by multiplying it with the inverse of the transposed ModelView matrix, not the transformation matrix.

Luigi Thirty fucked around with this message at 01:19 on Jul 5, 2016

Xerophyte
Mar 17, 2008

This space intentionally left blank

Luigi Thirty posted:

Any thoughts? :(

You're transforming normals into screen space which is probably some of it. Angles are not necessarily preserved after projection and I wouldn't expect transformedNormal to be normalized after the viewport transform either, so the shading will be screwy. You probably want to use ModelView.inverse().transpose() to compute world space normals when shading.

That said, checking the sign of z in the screen space normal should work for checking triangle orientation. Have you checked that the winding is consistent?

E: Well, I'm late.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Xerophyte posted:

You're transforming normals into screen space which is probably some of it. Angles are not necessarily preserved after projection and I wouldn't expect transformedNormal to be normalized after the viewport transform either, so the shading will be screwy. You probably want to use ModelView.inverse().transpose() to compute world space normals when shading.

That said, checking the sign of z in the screen space normal should work for checking triangle orientation. Have you checked that the winding is consistent?

E: Well, I'm late.

Thanks anyway. Now if I can just figure out why my view turns into this mess if eye is at the same Z coordinate as an object, even if the object isn't visible, I'll be set!

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Oh boy. Today I got pointed to the slides for tri-Ace's R&D for Star Ocean 4. From 2009. The amount of stuff done (lens simulation! accurate bokeh shader) is insane. I want to figure out how to do this all eventually.

Not to mention the rest of the R&D they've done more recently. I have a lot to learn...

ErIog
Jul 11, 2001

:nsacloud:
Wow, that stuff is totally my kind of thing. Thanks for linking that!

Xerophyte
Mar 17, 2008

This space intentionally left blank

Luigi Thirty posted:

Thanks anyway. Now if I can just figure out why my view turns into this mess if eye is at the same Z coordinate as an object, even if the object isn't visible, I'll be set!

Guessing divide by zero in your "screen_pos.xyz = screen_pos.xyz / screen_pos.w" equivalent. Perspective projection is singular in the plane of the camera, it's one of the reasons we have clip planes.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Xerophyte posted:

Guessing divide by zero in your "screen_pos.xyz = screen_pos.xyz / screen_pos.w" equivalent. Perspective projection is singular in the plane of the camera, it's one of the reasons we have clip planes.

Ooooh, when I redid/stole the matrix inversion function I took out the assert that bombed out if the matrix was singular to confirm that my projection was working right. I'll pop it back in to confirm that's what's going on and figure out why my clip planes aren't working properly after work!

Xerophyte
Mar 17, 2008

This space intentionally left blank
Singular might not be the best word. With a perspective projection matrix



you get out.w = -in.z, regardless of your choice of n and f. So any vertex in the plane of the camera gets borked on projection if not already culled.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Suspicious Dish posted:

Oh boy. Today I got pointed to the slides for tri-Ace's R&D for Star Ocean 4. From 2009. The amount of stuff done (lens simulation! accurate bokeh shader) is insane. I want to figure out how to do this all eventually.

Not to mention the rest of the R&D they've done more recently. I have a lot to learn...

this is the good poo poo: http://research.tri-ace.com/s2015.html

finally someone in graphics discovers the airy disc

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
https://www.youtube.com/watch?v=9YXhCK2tLCU

how do i make it work

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Xerophyte posted:

Singular might not be the best word. With a perspective projection matrix



you get out.w = -in.z, regardless of your choice of n and f. So any vertex in the plane of the camera gets borked on projection if not already culled.

Hmm... that doesn't look like the matrix I have which I got from here. I don't think this is doing what I think it does. I'm not sure what it's doing, actually, but messing with zNear and zFar doesn't do any polygon clipping when my cubes get too close or too many units away.

code:
Matrix perspective_projection(){
    Matrix m = Matrix::identity(4);

    float aspectratio = 320.0 / 200.0; //320x200 resolution
    float verticalFOV = 30.0;
    float zNear = 1.0;
    float zFar = 50.0;
    float zRange = zNear - zFar;
    float tanHalfFOV = (std::tan(((verticalFOV/2) * M_PI) / 180.0));

    m[0][0] = 1.0f / (tanHalfFOV * aspectratio);
    m[1][1] = 1.0f / tanHalfFOV;
    m[2][2] = -(zNear - zFar) / zRange;
    m[2][3] = (2.0 * zFar * zNear) / zRange;
    m[3][2] = 1.0;
    m[3][3] = 0.0;
    
    return m.transpose(); //OpenGL is column-major, this renderer is row-major
}
I have no idea what I'm doing. :(

Luigi Thirty fucked around with this message at 01:08 on Jul 6, 2016

Xerophyte
Mar 17, 2008

This space intentionally left blank

Luigi Thirty posted:

Hmm... that doesn't look like the matrix I have which I got from here. I don't think this is doing what I think it does. I'm not sure what it's doing, actually, but messing with zNear and zFar doesn't do any polygon clipping when my cubes get too close or too many units away.

Sorry, I should be explaining this better. That matrix is the same thing as what I posted, just reparametrized on the FOV angles instead of the top-bottom and left-right planes used in the GL spec and with a different clip space orientation. It's good, don't worry about it.

Point is that while the projection matrix isn't singular, it (by intent and necessity) projects all vertices in the plane of the camera to have a w-coordinate of 0. In your matrix specifically the w-coordinate is determined by
code:
    m[3][2] = 1.0;
    m[3][3] = 0.0;
meaning that out = m * in results in out.w == in.z. Again, this is good and just means that Z+ is forward in your view space. Later you do out.xyz = out.xyz / out.w, which will divide by 0 if used on coordinates in the plane of the camera. The zNear and zFar parameters for your projection matrix just specify how the z-axis is scaled after the projection, adjusting them won't avoid the problem that perspective projection fundamentally cannot handle vertices in the camera plane. It's up to you to manually clip or cull triangles against your view frustum, and my guess is that's currently not happening for some reason so stuff explodes when the camera and object share a z-coordinate.

A simple hack is to not raster any triangle where vertex.w <= 0.0 for any vertex, since actually clipping triangles is a pain.

Xerophyte fucked around with this message at 09:52 on Jul 6, 2016

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Oooooooh, I thought zNear and zFar represented clipping planes, not scaling for Z. I'll play with it some more, that should help me make it not explode.

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

Luigi Thirty posted:

Oooooooh, I thought zNear and zFar represented clipping planes, not scaling for Z. I'll play with it some more, that should help me make it not explode.

It does both. The projection maps the world-space coordinates (or actually view-space, since you've applied both the world and view transforms) into "clip space", which is bounded over [(-1, -1, 0), (1, 1, 1)]. This maps to the edges of the view frustum. Triangles are clipped to that volume.

Sex Bumbo
Aug 14, 2004

Hubis posted:

[(-1, -1, 0), (1, 1, 1)]

We're talking gl so it's a unit cube isn't it?

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen

Luigi Thirty posted:

Oooooooh, I thought zNear and zFar represented clipping planes, not scaling for Z.

My friend, I can't recommend enough that you enter Jim Blinn's corner and take a :lsd: trip with him down the graphics pipeline.


Table of Contents: https://www.microsoft.com/en-us/research/publication/jim-blinns-corner-a-trip-down-the-graphics-pipeline/

Vintage hair aside, it's highly readable, comprehensive, implementable and era-appropriate to your 3D DOS adventures. It certainly helped me understand where I was putting all the bugs in various 3D engine prototypes back in the day, far more than any of the weightier reference tomes. (It's current pricing online seems steep to me, though.)

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I also recommend that you do not use matrices for anything in your first engine. The project matrix is a notorious beast which does depth remapping, perspective projection, and focal zooming, all in one package, which means it's more difficult to understand than it should be.

Do all that math by hand.

Sex Bumbo
Aug 14, 2004

Suspicious Dish posted:

I also recommend that you do not use matrices for anything in your first engine. The project matrix is a notorious beast which does depth remapping, perspective projection, and focal zooming, all in one package, which means it's more difficult to understand than it should be.

Do all that math by hand.

Whoa whoa what? Just use some default math package, call CreateMatrixPerspective or something some other nerd wrote, and when poo poo doesn't look right try flipping the order you're multiplying your matrices in. This has been my professional strategy for a decade.

At one point in my life I could derive all types of projection matrices, and it never came in useful.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe

Sex Bumbo posted:

We're talking gl so it's a unit cube isn't it?

Isn't the default gl depth range [0;1]?

Xerophyte
Mar 17, 2008

This space intentionally left blank
In this case its a custom software rasterizer which seems to use (-1 -1 -1) to (1 1 1), at least if it follows that tutorial. It doesn't really matter what space you map to as long as you're consistent, but since there are so many ways to do this it can be frustrating to get to the right form by guessing. It could mean a lot of transposing things, multiplying some rows by 2 and generally changing the order of operations until the right answer happens to pop out, especially if new and not sure where to look.

I'm not sure it's a good idea to do the projection step by step rather than drill down and try to figure out the matrix math though, but then again my normal approach is gently caress projection, shoot more rays. :v:

Sex Bumbo
Aug 14, 2004
Yeah, the post was referring to matrices which don't compute the depth range though.

Xerophyte posted:

In this case its a custom software rasterizer which seems to use (-1 -1 -1) to (1 1 1), at least if it follows that tutorial. It doesn't really matter what space you map to as long as you're consistent, but since there are so many ways to do this it can be frustrating to get to the right form by guessing. It could mean a lot of transposing things, multiplying some rows by 2 and generally changing the order of operations until the right answer happens to pop out, especially if new and not sure where to look.

I'm not sure it's a good idea to do the projection step by step rather than drill down and try to figure out the matrix math though, but then again my normal approach is gently caress projection, shoot more rays. :v:

Try test cases where you transform what you believe to be the world space extents of your camera frustum. They should ultimately map to the extents of your ndc-volume.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Xerophyte posted:

In this case its a custom software rasterizer which seems to use (-1 -1 -1) to (1 1 1), at least if it follows that tutorial. It doesn't really matter what space you map to as long as you're consistent, but since there are so many ways to do this it can be frustrating to get to the right form by guessing. It could mean a lot of transposing things, multiplying some rows by 2 and generally changing the order of operations until the right answer happens to pop out, especially if new and not sure where to look.

I'm not sure it's a good idea to do the projection step by step rather than drill down and try to figure out the matrix math though, but then again my normal approach is gently caress projection, shoot more rays. :v:

There are no matrices in this:

http://magcius.github.io/sw3dv/sw_rast.html
http://magcius.github.io/sw3dv/sw_rast.js

And any math for this is extremely straightforward.

You really don't need matrices -- they're just complicated, obscuring forms of basic adds and multiplies. Not to mention that the projection matrix pulls an awful hack with the depth remap. The depth remap is conceptually simple. You want [zNear, zFar] mapped to [0, 1]. Using basic linear interpolation, you get: remappedZ = (z - zNear) / (zFar - zNear).

But of course you can't do that in a matrix, since it only has adds and multiplies. You can multiply by the inverse, so you get: remappedZ = (z - zNear) * (1 / (zFar - zNear)). A bit more math magic can turn that into add-multiply form: remappedZ = z*(zFar / (zFar - zNear)) + 1*((zFar * zNear) / (zFar - zNear)).

There's still one problem. We don't have a constant 1 -- all we can do is pull from our input vector. So, uh, let's cheat. We have a w coordinate, which is always going to be 1, since our input coordinates are homogenous. We don't actually care about what w means, in this context, we're just using it to pull a 1 from.

I still think remappedZ = (z - zNear) / (zFar - zNear) is easier to read.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Hubis posted:

It does both. The projection maps the world-space coordinates (or actually view-space, since you've applied both the world and view transforms) into "clip space", which is bounded over [(-1, -1, 0), (1, 1, 1)]. This maps to the edges of the view frustum. Triangles are clipped to that volume.

I did it! My camera can be coplanar on the Z axis with my pyramid of cubes! :toot:

I'm doing this because I've wanted to since I was a babby who played games on our sick 486SX/2 for the first time. I got a book on Rend386 that I couldn't understand out of a bargain bin when I was 12. It's a hacked-together pile of garbage combining a 2D DOS graphic library I wrote and a synthesis of as much info on 3D I could get from various places and as much geometry as I could teach myself in the past few weeks. It's slow but it's mine and I can spin flat-shaded models loaded from .OBJ files, dammit.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Suspicious Dish posted:

I also recommend that you do not use matrices for anything in your first engine. The project matrix is a notorious beast which does depth remapping, perspective projection, and focal zooming, all in one package, which means it's more difficult to understand than it should be.

Do all that math by hand.

IMO understanding projective geometry makes the entire process basically trivial. it's much easier to understand whats going on when u don't have magic formulas littered about

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Don't worry, I have plenty of time to figure out two-dimensional rotations of the camera target point around the camera location point based on half-remembered 11th grade Euclidean geometry without matrices.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
If you meant that sarcastically, that kind of exactly proves my point. A camera isn't a geometric construct. Moving the camera to the right 50 pixels is the same as moving everything in the scene to the left 50 pixels. So, all a camera does is be an inverse of those sorts of local transformations, for every object in the scene.

If you ignore cameras, matrices, etc., then you can easily figure out how the projective geometry works. If you're implementing a software rasterizer, that's kind of a core requirement to understand.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

I know that :mad: and I understand how you make an orthographic projection from a set of vertices. I don't really understand the math behind perspective projection yet and I will continue to work on that. I kind of failed this stuff in college thanks to a learning disorder (dyslexia but for numbers :saddowns:) so it's pretty tough for me to comprehend.

Luigi Thirty fucked around with this message at 04:41 on Jul 7, 2016

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
This might just be me, but I find perspective projections much more intuitive than orthographic projections.

If you disregard screen width, fov and local coordinate systems, you essentially just want to trace a line from the origin through an arbitrarily large plane which is a known distance from the origin (let's say 1) and oriented in the view direction. All this really boils down to is a problem where for each coordinate of X and Y, you have two similar triangles, you know the Z-value of the plane and all three values of the vertex, so you can use the fact that all sides scale by the same factor to find X and Y.

For example, to find the X-value: Considering only the X-Z plane, the triangle made by the vector from the origin to the vertex and from the origin to the plane intersection point are similar (that is to say corresponding angles are equal.) This means that we know that the sides have to maintain their relationships, and the following must be true: Plane X/Vertex X = Plane Z / Vertex Z. Isolating the unknown (the plane intersection's X-coordinate) we get Plane X = Vertex X * (Plane Z/Vertex Z).

Like I said this leaves out FOV and accomodation for the particular coordinate system needed to actually rasterise the triangles, but those things are a question of 1)determining the size of your effective plane based on FOV and 2) dividing/adding/subtracting from your plane coordinates to get it into whatever range you're working in.

E: Ok, writing it out it's not that simple, but I still find orthographic projections harder :colbert:

Joda fucked around with this message at 05:18 on Jul 7, 2016

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Luigi Thirty posted:

I know that :mad: and I understand how you make an orthographic projection from a set of vertices. I don't really understand the math behind perspective projection yet and I will continue to work on that. I kind of failed this stuff in college thanks to a learning disorder (dyslexia but for numbers :saddowns:) so it's pretty tough for me to comprehend.

Watch this very introductory video I made for a bunch of people at work: https://www.youtube.com/watch?v=v8jUNC5WdYE

Did it help?

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Joda posted:

This might just be me, but I find perspective projections much more intuitive than orthographic projections.

If you disregard screen width, fov and local coordinate systems, you essentially just want to trace a line from the origin through an arbitrarily large plane which is a known distance from the origin (let's say 1) and oriented in the view direction. All this really boils down to is a problem where for each coordinate of X and Y, you have two similar triangles, you know the Z-value of the plane and all three values of the vertex, so you can use the fact that all sides scale by the same factor to find X and Y.

For example, to find the X-value: Considering only the X-Z plane, the triangle made by the vector from the origin to the vertex and from the origin to the plane intersection point are similar (that is to say corresponding angles are equal.) This means that we know that the sides have to maintain their relationships, and the following must be true: Plane X/Vertex X = Plane Z / Vertex Z. Isolating the unknown (the plane intersection's X-coordinate) we get Plane X = Vertex X * (Plane Z/Vertex Z).

Like I said this leaves out FOV and accomodation for the particular coordinate system needed to actually rasterise the triangles, but those things are a question of 1)determining the size of your effective plane based on FOV and 2) dividing/adding/subtracting from your plane coordinates to get it into whatever range you're working in.

E: Ok, writing it out it's not that simple, but I still find orthographic projections harder :colbert:

Poking around at work I found a copy of some lecture slides from a computer vision class with helpful diagrams too and I don't think this really is as complex as I thought. I'll look through everything plus that video and play with doing just straight projection math on model vertices.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Suspicious Dish posted:

Watch this very introductory video I made for a bunch of people at work: https://www.youtube.com/watch?v=v8jUNC5WdYE

Did it help?

Yes, that helped a lot and it's not really that complicated!

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I'm glad! And yeah, one of my major choices for that talk was to not talk about a matrix the whole time, so I'm glad it paid off...

Good luck with your project! Let us know if you have any more questions or need any more help...

Adbot
ADBOT LOVES YOU

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Suspicious Dish posted:

I'm glad! And yeah, one of my major choices for that talk was to not talk about a matrix the whole time, so I'm glad it paid off...

Good luck with your project! Let us know if you have any more questions or need any more help...

I managed to get controls hooked up so I can rotate and translate a (wireframe for the moment) world. What I'm stuck on now is figuring out the proper scaling setup so the FOV isn't super tight in my 320x200 world!



:gonk:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply