TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Where do I start with first principles in 3D rendering?

2 点作者 dfischer超过 4 年前
I&#x27;m struggling finding a path towards understanding the first principles in 3D rendering.<p>I can find a lot of complicated books and tutorials that assume a bunch of things like OpenGL or Glad or C++ or Dynamically Linking library X Y Z and magically creating a scene but where is the &quot;build it yourself&quot; path?<p>I essentially want to build my own &quot;hello world&quot; 3D engine to understand how to manipulate pixels&#x2F;shaders in 3D space.<p>I&#x27;m searching for tutorials and books around building a game engine from scratch as that seems to be the best fit -- I&#x27;m still searching. Nothing I have found yet seems thorough and to the point and self-bootstrapped. For example I find this walkthrough of building a text-editor from scratch absolutely perfect: https:&#x2F;&#x2F;viewsourcecode.org&#x2F;snaptoken&#x2F;kilo&#x2F;<p>I have no preference for language - I&#x27;m familiar with most. Anything more &quot;raw&quot; without including a bunch of libraries will suit me best. So &quot;single file&#x2F;header libs&quot; are the largest I&#x27;d like to play with. Having said that, C might be the best fit if it&#x27;s the easiest to compile and get up and running without any dependencies.<p>Some embarrassing questions:<p><pre><code> 1. What is the most basic way I can create a window and render pixels in it? 2. Same as one but essentially with the most direct way of creating &quot;fragment shaders?&quot; (Is there something more direct than GLSL?) 3. My second question implies OpenGL as the API - is there a more direct or easier way to manipulate a window and pixels within it than OpenGL that is specific per OS? 3a. What would be the most direct API&#x2F;layer to access per OS? </code></pre> For context: I&#x27;m currently coding on Windows&#x2F;WSL - I recently switched from MacOS. I&#x27;m most familiar with MacOS and unix flavors for dev environments. I mention this in case there is a more direct way to accomplish my goal being on Windows than trying to go a cross-platform approach way (OpenGL).<p>I&#x27;m specifically avoiding any engine like processing, unity, webGL, etc - these abstract too much of the fundamentals I&#x27;m trying to learn.<p>I&#x27;d be really happy if I can just:<p><pre><code> 1. Create a window 2. Render pixels in that window that allow 2D&#x2F;3D space drawing&#x2F;coloring. 3. Create some basic shapes from a square to a cube and further real-time transformations. </code></pre> It can&#x27;t be that complicated can it? Hah.

3 条评论

jonnelafin超过 4 年前
&gt; I&#x27;d be really happy if I can just:<p>&gt; 1. Create a window 2. Render pixels in that window that allow 2D&#x2F;3D space drawing&#x2F;coloring. 3. Create some basic shapes from a square to a cube and further real-time transformations. It can&#x27;t be that complicated can it? Hah.<p>All this really depends on what language you want to do this on. (A viable example on Java)[<a href="https:&#x2F;&#x2F;youtu.be&#x2F;KA6rJZOfTTQ" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;KA6rJZOfTTQ</a>]. I think what you want is basic software rendering, so be advised: software rendering gets really slow really fast.<p>I tried something akin to this a couple years back l, it didn&#x27;t end too well, but I learned a ton in the process, feel free to (take a look )[<a href="https:&#x2F;&#x2F;github.com&#x2F;jonnelafin&#x2F;PB3D" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jonnelafin&#x2F;PB3D</a>], but the code is crap, so I think you are better off on writing your own.<p>Also these are some wikipedia articles on perspective transformations etc:<p>(Perspective projection)[<a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;3D_projection" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;3D_projection</a>] (Perspective projection -&gt; Mathematical formulas) (Rotation matricies)[<a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Rotation_matrix" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Rotation_matrix</a>]
raxxorrax超过 4 年前
I like <a href="https:&#x2F;&#x2F;www.babylonjs.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.babylonjs.com&#x2F;</a> very much, if you can live with JS. It has a nice community and very good tutorials.<p><a href="https:&#x2F;&#x2F;playground.babylonjs.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;playground.babylonjs.com&#x2F;</a> is nice to dabble and you can start right now.<p>You already know about shaders and pixels, but I really recommend doing a blender tutorial to understand the pipeline from modeling to computer graphics. There is a lot of shared terminology.<p>Aside from that, modelling can be immense fun.
phendrenad2超过 4 年前
If I were you, I&#x27;d focus on OpenGL 4.x. Going straight to the 3D API, since 2D these days is just a texture on the side of a 3D plane lol.<p>First thing you&#x27;ll need is to somehow open a window in your preferred OS and language and get a simple &quot;hello triangle&quot; (many tutorials for that) running in any OpenGL version.<p>There are OpenGL bindings for most languages, so pick the one that gets you started fastest. I usually use Windows with C (through the raw win32 API - which isn&#x27;t everybody&#x27;s cup of tea and can be somewhat confusing), but maybe there are XCode projects that show a simple window with an OpenGL demo in Objective C or Swift.<p>Also if you&#x27;re familiar with the Java world (maven, etc.) you can use LWJGL, which provides really simple Java wrappers around the OpenGL C API.<p>Once you have the window up and running, you should understand how GPUs actually work. GPUs are basically separate CPUs at this point, but they also do something that&#x27;s tough to reproduce on a CPU: they do rasterization. That means they take a bunch of triangles, expressed as floating point numbers, and splat them all together onto a regular integer-based grid (your framebuffer for your monitor or game window).<p>The bare minimum for OpenGL 4.x is two shaders: a vertex shader and a fragment shader (fragment just means &quot;pixel&quot; unless you do more advanced stuff like multisampling antialiasing etc.) The bare minimum vertex shader just takes a vertex and passes it through unchanged. The bare minimum fragment shader sets a color and takes no input. Fragment shaders run after rasterization. That&#x27;s why they operate on pixels. Vertex shaders run before rasterization.<p>Of course the GPU also does nice stuff like interpolating per-vertex values across each pixel of the triangle. That&#x27;s why so many &quot;hello triangle&quot; delos show a gradient across the triangle. It&#x27;s an easy easy to show off that feature (which is important for textures later).<p>I&#x27;d get away from thinking in terms of pixels&#x2F;shapes&#x2F;solids. There are higj-level wrappers around OpenGL that do such things (like Java3D), but are you really learning graphics if you don&#x27;t study the bottom levels?<p>If you really want to start with 2D, I suggest going through all the steps of setting up OpenGL, and then just render two textured triangles forming a quad covering your window. Then to draw to the window in 2D, you just write to the texture buffer and re-send it to OpenGL. It&#x27;s more work, but you&#x27;ll be more confident going into real modern 3D stuff.<p>Hopefully I&#x27;ve given you some ideas. I think you&#x27;re somewhat torn between low-level and high level, and I regret to inform you that you really can&#x27;t easily have both out of the box, and you should probably start at the low-level.<p>Although, there are maybe some simplistic 3D engines like OpenScenGraph that might be close, in some ways, to what you want.
评论 #25373439 未加载
评论 #25371549 未加载