Hot answers tagged

31

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....


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: ...


13

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 ...


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 ...


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

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

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. ...


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

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) ...


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

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

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

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

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 ...


3

You are generating a lot of garbage and doing a lot of excess driver calls in those loops. Things like new VertexPositionColor[3] has to perform a heap allocation that the GC must then clean up. Ensure that every type you call new on in a loop is a struct. Be aware that things like foreach have to create a new enumerator object which may be a class type ...


3

Things like int*** are completely the wrong thing to use here. A "triple pointer" is not logically the same thing as a 3-dimensional array. You can just use a plain std::vector and claculate offsets manually with something like z * width * height + y * width + x (with the total size being width * height * depth of course). Create a vector, resize it, then ...


3

If you do tangent space normal mapping, as practically every game does nowdays, you should also store tangent space (binormal and tangent in addition to normal). For skinned characters you also need to store multiple (usually 4) bone indices and weights. In addition there can be multiple UV coordinates, some texture blending weights, color data, spherical ...


3

This question seems to be an X/Y problem. I think what you are really asking "how do I rotate a set of triangles?" You've settled on a very slow, very wrong solution to this problem. You should never be directly modifying vertex data on the CPU, unless you absolutely have to. I think your answer boils down to replacing: effects.Parameters["xWorld"].SetValue(...


3

From the OpenGL wiki: The input_primitive​ type must match the primitive type used with the drawing command that renders with this shader program. Given, Unity is probably using DirectX on Windows, but the same thing should hold true. Because your shader is asking for a point, it is only taking the first point from each primitive and ignoring the rest. ...


3

There is nothing inherently wrong with your original code when it comes to normalization. The only problem can be with meshes that do not properly share vertices, meaning your normalization code will always normalize the vertices that belong to a single Triangle. If you wish to fix such a mesh, you should either: Weld all vertices during import stage Apply ...


3

If we take as the requirements: no distortion no constraints on seam placement OK to overlap faces then we can use a pretty simplistic approach, independently rotating each face into a 2D plane and more or less leaving it wherever it ends up. // Iterate over each face (here assuming triangles) for(int index = 0; index < triangles.length; index += 3) { ...


3

If you use weight painting instead of vertex colors, you could export the model in any format that supports skeletal animation.


3

You could simply use multiple textures on the vertices, where each channel of each texture contains the value of some attribute. Then you can paint the attributes in any program that allows you to paint a texture on a model. You can have 4 attributes per texture. In your vertex program you can sample the texture to get the attribute values at that location.


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