News for hackers. Stuff that matters.
Re:Hallucinations re: the rendering of Cyberpunk 2077 by atum47 on Thursday December 17, 2020 @04:46PM (#25460918)
I've been meaning to get in deeper in 3D rendering. I always thought it is fascinating. I took a shot at creating my own 3D engine in the browser from scratch using webgl and it's kinda hard. Back then I was between jobs so I had a lot of free time.

How do you got into CG? Do you fiddle with other areas, like AI, ML...? I'm asking cause I think you really have to concentrate in one field to get to the level of the guys behind cyberpunk. They probably never had to learn react / redux in order to get a job.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by chairmanwow1 on Thursday December 17, 2020 @06:12PM (#25461753)
It's honestly super fun to go from zero to one with rendering just because it opens your eyes to how that second processor on your machine works.

Writing vertex and fragment shaders blew my mind the first time I did it. "Wait, this code will be run for EACH PIXEL ON THE SCREEN?" It's obvious in principle, but the actual implementation felt awesome to experience first-hand. Like the feeling of accomplishment that you get in re-deriving a famous theorem yourself. It's not groundbreaking or novel, but it unlocks a much deeper understanding for why we need GPUs at all.

You can take a look at the humble repo I used to both learn C++ and explore 3D rendering [1]. If by some chance you are interested in learning more about how this stuff works, I highly encourage you to check out TheCherno's youtube channel [2]. I'm not a huge fan of his newer stuff (Hazel engine), but his older series implemented 3D graphics from scratch in Java. Taught me a huge amount about how this stuff works and really ignited my interest in programming.

[1] https://github.com/TimelyToga/tlotk/tree/master/src/engine/g...

[2] https://www.youtube.com/watch?v=iH1xpfOBN6M&list=PL656DADE0D...

Re:Hallucinations re: the rendering of Cyberpunk 2077 by atum47 on Thursday December 17, 2020 @08:30PM (#25462757)
Thank, I'll take a look. I used to watch the cherno's videos, long time ago.

Funny story: following a video (ThinMatrix) about creating a 3D engine in Java (I was translating everything to JavaScript and working around the old OpenGL concepts_) I learned that you can't have an object as a index in a JavaScript Dictionary. Living and learning.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by chairmanwow1 on Thursday December 17, 2020 @09:27PM (#25463118)
ThinMatrix is great too. Although, I've come to like Dave Frampton's channel even more than TM [1]. The perfect balance of technical detail, artistry, game design, and calm steady progress.

[1] https://www.youtube.com/user/majiDave

Re:Hallucinations re: the rendering of Cyberpunk 2077 by winter_blue on Thursday December 17, 2020 @06:39PM (#25461958)
The github repo you linked (https://github.com/TimelyToga/tlotk/) say page does not exist, so it seems to be private and not public?
Re:Hallucinations re: the rendering of Cyberpunk 2077 by chairmanwow1 on Thursday December 17, 2020 @09:15PM (#25463047)
Oops. Sorry about that. I’ve made it public~
Re:Hallucinations re: the rendering of Cyberpunk 2077 by atum47 on Friday December 18, 2020 @12:05AM (#25464074)

    exit(FUCKED_UP_SHADER_COMPILATION);
funny
Re:Hallucinations re: the rendering of Cyberpunk 2077 by corysama on Thursday December 17, 2020 @04:52PM (#25460987)
The rendering engineers on Cyberpunk are definitely career experts. But, hobbyists can get impressive results in their spare time. IMHO, a good target to shoot for is to write your own https://www.khronos.org/gltf/ viewer. It's a scalable goal that you can take as far as you like.

Start with https://github.com/jkuhlmann/cgltf to handle loading the data. Check the sidebar of https://www.reddit.com/r/opengl/ for tutorials.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by atum47 on Thursday December 17, 2020 @04:55PM (#25461020)
thanks. I was able to get the basics stuff out of the way:

https://victorribeiro.com/3Dsphere/

https://www.youtube.com/watch?v=w13Q_KL1I9A

I just need to focus a little bit more in order to get more complex stuff done.

for instance: I don't know jack about animations / bones / skin deformation. =(

Re:Hallucinations re: the rendering of Cyberpunk 2077 by ilays on Thursday December 17, 2020 @05:11PM (#25461190)
Re:Hallucinations re: the rendering of Cyberpunk 2077 by corysama on Thursday December 17, 2020 @05:35PM (#25461423)
That book is a highly-recommended intro. The site for the book https://www.realtimerendering.com/ also list tons more great material.
Re:Hallucinations re: the rendering of Cyberpunk 2077 by brundolf on Thursday December 17, 2020 @05:13PM (#25461208)
> I don't know jack about animations / bones / skin deformation

I only know the basics, but as far as I know that stuff is generally pretty straightforward (at least compared to actual rendering)

Basically you have an invisible vertex floating inside the mesh, and vertices on the visible mesh are "weighted" to it (with a floating point weight), so that when the bone moves, it "pulls" vertices towards it based on the weight strength. A mesh vertex can be weighted to multiple bone vertices at once. Bones typically consist of two vertices, where one is treated as an anchor and the other rotates around it. They're then arranged in a hierarchy, so that a parent bone's transform (translate/rotate/scale) applies to its children, and so on. So for example, rotating an upper arm bone causes the forearm bone to rotate with it.

An animation is then a series of keyframes on those bones (translate/rotate/scale to a particular x/y/z at time t). Those keyframes are interpolated when the animation is applied, and the mesh vertices are dragged along accordingly.

Motion-capture is just taking position data from a live actor and mapping it to those bone keyframes.

Things get slightly more complicated when it comes to blending between multiple animations (for example, running + swinging a sword; you basically average the keyframes). And then there's IK or Inverse Kinematics, which basically means that instead of driving an animation purely from explicit keyframes, you procedurally place the "end" of the limb (a character's foot goes all the way to the ground, for example) and then procedurally work backwards adjusting the bones up the hierarchy to satisfy that position. This is pretty common these days and leads to dramatically more natural-looking animation for characters and creatures (you can see it in action by walking on some stairs in a recent game). I don't know exactly how it's implemented.

But that's about it from a technical perspective. Of course the artistry of getting all of this just right is much harder - from the bone-weighting ("rigging") to the keyframes to the motion capture data cleanup - but the technical aspect isn't nearly as complicated as rendering (to my understanding).

Re:Hallucinations re: the rendering of Cyberpunk 2077 by atum47 on Thursday December 17, 2020 @05:21PM (#25461288)
I get the concept because I used to be a 3d artist... But when it comes to program this...

A static model I just copy it's vertex position to a buffer, right? So when there's a bone animation I just update the vertex in my models and the copy it again to the buffer, for every frame?

Re:Hallucinations re: the rendering of Cyberpunk 2077 by corysama on Thursday December 17, 2020 @05:34PM (#25461410)
That can work. But, it's slow. The way this has been done is to not modify the buffers and instead do the work in the vertex shader. The vertex shader sends the skinned verts straight to the triangle rasterizer and then then are never needed again. So, no need to read-modify-write the buffer just to have the rasterizer read it back again.
Re:Hallucinations re: the rendering of Cyberpunk 2077 by atum47 on Thursday December 17, 2020 @06:03PM (#25461674)
yeah, I figured that should be a better solution.

I was using ThinMatrix [1] videos as guidelines when I was creating my engine. I'll take a look in how he implemented animations. Thank you.

1 - https://www.youtube.com/user/ThinMatrix

Re:Hallucinations re: the rendering of Cyberpunk 2077 by 936936 on Thursday December 17, 2020 @05:42PM (#25461483)
Your vertex buffer should hold indices for which bones influence the position of each vertex and by what fraction. Each vertex could, for example, have 4 indices and 4 floats to indicate these values, and these only need to be uploaded to the gpu once.

The transformation matrices are interpolated for each rendered frame using the hierarchial animation data and the computed matrices are uploaded to the gpu in a buffer. The matrices are accessed in the vertex shader by indexing into the matrix buffer to calculate the vertex position.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by BearOso on Thursday December 17, 2020 @05:38PM (#25461451)
No, you'll generally pass the relevant bone information and desired transforms to a vertex shader, and that computes the new positions.
Re:Hallucinations re: the rendering of Cyberpunk 2077 by brundolf on Thursday December 17, 2020 @05:26PM (#25461330)
Ah, I misunderstood. Yeah I've never actually implemented it myself :)
Re:Hallucinations re: the rendering of Cyberpunk 2077 by oplav on Thursday December 17, 2020 @05:35PM (#25461416)
> They're then arranged in a hierarchy, so that a parent bone's transform (translate/rotate/scale) applies to its children, and so on. So for example, rotating an upper arm bone causes the forearm bone to rotate with it.

How do you reconcile noise in motion capture data to bone transformations? For example, isn't it possible that the motion capture data slightly elongates or shortens the forearm in a way that makes it impossible to maintain the relationship with the upper arm bone?

In my head, it feels like you would have to pick the closest point on the sphere that's created if you rotate the forearm all around the elbow joint, but that seems expensive to do everywhere all the time.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by brundolf on Thursday December 17, 2020 @05:44PM (#25461515)
You can have bones that are parented but don't have one of their vertices directly attached to one of the parent's vertices. It's really just a hierarchy of transformation (child's overall transform = its transform relative to parent + parent's transform). Put differently, the "attached at the joints" notion is often approximated just because that's how human skeletons work, but it's by no means required. And "bones" in this sense don't always even correspond to actual skeletal bones; they're really just a tool for moving around groups of vertices without having to mess with hundreds or thousands of them individually.

That said - and I haven't done this myself, I'm just speculating - if you're using motion capture data directly maybe it makes sense to ditch the hierarchy altogether and have each bone be independent? Though, that could be problematic if you wanted to blend some "artificial" animations together with the recorded ones. I'm not sure what the standard practice is.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by Daub on Thursday December 17, 2020 @07:21PM (#25462296)
Raw motion capture data almost always requires some editing after it has been captured. This is done by the animator, and they can’t work without their rigs. Rigging is an entire craft... tried a enough to know that I suck at it. Rigging quadrupeds is a god level skill.
Re:Hallucinations re: the rendering of Cyberpunk 2077 by simias on Thursday December 17, 2020 @06:00PM (#25461655)
You can learn quite a lot by writing a toy raytracer with things like textures, shadows, bump mapping and the like.

Of course raytracers don't work like polygonal hardware rendering but a lot of the maths and concept do carry over I've found. If you understand how normal mapping and reflections work in a software Raytracer you shouldn't have too much trouble implementing the same algorithms in a hardware accelerated pixel shader for instance.

In general I think that implementing a raytracer is just one of these projects that's just too cool and simple not to do, so I don't think you'll be wasting your time anyway.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by c0de517e on Thursday December 17, 2020 @05:37PM (#25461439)
It's a lifelong journey of passion and learning :) I put together a list of resources here, just start somewhere and keep going, there are so many options nowadays the really the best thing is to chose a project/path and go from there http://c0de517e.blogspot.com/2020/11/baking-realistic-render...
Re:Hallucinations re: the rendering of Cyberpunk 2077 by adamnemecek on Thursday December 17, 2020 @05:45PM (#25461518)
I would recommend checking out other GPU APIs, OpenGL is kind of terrible. DirectX and Metal are nice (and also have a nice debuggers) or WebGPU. WGPU is a nice WebGPU implementation https://github.com/gfx-rs/wgpu
Re:Hallucinations re: the rendering of Cyberpunk 2077 by IdiocyInAction on Thursday December 17, 2020 @07:18PM (#25462276)
The learnopengl tutorial is quite good though and you don't have to learn Rust.
Re:Hallucinations re: the rendering of Cyberpunk 2077 by adamnemecek on Thursday December 17, 2020 @07:47PM (#25462461)
I agree that learnopengl is a good tutorial but OpenGL is kinda bad.
Re:Hallucinations re: the rendering of Cyberpunk 2077 by IdiocyInAction on Thursday December 17, 2020 @07:17PM (#25462268)
Learn basic CG theory. Implement ray tracing and rasterization. Understand the math; I'll come up quite often. Learn how the GPU works. Learn a graphics API, like OpenGL.

For the level you see in Cyberpunk, you need to learn modern, physically-based techniques. This requires a bit more math, though nothing you wouldn't see in a CS degree. My favorite reference on PBR techniques is the PBR book, which is free online. Applying some of these techniques in a real-time setting is of course another challenge.

However, all this probably takes a ton of time and math and low-level programming knowledge for a newcomer.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by golergka on Thursday December 17, 2020 @06:36PM (#25461941)
> How do you got into CG?

There's plenty of job openings in game development industry outside of the top of the field roles for the best AAA projects. These job openings require less expertise and experience, but yet will allow you to get your hands dirty with various areas, 3d rendering included — although in smaller studios working on smaller projects you most likely will not be a part of dedicated rendering team and will be involved in different areas of the project.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by percentcer on Friday December 18, 2020 @03:01AM (#25464893)
Peter Shirley's "Ray Tracing in One Weekend" is probably the best zero-to-one introduction to graphics but it doesn't have much to do with the tooling you'd need in industry (and probably better for it!):

https://raytracing.github.io/books/RayTracingInOneWeekend.ht...

Re:Hallucinations re: the rendering of Cyberpunk 2077 by gens on Thursday December 17, 2020 @06:57PM (#25462139)
https://learnopengl.com/

This is good. The rest is more of theory. I can dump you a lot of papers, talks, and reviews like the OP one.

Re:Hallucinations re: the rendering of Cyberpunk 2077 by ilogik on Thursday December 17, 2020 @05:30PM (#25461366)
I really enjoyed following along with this book: http://raytracerchallenge.com/