VertexRed() etc.

Blitz3D Forums/Blitz3D Programming/VertexRed() etc.

_PJ_(Posted 2013) [#1]
I'm doing something wrong here, but I don't know quite how to fix it.

What I wanted to do, was to be able to identify the colour of a given mesh, by evaluating the VertexRed(), Green & Blue of A vertex of A triangle in the mesh.

As far as my thinking goes,
Theoretically all RGB's should be the same for all vertices, since the meshes are primitives with EntityColor applied. No EntityFX are set.

However, in my program, (in which the meshes used are COPIES of an original, with colour applied AFTER the copy is made), the RGB returned is consistently 255,255,255

I thought perhaps this may just be due to the original not being coloured and made a small test prog to see if there were any differences.

However, when I run the following, ALL the "Vertex" colours are white...

Can anyone point out where I've gone wrong? :D


Graphics3D 1024,768,32,6
SetBuffer BackBuffer()

Local Master=CreateCube()
EntityColor Master,255,0,0

Local Copy_A=CopyMesh(Master)
EntityColor Copy_A,255,255,0

Local Copy_B=CopyEntity(Master)
EntityColor Copy_B,0,255,0

Local Copy_C=CopyEntity(Copy_A)
EntityColor Copy_A,0,0,255
UpdateWorld
RenderWorld

Local V
Local Surface

Surface=GetSurface(Master,1)
V=TriangleVertex(Surface,1,0)

Color 255,0,0
Print "Master"
Color VertexRed(Surface,V),VertexGreen(Surface,V),VertexBlue(Surface,V)
Print "Vertex"
Print

Surface=GetSurface(Copy_A,1)
V=TriangleVertex(Surface,1,0)
Color 255,255,0
Print "Copy A"
Color VertexRed(Surface,V),VertexGreen(Surface,V),VertexBlue(Surface,V)
Print "Vertex"
Print

Surface=GetSurface(Copy_B,1)
V=TriangleVertex(Surface,1,0)
Color 0,255,0
Print "Copy B"
Color VertexRed(Surface,V),VertexGreen(Surface,V),VertexBlue(Surface,V)
Print "Vertex"
Print

Surface=GetSurface(Copy_C,1)
V=TriangleVertex(Surface,1,0)
Color 0,0,255
Print "Copy C"
Color VertexRed(Surface,V),VertexGreen(Surface,V),VertexBlue(Surface,V)
Print "Vertex"
Print



Rob the Great(Posted 2013) [#2]
Keep in mind that an entity's color and its vertex colors are completely unrelated. An entity color can be 0,0,0, but the vertex colors can still be 255,255,255.

I haven't played around much with vertex colors, but to my understanding, entity color affects an entire texture's "ambient" lighting if you will, while vertex colors affect each individual triangle's lighting and color. Setting the vertices on a single triangle to pure green will make that triangle pure green (if vertex coloring is enabled), but every other triangle will still be white.

Vertex RGBs may not necessarily return the overall color of an entity, as is what's happening in your code above. I don't even think there is a blitz command to obtain an entity's color. You may have to make a type to store that information manually when you set it in the program.


Yasha(Posted 2013) [#3]
Rob is completely right. Just to add an example, if you set your Entity's colour to pure red and set the vertices of a single triangle to pure green, that triangle should be drawn as pure black (assuming all the normal blend modes), which should help demonstrate how there are two completely different attributes in effect. EntityColor in effect sets the "base" colour for drawing operations that affect a mesh (i.e. rendering), but it doesn't actually colour the mesh itself in any way. that's what I get for talking without testing.

Also, without the vertex colouring FX enabled, it's always possible that the engine will discard vertex colours (haven't tried it), since it's not under any obligation to keep them.

One command that actually will paint vertices is LightMesh, although since it takes normals into account it's probably of limited utility for block colouring (the messing around to make it work is probably more complicated than painting the vertices individually).


Stevie G(Posted 2013) [#4]
This is not correct.

Vertexcolors are 255,255,255 by default. When you set entityfx to 2 (enabling vertex colors), entitycolor is ignored during the render. On the flip side, if entityfx does not have the 2 flag set then the vertexcolors are ignored. You can't mix and match the 2 methods - it's one or the other. Providing the entity is not set to fullbright, either method will still result in colours being adjusted depending on ambient lighting and other lights.

Also, you can't color individual vertices on each copied entity differently as the mesh data is shared across the copies and any change to the mesh level data changes all instances of that mesh. One way to do this would be to copymesh, instead of copyentity and then iterate throught the vertices and colour them and use your current method of obtaining the vertexcolor. This is very inefficient though ..

As has been mentioned, there is no command to get the entitycolor information directly from an entity. You will need to store this yourself. Probably best to use a type to store each instance of the entity and include r,g,b fields. Another method would be to store the ARGB value in the entities name for easy retrieval but this will mean you need another function to obtain the individual r,g,b elements.

If you can give a bit more information of what you are using this for, I'm sure someone can give you more help on the best method.

Stevie


_PJ_(Posted 2013) [#5]
Got it, thanks all.

I had assumed that ENtityCOlor was actually setting the Vertex colours of every vertex in a mesh.

entity color affects an entire texture's "ambient" lighting if you will, while vertex colors affect each individual triangle's lighting and color.

I think this pretty much sums it up.


_____


I should be able to paint the entities a different way, and use EntityBrush GetBrush or whatever! :)