Highlevel shader has odd normals output?

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
dart_theg
Posts: 53
Joined: Sun Dec 29, 2024 3:13 am

Highlevel shader has odd normals output?

Post by dart_theg »

I'm working on adding shader support for my game engine, and the low level shaders work great but high level is where I run into problems.

https://i.imgur.com/Fjd5YKv.gif

The first is with high level, and the second is with low level.
The shader is from Example 10.

Any idea what may be the issue?
CuteAlien
Admin
Posts: 9926
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Highlevel shader has odd normals output?

Post by CuteAlien »

Well it does look like front/back faces of the box are the wrong way. And maybe low-level doesn't do backface culling? Probably not the real reason, but hard to tell without more info and having something to experiment with.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
dart_theg
Posts: 53
Joined: Sun Dec 29, 2024 3:13 am

Re: Highlevel shader has odd normals output?

Post by dart_theg »

I set backface culling to true and front face culling to false and now it doesn't look all weird, but it's still not consistent with low level/the example file...

https://i.imgur.com/LGN75Ua.png

Here's my code for adding the shader callback and everything. It's slightly edited callback from Example 10:

io::path vsPath = vs.c_str();
bool hasPS = !ps.empty();
io::path psPath = hasPS ? io::path(ps.c_str()) : io::path("");

ShaderCallback* cb = new ShaderCallback(irrHandler->useHighLevelShaders, irrHandler->useCGShaders, device);

s32 mt = -1;
if (irrHandler->useHighLevelShaders) {
mt = gpu->addHighLevelShaderMaterialFromFiles(vsPath, "vertexMain", EVST_VS_1_1, psPath, hasPS ? "pixelMain" : nullptr, EPST_PS_1_1, cb, mat.MaterialType, 0, irrHandler->useCGShaders ? EGSL_CG : EGSL_DEFAULT);

mat.BackfaceCulling = true;
mat.FrontfaceCulling = false;
} else
mt = gpu->addShaderMaterialFromFiles(vsPath, psPath, cb, mat.MaterialType, 0);

mat.MaterialType = (E_MATERIAL_TYPE)mt;

cb->drop();

Let me know if there is a huge flaw. I'm not incredibly knowledgeable with shaders.
n00bc0de
Posts: 116
Joined: Tue Oct 04, 2022 1:21 am

Re: Highlevel shader has odd normals output?

Post by n00bc0de »

Are you setting your shader contants every frame? From looking at the code for Example 10, it looks like it uses a light position, world projection, and a few other variables. If you are not setting that each frame then if could cause the results to be wrong.
CuteAlien
Admin
Posts: 9926
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Highlevel shader has odd normals output?

Post by CuteAlien »

You can disable both cullings. But you shouldn't have to. Lets start simple - if you run Irrlicht example 10 directly and not in your engine - does it work? If not - which driver does it fail?

The problem shouldn't be in shader loading code you posted as you seem to have a shader in both cases. To make sure check if mt >= 0.
Also you could experiment with requesting higher shader numbers (EVST_VS_5_0, EPST_PS_5_0), thought if I remember right those only matter on D3D and on OpenGL they were ignored anyway. And the example seems to use your numbers so it should work.

I assume it's also not a problem in the box mesh if you create it the same way as the example. If you load some box modeled in some tool instead please post the model file somewhere.

So could be ShaderCallback doing something wrong (aka what n00bc0de proposes). Or the shader file itself might be wrong (was it changed in any way?)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply