Hot answers tagged

49

Generally speaking, a Normal vector represents the direction pointing directly "out" from a surface, meaning it is orthogonal (at 90 degree angles to) any vector which is coplanar with (in the case of a flat surface) or tangent to (in the case of a non-flat surface) the surface at a given point. A Tangent vector is typically regarded as one vector that ...


30

Vertex colors aren't that relevant when you have a fully textured 3d mesh. But it gets interesting when you have an untextured but colored mesh. In that case you assign a color to every vertex. The shader would then color each pixel of a polygon by interpolating between the colors of the three vertices. Vertex colors can also sometimes be interesting in ...


28

You could easily find the normal by calculating two vectors, V1 = P2-P1, and V2 = P3-P1, and then find the cross product N = V1 x V2. Then you normalize N. Depending on the ordering of the vertices (clockwise or counterclockwise) you will get a normal facing front or back. You also need to make sure that three three points aren't aligned, if they are you ...


25

In theory, Vertex Color allows to color a model without having to bother with textures. This is quite common in CAD. In practice, it's just one more slot you can use to push data into the vertex, which you then use in the vertex shader to do crazy stuff. "Isn't a vertex simple point on 3D space?" That's what I used to think, when I first started with 3D....


17

Normal vectors are typically used for lighting calculations. It is a vector that is supposed to be perpendicular to the surface that is approximated by the vertices of a mesh. Normals are defined at each vertice position but can be calculated differently depending on how you want light to refect at that vertice or what you want to do with your light ...


16

Let's imagine a big grid mesh, like one we might use for terrain. We'll render n triangles worth of it, covering say half our 1080p screen, in a single draw call. If we weld all of our vertices and have no smoothing/texturing seams, then each triangle has 3 vertices and each vertex is shared by 6 triangles, so we have n/2 vertices. To render this we need to: ...


11

Modern graphics APIs are very careful about specifying how rasterization of triangles that share edges will be done in order to avoid overlapping fragments and missing fragments. Fabien Giesen mentions one of these rules in his article series on the graphics pipeline, cited here: you need to have tie-breaking rules to ensure that for any pair of ...


10

The difference between the tangent and the binormal is less immediately clear on surfaces, but that shouldn't be too surprising - the binormal was originally defined not for surfaces but for curves, where the concept makes a lot more sense (and where it really lives as a 'normal' in that it's orthogonal to the direction of movement, thus the name). To be ...


9

There are three main steps here: Use some method to assign biomes to regions (this is the hard part, with multiple strategies I'll break down shortly) For each point in your mesh or tile/node in your world, determine which biome it's in, as well as which neighbouring biomes it's close to. Compute an interpolation weight representing the influence of each ...


8

Vertices can have colors, it's a property just like the normal of it. In 3d enviroments a triangle gets colored based on their vertices' color information. The closest fragments to vertex A get the color of it, the closesr to vertex B get the colornof B, and the color interpolates between the 2. It works the same way as per-vertex lighting It's an easy ...


7

This is a performance question. So, as always, the answer is: measure it! So this is exactly what I did: The Y axis is time taken to render, and the X axis is the number of "faces" rendered (pre-merging). By my own rough estimates, a "really big Minecraft vista" is somewhere around the middle of the X axis. This is all assuming reasonable culling (you're ...


7

it doesn't generate a quad, instead it generates a fullscreen triangle. The outputs end up as: output[0].texcoord = float2(0,0); output[0].position_cs = float4(-1, 1, 0, 1); output[1].texcoord = float2(2,0); output[1].position_cs = float4(3, 1, 0, 1); output[2].texcoord = float2(0,2); output[2].position_cs = float4(-1, -3, 0, 1); It goes beyond the ...


6

Yes. VertexPositionTexture is a 20 byte structure. With over 2 million of them, they take up around 43MB of memory. Which gets copied around a bit on the CPU, and then transferred to the GPU. Each frame! There are almost certainly going to be other optimisations you can pursue. I see, in the comments, merging adjacent faces is suggested. I think Minecraft ...


6

Try this: BoxCollider b = obj.GetComponent<BoxCollider>(); //retrieves the Box Collider of the GameObject called obj Vector3 vertice1 = myobject.transform.TransformPoint(b.center + new Vector3(-b.size.x, -b.size.y, -b.size.z)*0.5f); Vector3 vertice2 = myobject.transform.TransformPoint(b.center + new Vector3(b.size.x, -b.size.y, -b.size.z)*...


5

So I've really exceeded my time budget for this question, with my mega-answer. But here's an idea, which you can hopefully evaluate using the code I've provided in my other answer: Basically, you have two texture coordinates per quad: One that is the same for all vertices of a given quad, to select the tile within the texture atlas. The second has ...


5

There are several factors that contribute to how the geometry is saved and processed in different mediums (programs, file formats, APIs). I did implement several commercial geometry analysis programs, so I have some experience with it. First I am sure this has nothing to do with Unity simplifying anything. But in case it did there are several decimation ...


5

The input primitive, aka. the mesh fed into the shader, has a MeshTopology setting which can be adjusted in code. The accepted answer works because the default input primitive for a mesh(including imported meshes) is triangle/MeshTopology.Triangles. But if you use MeshTopology.Triangles, you will be creating more geometry than you need for the shader. ...


5

1. Creating textured model in Blender First, add a new texture by going to texture panel on the right. Select type "Image or Movie", click "Open" and locate your texture file. Then, move your mouse to the 3d view, press Tab to select the default cube, then press "U" and select Unwrap. Go to UV Image Editor: and select the texture: At this point, the cube ...


5

No it is not. The input to the shader pipeline expects a "stream" of vertices. So say you're using DRAW_TRIANGLES (or whatever it is) what actually happens is this: Create 3 buffers (these are your varyings) of sufficient size Fetch vertex (attributes) and put them in the input to the vertex shader Run the vertex shader Transfer varyings output ...


5

What I do is a test known as Ray-Picking. It is a test to see if a "ray" intersects a triangle. In order to use it, you need to learn how to convert your mouse coordinate into world coordinates (where your triangles are). Then, you need to create a matrix which is the inverse of how you render your triangles, so it should equal the inverse view matrix ** ...


4

Index buffers are useful because they reduce the amount of vertex data that the GPU must process. First of all, where vertices are reused across multiple triangles, only one copy of the vertex data is needed; since vertex data is typically much larger than index data, that means less memory consumed, and less memory bandwidth required to load the vertex ...


4

You need to process exported models to be used in a game. Model editors like Blender or Max are not strictly intended for making real-time simulations. You can use tools like AssImp to read in models in various formats, do a number of post-processing steps (many are built in), and then save it in a format better fitted to your engine. One of these stages ...


4

I know this is old but i would like to add a little practical information. As stated by others but more specifically related to graphical programming. A Normal aka (a surface normal) is orthogonal to a flat plane our triangles surface. (it sticks out from it) A Tangent can be considered to be a normal that lies along or on that plane (its co-planar) ...


4

This means that I can only store 2^16 = 65536 vertices. No it doesn't. It means that you can only use 16-bit indices (assuming it even means that, as I'm fairly sure D3D9 allows 32-bit indices. That's what the INDEX32 index buffer format means, right?). Which means that a single draw call can only access a 16-bit range of indices. But you are not limited to ...


4

As you are using hlsl I presume you use DirectX. You can use the input semantic VPOS (DX9) or SV_Position (DX>=10): MSDN - VPOS & SV_POSITION semantics When you pass the render target resolution reciprocal one mad is sufficient to construct the screen space uv for every type of geometry. You can not simply do what you proposed as the interpolation does ...


4

Video cards without hardware T&L are dinosaurs. Seriously, there haven't been any new cards without hardware T&L since about 2000. Forget about them, just use hardware vertex processing and assume it's supported - unless you specifically need to support 14-year-old cards for some reason.


4

Typically, your list of indices looks like this: [ 1st vertex index of triangle 0, 2nd vertex index of triangle 0, 3rd vertex index of triangle 0, 1st vertex index of triangle 1, 2nd vertex index of triangle 1, 3rd vertex index of triangle 1, 1st vertex index of triangle 2, ...etc ] So the three vertices of triangle i are: vertices[indices[...


4

The example you use of a cube is a very specific, and somewhat contrived, one where indexing does not provide it's full benefit. For most real-world examples the constraints you mention do not exist, and indexing has been demonstrated - for approx 20 years - to be effective. This is something that goes back to at least Quake 3 in 1999: Quake3’s rendering ...


Only top voted, non community-wiki answers of a minimum length are eligible