|
surface - surface handle index - index of the vertex, from 0 to CountVertices( surface )-1 red# - red value, 0 to 255 green# - green value, 0 to 255 blue# - blue value, 0 to 255 alpha# (optional) - vertex transparency, 0.0 to 1.0; 1.0 (default) |
|
Sets the colour of an existing vertex. Vertex colours blend smoothly across each triangle, which makes them a very cheap way to shade a mesh: baked lighting, gradients on skies, tinted terrain-style geometry, glowing tips on effects - all without a single texture. New vertices start at 255,255,255 with alpha 1. Vertex colours are ignored until the entity or brush uses EntityFX/BrushFX flag 2 (use vertex colours instead of brush colour). For the per-vertex alpha# to show as transparency, also add flag 32 (force alpha-blending) - flags 2+32 together. Colour values outside 0-255 are clamped. See also: EntityFX, BrushFX, VertexRed, VertexGreen, VertexBlue, VertexAlpha. |
; VertexColor Example
; -------------------
; VertexColor tints a single vertex; the GPU blends the colours
; smoothly across each triangle. Vertex colours only show when the
; entity has EntityFX flag 2 set. Here each corner of a quad cycles
; through colours at its own pace.
Graphics3D 640,480
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,0,-4
panel=CreateMesh()
surf=CreateSurface(panel)
; A simple quad with one vertex per corner
v0=AddVertex(surf,-1.5,1.5,0)
v1=AddVertex(surf,1.5,1.5,0)
v2=AddVertex(surf,1.5,-1.5,0)
v3=AddVertex(surf,-1.5,-1.5,0)
AddTriangle surf,v0,v1,v2
AddTriangle surf,v0,v2,v3
; Flag 2 = use vertex colours instead of lighting
EntityFX panel,2
While Not KeyDown(1)
; Cycle each corner's colour with offset phases - the documented
; command, called once per vertex per frame
t#=MilliSecs()*0.1
r0#=127+128*Sin(t)
g0#=127+128*Sin(t+120)
b0#=127+128*Sin(t+240)
VertexColor surf,v0,r0,g0,b0
VertexColor surf,v1,g0,b0,r0
VertexColor surf,v2,b0,r0,g0
VertexColor surf,v3,255-r0,255-g0,255-b0
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"Arrow keys: move camera Esc: exit"
Text 0,20,"VertexColor surf,v0,"+Int(r0)+","+Int(g0)+","+Int(b0)
Flip
Wend
End