4 ms·
Is it normal that the first time you manage to render a triangle it has what looks like a pretty complex gradient colour? I’d have expected rendering a solid co
by mcintyre1994 4y ago
Is it normal that the first time you manage to render a triangle it has what looks like a pretty complex gradient colour? I’d have expected rendering a solid colour or without fill to be easier and to happen first, but that’s just a completely uninformed guess. Or is this person just way ahead of anyone else working on the same thing, and they would have had it working without that colour at some earlier point but didn’t show it off until now?
- kreddor 4y agoI think that's just how the hardware does it when you assign a different color to each vertex.
- flohofwoe 4y agoSince the color interpolation is done by the hardware from per-vertex attributes it's not any additional effort compared to a solid-color triangle (from a coder's point of view at least). But the simple triangle still means that most of the render pipeline already works. The next step in the "Hello Triangle" evolution would be to apply a texture to the triangle.
- mcintyre1994 4y agoAh that hardware interpolation is what I wasn’t aware of, thanks! :)
- captainmuon 4y agoDoes modern hardware still have this "default" behavior? I could imagine you would have to write a (basic) shader to get any kind of output, whereas back in the day the 3D accelerator knew how to do Phong shading etc. in hardware.
- flohofwoe 4y agoYou need a vertex- and pixel-shader, but AFAIK even on modern GPUs the vertex attribute interpolation happens as fixed-function feature between the vertex- and pixel-stage (e.g. the vertex shader runs per vertex and outputs different colors for each vertex, and the pixel shader runs per pixel and gets the hardware-interpolated per-pixel color as input).
- Const-me 4y agoModern GPUs don’t know Phong shading, they expect developers to supply a pixel shader for that. However, they still interpolating all these numbers in hardware. For traditional rendering, a vertex shader outputs float4 position and a bunch of other per-vertex attributes which may contain normals, colors, texture coordinates, or anything else. GPU hardware itself only uses the positions. The hardware rasterizes triangles into pixel grid, interpolates the rest of the per-vertex attributes over the triangle, and calls the pixel shader for each pixel covered by the triangle passing the interpolated per-vertex attributes. It’s more complicated in reality: clipping, early depth rejection, pixel shaders need partial derivatives so the pixels are grouped into 2x2 blocks, some GPUs do tiled rendering. But still, on the high level the workflow stayed about the same since shaders arrived in Direct3D 8 in 2001 with GeForce 3. The only major disruption so far is UE5 which uses compute shaders for nanite meshes, instead of the hardware rasterizer.
- datalopers 4y agoIs there a particular book you recommend to approach learning this subject?
- Const-me 4y agoNot quite a book, but if you already know, at least to some extent, some 3D GPU API, I can recommend this series of blog posts: https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/ https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-...
- n42 4y agoReal-Time Rendering https://smile.amazon.com/Real-Time-Rendering-Fourth-Tomas-Akenine-M%C3%B6ller/dp/1138627003?tag=realtimerenderin https://smile.amazon.com/Real-Time-Rendering-Fourth-Tomas-Ak...
- datalopers 4y agoThanks!