need help with per-vertex lighting
need help with per-vertex lighting
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.
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.
Last edited by Max Power on Mon Apr 13, 2015 8:39 am, edited 1 time in total.
Re: need help with per-vertex lighting
Irr does support quads (only not in VBOs without my patch), but I'm not sure it would solve your problem. Try it anyway.
Re: need help with per-vertex lighting
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?
Would you have any suggestion how I can make the transitions in the second picture look like in the first?
Re: need help with per-vertex lighting
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).
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.
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.
Re: need help with per-vertex lighting
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.
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.
Re: need help with per-vertex lighting
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
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
Re: need help with per-vertex lighting
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.
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.
Re: need help with per-vertex lighting
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
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
Re: need help with per-vertex lighting
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:
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...
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)".
Re: need help with per-vertex lighting
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.
You can disable the interpolation with the flat keyword, I don't remember which GLSL version that was added in.
Re: need help with per-vertex lighting
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?
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?