Unidirectional gouraud shading in the engine

Posted By: ulillillia

Unidirectional gouraud shading in the engine - 08/23/05 15:24

In MED and WED, when you move the camera around (panning), the lighting changes. I'd like to have this same thing in the engine except not changing from panning (be constant). Like, for example, if I had the Sun to the southeast 45° above the horizon, the lighting would be like that. This would cause the northwest sides of objects to be the darkest and the southeast sides to be the lightest. The lightest should be the true color version while the darkest be half transparent black. The function only needs to run once for the associated world and change when the world changes (such as going from the city world to the mountain world) being processed only once again (although things will be flagged as visible and invisible and eventually be created when the player changes the graphics options for some worlds).

These are MDL models, not blocks. I'd like to know how to accomplish this. The only thing that I can think of is to have a separate model for the lighting, but this is hard to do on curved surfaces like hilly land and could seriously hurt the frame rate, even with my.dynamic set to off.
Posted By: Specterdragon

Re: Unidirectional gouraud shading in the engine - 08/23/05 18:06

Well, this could easily be accomplished with a simple shader. My question though... Isn't there a way to do this directly from inside WED? If it's somehting that simple, I would think there is a mat_shaded option on the object properties window.

Unfortunatly, I'm at work at the moment and can't look, but it seems like it would be that simple.
Posted By: ello

Re: Unidirectional gouraud shading in the engine - 08/23/05 18:13

i once did a nice lighting situation, maybe thats what you are talking about.
heck this: http://www.earthcontrol.de/downloads/katakomben/katakomben.zip out, the global lighting always comes from the same side, no matter where you look at.
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 08/23/05 18:33

Hmm. I downloaded it and Winzip says that that ZIP file is an invalid archive and don't see anything. Thus, I can't use it. Winzip said to try to redownload it so I did and that didn't work either.

Question, does this allow you to configure the angle positions of the "Sun"?
Posted By: ello

Re: Unidirectional gouraud shading in the engine - 08/23/05 18:36

that was just ment as a demo to see if you where talking about that. (file works for me)

you can check the images on my website (downloads -> katakomben) and tell me if thats what you are talking about...
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 08/23/05 18:49

It's hard to see the lighting as the area is very foggy and from the best I can tell, I can't make anything out well enough to see if it's what I'm after. Perhaps showing an "octagonal" sphere might help (without the intense fog of course) with this applied. Interesting project though.
Posted By: Julius

Re: Unidirectional gouraud shading in the engine - 08/29/05 08:53

i don't know if this will help, but try the settings in WED's Map Properties -> Sun to set the position and brightness of the sun, and in the manual (Help -> Contents) do a Seartch for "sun_light".

i hope this is what you're looking for. i think it lights all entities in the direction of the sun and puts shadow on the other side.

julius
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 08/29/05 19:05

I looked into that earlier, but it causes false coloring. I'd like it to have hard gouraud shading where all faces facing in one direction have the same lighting conditions. In fact, it turns my much-better-looking world:



into this horrible-looking version of almost the same position (without any modifications besides the addition of the sun through script)):



Before, the ambient was giving me problems, but setting it to zero fixed it. In this case, the ambient is zero and it doesn't help. In fact, both the ambient and albedo are at the default and simply changing them won't get what I want.

That is definitely not acceptable. That's why I can't use the sun (or any lights at that). Perhaps you might want a screenshot or two of what I'm talking about to better explain this?
Posted By: Pappenheimer

Re: Unidirectional gouraud shading in the engine - 08/29/05 21:05

I think that you mean the effect that the sharp edges of the houses look smooth.
That is because auf the models. If you want to have sharp edges while goroud shading, you have to build them with seperate planes for each side, DON'T merge them.
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 08/29/05 22:33

Perhaps, you might need some objects to help understand what I'm after? Here's a screenshot of what I'm talking about:



This is a view of what I'm after. This is textured, by the way, and it took two hours to figure it out and it's still not perfect. If you want, you can download the model and see for yourself what I'm after. It's not exact, but fairly close In my case, the sun comes from due east and is 45 degrees above the horizon.

If I were to have separate planes, the vertex count would practically double (or quadruple in some cases). This would seriously harm the frame rate. Blocks appear correctly with the shading as they should. Blocks have what I call "hard gouraud shading". If you add the sun and have a bunch of blocks of all shapes and look at them after building, that's exactly what I want for models. The screenshot directly above is how blocks appear. The darkest side should be half as bright as the lightest side. I don't think I'm asking much.
Posted By: Stansmedia

Re: Unidirectional gouraud shading in the engine - 08/30/05 13:29

Quote:

i once did a nice lighting situation, maybe thats what you are talking about.
heck this: http://www.earthcontrol.de/downloads/katakomben/katakomben.zip out, the global lighting always comes from the same side, no matter where you look at.




Thats really cool ello.
Posted By: ello

Re: Unidirectional gouraud shading in the engine - 08/30/05 13:36

ok, i got you..

you need to apply ShadeMode=flat; to the objects. additional you can calculate the lighting using dot(normal,-vecSunDir); just as a point into the direction.

thanks, kris:) i like it pretty much, too
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 08/30/05 16:10

I figured you would've needed that example as a guide. Using what you have given me to add, I get script errors. shademode = flat is not recognized by the engine. I can't find it in the manual either so perhaps you might have the wrong thing. Searching for "shade" didn't help either and "mode" gives a lot of unrelated results. The thing with "dot(normal, -vecSunDir)" is also giving me script errors. I figured that the hyphen in the front was causing it, but that didn't help. One of my other errors was because I forgot a semicolon, but that I fixed on my own. Here's what I'm up to right now:

shademode = flat;
sun_light = 256; // some random number - don't know the impact of it
sun_angle.pan = 0; // from due east - brightest on the east side of object
sun_angle.tilt = 45; // half way from horizon to straight up - about 8:40 AM
dot(normal, vecsundir);

Edit: Oh, as a reminder, this only needs to be applied just once each time a level loads and not be reprocessed every frame. Thanks.
Posted By: ChrisB

Re: Unidirectional gouraud shading in the engine - 08/30/05 19:25

Code:
 
material mat_model
{
effect="
technique hardedge{
pass p0{
ShadeMode=flat;
}
}";
}



This overrides the shading of all models (if they have not other materials).
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 08/30/05 20:38

Ah. I didn't know it was one of those things in an effect string. However, that still leaves the dot(normal, vecsundir) thing left. Is that, perhaps, a material effect?

Almost all my models don't have materials assigned to them, except to change the ambient color to 255 for all of them for true color (default is 200 for some odd reason). This, however, is that mat_model material, the global one. Most have only one action: my.dynamic = off;. This speeds up the frame rate as most of the objects are static, though few move.
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 08/30/05 21:04

So, I tried adding the shademode = flat thing which IS better, but still not correct. The colors on the lighted sides are wrong and the lighting should be based on the angle of the surface not what I have here:



That one odd block, the red one on the left in front, is how it should look. That's a block though and will later be replaced with a model, a start platform. Note that the other objects in the background have this bad white color and you can clearly see the polygons that make up the object. The polygons should, actually, be made of the same lighting when on the same plane (as with the block. The "normal" color you see is how they should appear at the brightest. For the darkest, it's like putting a half-transparent black object over it as with layers in GIMP. That's the concept I'm using in my 2D game (and the same basic sun angle as well where the brightest is on the top right and the darkest is on the bottom left. That red octagon-sphere above is how it should look like. This is only textured though and took about two hours to figure it out.
Posted By: ulillillia

Re: Unidirectional gouraud shading in the engine - 09/02/05 12:09

One odd (and unusual) way of doing this, though I'm not sure if it'll work, is to have a light darken a texture. The light should be pure black (or 8, 8, 8 if 0, 0, 0 causes problems). The light should then darken everything it hits to half as bright. In the case of that octagon sphere (shown above), the light would be coming from the west and 45 degrees below the horizon. Anything, it hits, dependent strictly on the angle of the polygon, will get darkened and the head-on area (for the light) will be the darkest and the side on the opposite end will be completely unaffected by the light (true color). How do I do this?
© 2024 lite-C Forums