need help with per-vertex lighting

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

need help with per-vertex lighting

Post by Max Power »

I use vertex colors as some kind of static lighting, so I can raycast to each vertex only when changes occured in the world and have shadows without any performance loss.

I know it doesn't look very pretty, but with some smoothing later on, I think it will suit my needs.

I suppose the problem is, I have to interpolate between the vertex colors as quads, not as triangles. Only there are no quads in Irrlicht afaik. Before I begin trying to write some shader that uses the missing 4th color value, stored somewhere inside the vertex data, and modify the whole interpolation part manually, I'd like to get some advice. Maybe it doesn't have to be so complicated. What I don't want is to increase the polygon count.

Here are pictures of the problem. Depending on the light's direction, there either is (2nd pic) or isn't (1st pic) a problem, depending on wether interpolation between light and shadow can happen smoothly or not. To show what I mean, I added a wireframe material (sorry it's so dark), so you know how the triangles are drawn.


Image

Image
Last edited by Max Power on Mon Apr 13, 2015 8:39 am, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: need help with per-vertex lighting

Post by hendu »

Irr does support quads (only not in VBOs without my patch), but I'm not sure it would solve your problem. Try it anyway.
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: need help with per-vertex lighting

Post by Max Power »

Let's assume for a moment I never said anything about quads ^^
Would you have any suggestion how I can make the transitions in the second picture look like in the first?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: need help with per-vertex lighting

Post by hendu »

Move to a per-pixel model. Interpolation is always a smooth gradient, it cannot be made to handle arbitrary angles without adding more interpolation points (verts).

Image

In theory, you could work around it by extending the range, then clamping, such that the result would look the same. In this picture, the top-left and bottom-left corners would then be over 1 by a suitable amount, which you'd then handle in the shader.
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: need help with per-vertex lighting

Post by Max Power »

All I ever did inside fragment shaders was to use either global or vertex-interpolated values. No idea how I'd do per-pixel lighting. I googled it, but didn't find anything enlightening...

So... I would need a light map for every surface I guess? In a large voxel world that would easily make hundreds of thousands of those, no?

Btw, I don't necessarily need precisely drawn shadows. I just want to do something about the "interruption" of interpolation between two vertices in opposite corners of a square, when the two triangles' internal edges are not connecting THEM but the other pair of opposite vertices.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: need help with per-vertex lighting

Post by hendu »

Yes, lots of shadow maps in a big world if you want to precalculate.

If you use my extended range gradient, it doesn't matter which way the quad's inner connection goes. Picture it as going to the ultraviolet range, cannot be seen by human eyes ;)
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: need help with per-vertex lighting

Post by Max Power »

Your patch...

Is it part of some other Irrlicht branch or how do I get it?

Can you give me a quick overview about what Irrlicht versions there are? Because I only ever used the "standard" version.

I think doing some fake quad interpolation on triangles inside the vertex-shader probably isn't even possible, is it? And even if it is, storing the 4th color inside the other vertices would be overly complicated and likely redundant as well.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: need help with per-vertex lighting

Post by hendu »

http://sourceforge.net/p/irrlicht/patches/240/

There are three active branches: trunk, shader-pipeline and ogles. Then there are a few forks like mine.

There is no need for quad interpolation? And the alpha vertex color is already taking VRAM, so you might as well use it ;)
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: need help with per-vertex lighting

Post by Max Power »

Ok, after reading a bit about shader attribute variables, I decided there is no way to change the way interpolation between vertices is done. So the color I get to use inside the fragment shader will always be triangle-interpolated and it's impossible to modify the weighting. For example, the right-angle vertex' weight will always be 0 at the hypothenuse, which just won't work.

I also decided it's impossible to pass the 3 (+1) "raw" vertex colors to the fragment shader to do the interpolation there, based on uv-coordinates.

I then went on to figure out how to use an SVN client to download the shader-pipeline branch, which would finally allow me to use actual quads and other stuff like custom vertex-types.

...and finally got stuck trying to compile that thing. Can I comment out all the d3dX defines and just use openGL? I did download the Windows kit from the link inside IrrCompileConfig.h, but there's no d3d9shader.h and I don't know what libs I need to use from there.

And even if I comment all the d3d stuff out, I still get linker errors and have no idea what to do about them:

Code: Select all

1>CSceneManager.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: __thiscall irr::scene::CInstancedMeshSceneNode::CInstancedMeshSceneNode(class irr::scene::IMesh *,class irr::scene::ISceneNode *,class irr::scene::ISceneManager *,int,class irr::core::vector3d<float> const &,class irr::core::vector3d<float> const &,class irr::core::vector3d<float> const &)" (??0CInstancedMeshSceneNode@scene@irr@@QAE@PAVIMesh@12@PAVISceneNode@12@PAVISceneManager@12@HABV?$vector3d@M@core@2@33@Z)".
 
1>CIrrDeviceWin32.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""class irr::video::IVideoDriver * __cdecl irr::video::createDirectX11Driver(struct irr::SIrrlichtCreationParameters const &,class irr::io::IFileSystem *,struct HWND__ *)" (?createDirectX11Driver@video@irr@@YAPAVIVideoDriver@12@ABUSIrrlichtCreationParameters@2@PAVIFileSystem@io@2@PAUHWND__@@@Z)".
Some help would be appreciated. And if I somehow manage to compile this version, I may assume that if Irrlicht 1.9 ever gets released, it will look a lot like this, right? So I won't have to rewrite everything, I mean...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: need help with per-vertex lighting

Post by hendu »

Shader-pipeline is not for 1.9 but for a later version. Can't help with the compiling, I don't use it.

You can disable the interpolation with the flat keyword, I don't remember which GLSL version that was added in.
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: need help with per-vertex lighting

Post by Max Power »

I think I will put aside this problem for now and work on something else. It's just getting ridiculous. If I could use quads, it would be so simple.

The only thing I could come up with is to store all 4 vertex-colors of a square inside the primitive's provoking vertex (which I only just heard about...), so I can pass them on as "flat".
Since I can't define custom vertex types in Irrlicht 1.8.1, I guess I would need to store SColors as 32-bit float normal components or something (assuming I can properly cast them back inside the shader somehow).
Then I would use the texCoords inside the fragment-shader to know the UV-coordinates (there has to be a better way, but I didn't find it :/) and interpolate the flat colors myself.

Sounds pretty stupid, eh? Anyway, thanks for your help and patience. Is 1.9 going to be released anytime soon? And will it have non-triangular primitives?
Post Reply