Gamestudio Links
Zorro Links
Newest Posts
FXCM demo test failed
by qin. 01/13/26 13:53
Camera always moves upwards?
by NeoDumont. 01/12/26 09:39
Alpaca Plugin v1.5.2 Release
by kzhao. 01/11/26 13:42
Alpaca Plugin v1.4.0
by kzhao. 01/11/26 13:38
separating groups of 3 digits by a comma
by joe_kane. 01/11/26 00:01
MRC.c and WFO
by joe_kane. 01/10/26 23:58
BarOffset (default = 940 for daily bars?
by joe_kane. 01/10/26 23:46
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 5,207 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
promfast, joe_kane, Namitha_NN, Syndrela, agasior
19190 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Change color/Brightness per Vertex #312716
02/26/10 02:05
02/26/10 02:05
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline OP
Expert
Damocles_  Offline 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_] #312742
02/26/10 10:34
02/26/10 10:34
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
On the shader side it actually isn´t a problem at all. As you just have to pass it from the vertex to the pixelshader and use it there. The as I think also not so hard part, is to feed the vertexshader with those information as some extra vertexdata. You could do it as color or another texcoord or whatever. The maybe harder part is, to get those information, as you would have to use a file format supporting vertexcolors or however you want to call it.

Re: Change color/Brightness per Vertex [Re: Slin] #312745
02/26/10 10:55
02/26/10 10:55
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline OP
Expert
Damocles_  Offline OP
Expert

Joined: Feb 2009
Posts: 2,154
I never programed any shader.
The Vertexinformation could be given directly as
a handmade array (for the start) if thats possible (must be in
a compatable format I guess)

My idea is actually to have a terrain Model (or simple tile-cube models), and adjust the
brightness of Vertecies, to create simple shadows,
without having a specific shadowmap.
(so that the vertex-elumination can be altered in runtime)

The vertexposition/number could be easily determined for
regular models such as a terrain / gridbased model.

Re: Change color/Brightness per Vertex [Re: Damocles_] #312749
02/26/10 11:46
02/26/10 11:46
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
The shader part is one or two minutes of work, if you are able to extend the D3D vertex format to also have a color, I can help you with the shader. Extending the vertex format isn´t that hard I think, but I am currently more into OpenGL than D3D and I am also not sure how to do it in combination with A7.

Re: Change color/Brightness per Vertex [Re: Slin] #312762
02/26/10 12:55
02/26/10 12:55
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline OP
Expert
Damocles_  Offline OP
Expert

Joined: Feb 2009
Posts: 2,154
ok, i have a look at that

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 Offline
Serious User
DJBMASTER  Offline
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...
Code:
#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_ Offline OP
Expert
Damocles_  Offline 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
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

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:
Code:
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(&currentVec, this, ent_bonename(this, NULL, vexCount));
		ang_for_bone(&currentAng, 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(&currentVec2, this.pan);
		vec_add(&currentVec2, this.x);
		// then get relative position to bone
		vec_sub(&currentVec2, &currentVec);
		// account for the bone's angle
		vec_rotateback(&currentVec2, &currentAng);
		// 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: JibbSmart] #312900
02/26/10 19:29
02/26/10 19:29
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline OP
Expert
Damocles_  Offline OP
Expert

Joined: Feb 2009
Posts: 2,154
Thanks for the code example.

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 Offline
Expert
Hummel  Offline
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 laugh

Page 1 of 2 1 2

Moderated by  Blink, Hummel, Superku 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1