|
2 registered members (Quad, TipmyPip),
6,316
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Change color/Brightness per Vertex
#312716
02/26/10 02:05
02/26/10 02:05
|
Joined: Feb 2009
Posts: 2,154
Damocles_
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 2,154
|
Hi, does anyone know of a shader, where you can adjust the elumination of a model by directly changing the brightness of a vertex (eg edge of a polygon). So that you could for example say Vertex 10,24 and 54 of a model should be darker. by this changing the elumination smoothing/interpolating over the triangle. Like in Gouraud Shading, but that I can alter the elumination myself. for example to put a darkened or colored area onta a model, at specific vertex positions.
|
|
|
Re: Change color/Brightness per Vertex
[Re: Damocles_]
#312800
02/26/10 14:27
02/26/10 14:27
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
You can define your own FVF (Flexible Vertex Format) so the vertex structures consist of position and diffuse properties...
#define MYVERTEX_FVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)
This is one of the first things you learn with DirectX, using vertex buffers to draw primitives. I think FVF are supported by the programmable pipeline in DX9, although they are generally used within the Fixed-Function Pipeline, and so to get them working in shaders I think you have to convert them to vertex declartions. The D3D function 'CreateVertexDeclaration' might be what you are looking for.
Last edited by DJBMASTER; 02/26/10 14:30.
|
|
|
Re: Change color/Brightness per Vertex
[Re: DJBMASTER]
#312811
02/26/10 14:45
02/26/10 14:45
|
Joined: Feb 2009
Posts: 2,154
Damocles_
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 2,154
|
Thanks for the info. Actually Im looking for a method to simply alter the brightness (full or offset-value) for each vertex. But Im not really into all that low level rendering stuff. To I think I have to pass on that. (Im more proficient in AI and gamelogic programming) The basic Idea behind all this is to have a worklow to archive screens like this: (yes, saw that recently in Morbius)  Kind of very old and classic 3D scenes. Where the "shadows" are actually just realized by altering Vertex-brightness, without fancy mixing of Textures. The good thing is, that is is very fast. So with a method to alter the vertex-brightness it is realively easy to create a level-editior that generates "Block/Grid" based levels, and creates a simple shadoweffect on some of these blocks. Thus creating a fast and flexible elumination/shadowing of the scene without any dynamic lights etc. But realizing that myseft goes a bit too deep into the rendering-procedure for me.
|
|
|
Re: Change color/Brightness per Vertex
[Re: Damocles_]
#312893
02/26/10 18:47
02/26/10 18:47
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
When I set up an example demonstrating how much faster GPU-driven bones animation was than CPU-driven animation, I had to modify vertices to contain an index so that each vertex knew which matrix it should use. I used ent_getvertex to modify the second uv set, which wasn't being used. I really don't understand the manual's example usage of ent_setvertex. Using c.v (you'll know what I mean if you look in the manual) gives you access to the actual vertex buffer, so modifying the contents of c.v shouldn't require the use of ent_setvertex at all (my code doesn't). Here's the function I had:
function initEnt() {
VECTOR currentVec;
VECTOR currentVec2;
ANGLE currentAng;
CONTACT* c;
var vexCount = ent_status(this, 0);
STRING* currentBone = str_create("#10");
while (vexCount > 0) {
c = ent_getvertex(this, NULL, vexCount);
// get position relative to the bone it is attached to
vec_for_bone(¤tVec, this, ent_bonename(this, NULL, vexCount));
ang_for_bone(¤tAng, this, ent_bonename(this, NULL, vexCount));
// swapping co-ordinates so I can use built-in functions
currentVec2.x = c.v.x;
currentVec2.y = c.v.z;
currentVec2.z = c.v.y;
// translate into world space
vec_rotate(¤tVec2, this.pan);
vec_add(¤tVec2, this.x);
// then get relative position to bone
vec_sub(¤tVec2, ¤tVec);
// account for the bone's angle
vec_rotateback(¤tVec2, ¤tAng);
// swap z and y co-ordinate back when we recover
c.v.x = currentVec2.x;
c.v.y = currentVec2.z;
c.v.z = currentVec2.y;
// will also need to set u2 to something that indicates which bone it is attached to
ent_bonename(this, currentBone, vexCount);
if (str_cmpni(currentBone, "root") == 1)
c.v.u2 = 0;
else if (str_cmpni(currentBone, "head") == 1)
c.v.u2 = 1;
else if (str_cmpni(currentBone, "upper") == 1)
c.v.u2 = 2;
else if (str_cmpni(currentBone, "lower") == 1)
c.v.u2 = 3;
else if (str_cmpni(currentBone, "hand") == 1)
c.v.u2 = 4;
else
c.v.u2 = 5;
//...
vexCount -= 1;
}
}
It's not very clean, as I was busting out an example as fast as I could to make a case for GPU-based bones animation. But it hopefully makes it clear how I used ent_getvertex. I called this once at the beginning of the program to modify the second uv set (specifically, u2). Something similar could easily be done to indicate a brightness/darkness for a vertex, and whatever shader you used would be very easy to modify (as Slin already said). I hope this is of some use. Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Change color/Brightness per Vertex
[Re: Damocles_]
#312974
02/27/10 12:11
02/27/10 12:11
|
Joined: Mar 2006
Posts: 2,252
Hummel
Expert
|
Expert
Joined: Mar 2006
Posts: 2,252
|
I've packed together a small project for you. The shader simply uses the object space normals as color and the random values wich are sent to the shader using the second texcoords as brightness.  Should´nt be that problem to add this to an arbitrary shader even for a non shader programmer 
|
|
|
|