Skip to content

WIP: glsl/normal: use ifdef for normal z reconstruction#189

Closed
illwieckz wants to merge 2 commits intoDaemonEngine:masterfrom
illwieckz:ifdef-heightmap
Closed

WIP: glsl/normal: use ifdef for normal z reconstruction#189
illwieckz wants to merge 2 commits intoDaemonEngine:masterfrom
illwieckz:ifdef-heightmap

Conversation

@illwieckz
Copy link
Copy Markdown
Member

@illwieckz illwieckz commented Mar 24, 2019

DO NOT MERGE until the #ifdef bug is fixed, see #190.

This is a simple change that makes glsl relying on #ifdef instead of an uniform to test for the fact the normalmap is embedding heightmap in alpha channel or not. This makes GMA965 able to render parpax default scene with 11 fps instead of 10 (+10%) (unnoticeable on R9 390X).

This is not merged yet because of a nasty bug, it looks like the define is not defined any time as while I move in map, the wrong code is sometime run instead of the expected one:

glsl ifdef

glsl ifdef

The bug is on the wall texture, not on the blooming reactor.

I reproduced the bug on both radeonsi (R9 390X) and i965 (Haswell) drivers, this is likely to not be a driver bug but a bug in dæmon code, the ifdef code is very cryptic and would benefit a lot from a rewrite.

I'm basically pushing this branch so people have code to debug the #ifdef bug (#190).

@illwieckz illwieckz added T-Improvement Improvement for an existing feature A-Renderer labels Mar 24, 2019
@slipher
Copy link
Copy Markdown
Member

slipher commented Mar 25, 2019

A couple suspicious things:

  • You only set the height mapping macro if the parallax cvar is enabled, but some of the GLSL that depends on it is outside of ifdef parallax blocks.
  • Liquid shader has the macro but it is never enabled.

@illwieckz
Copy link
Copy Markdown
Member Author

You only set the height mapping macro if the parallax cvar is enabled, but some of the GLSL that depends on it is outside of ifdef parallax blocks.

good catch!

Liquid shader has the macro but it is never enabled.

right, this code is not yet used but it's better to not have bugs in dormant code

I'll reread the stuff to be sure this variable is set in any code that use normal map (they may be more), not only those that use parallax.

@illwieckz
Copy link
Copy Markdown
Member Author

illwieckz commented Mar 25, 2019

I postpone changes to this PR for after #188 merge since once #188 is merged I would be able to do things like that:

if (normalMapping || parallaxMapping)

@illwieckz
Copy link
Copy Markdown
Member Author

I rebased on master but the #190 bug is still there so merge is blocked

@slipher
Copy link
Copy Markdown
Member

slipher commented Mar 31, 2019

It looks like in some shaders, you are doing SetHeightMapInNormalMap only if a condition is met. So when the condition is not met, you get a random value left over from the last time the shader was used.

@illwieckz illwieckz force-pushed the ifdef-heightmap branch 2 times, most recently from 523a6fb to 48a0893 Compare April 20, 2019 15:04
@illwieckz
Copy link
Copy Markdown
Member Author

do someone can explain me why the latest commit is fixing the bug?

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 20, 2019

Do you really need the 2nd commit for it to work? It looks like the first one was changed to avoid the bug that I talked about before.

@illwieckz
Copy link
Copy Markdown
Member Author

illwieckz commented Apr 20, 2019

Yes, the second commit is required to fix the bug. The changes I added to the first commit to fix the issue you talked about before is not enough.

It's also why I kept this second commit separate to be able to ask the question. 😛

@illwieckz
Copy link
Copy Markdown
Member Author

illwieckz commented Apr 20, 2019

Well, that only fixes it for now, if I add some commits editing some unrelated stuff the bug comes back again… the unrelated commit I was working on was a commit merging reflection in lightmap stage to avoid double parallax compute… this one added a macro since the reflectCube glsl would be useless in that case, and the bug came back… I know the macro thing is tricky since each macro is a bit of one integer, may be we overflow that integer because of “too many macro”?

There is a check about that “too many macro” scenario but I never triggered it so I suspect it does not work. In some WIP earlier commits I had a lot of macros and I was wondering why the "too many macro" test was not shooting at me…

@illwieckz
Copy link
Copy Markdown
Member Author

@slipher, note that MAX_SHADER_MACROS is set to 9 here:

static const unsigned int MAX_SHADER_MACROS = 9;

@illwieckz
Copy link
Copy Markdown
Member Author

But I never get this error in any way:

if ( _compileMacros.size() >= MAX_SHADER_MACROS )
{
Sys::Drop( "Can't register more than %u compile macros for a single shader", MAX_SHADER_MACROS );
}

@illwieckz
Copy link
Copy Markdown
Member Author

This may be a bug similar to the one fixed in #211

illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 13, 2019
no renaming in gl code because one day it will use a macro definition
in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 15, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 15, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
@illwieckz
Copy link
Copy Markdown
Member Author

This will be obsoleted by my PR introducing loose heightmap support.

I'm not sure there is a bug in that ifdef code, similar artifact can happen with zero normalscale (hence undefined normalscale). I noticed some issues with that other feature, so maybe it's the same.

@illwieckz illwieckz closed this Dec 15, 2019
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 15, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 15, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 24, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 25, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 26, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 26, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 27, 2019
about renaming heightMapInNormalMap as hasHeightMapInNormalMap:
there is no no renaming in gl code because one day it will use
a macro definition in any way, see DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 27, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 28, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189

About the collapse code collapsing heightmap stage while heightmap is a pre-colapsed stage attribute:

> @slipher: The commit message says the heightmap is a per-stage attribute, but this looks like it's in a stage by itself?

> @illwieckz: The dpMaterial DarkPlaces compatibility layer is not yet ported to the pre-collapsed stage code and I'm using Xonotic assets to test this feature, hence the temporary requirement to collapse a standalone heightmap stage. There is no keyword available to mapper to use the standalone heightmap stage, only the per-stage attribute, so there is no chance a mapper uses the standalone heightmap stage by mistake and we can drop it one day.

DaemonEngine#252 (review)
illwieckz added a commit to illwieckz/Daemon that referenced this pull request Dec 28, 2019
also make USE_HEIGHTMAP_IN_NORMALMAP a macro, obsoletes DaemonEngine#189

About the collapse code collapsing heightmap stage while heightmap is a pre-colapsed stage attribute:

> @slipher: The commit message says the heightmap is a per-stage attribute, but this looks like it's in a stage by itself?

> @illwieckz: The dpMaterial DarkPlaces compatibility layer is not yet ported to the pre-collapsed stage code and I'm using Xonotic assets to test this feature, hence the temporary requirement to collapse a standalone heightmap stage. There is no keyword available to mapper to use the standalone heightmap stage, only the per-stage attribute, so there is no chance a mapper uses the standalone heightmap stage by mistake and we can drop it one day.

DaemonEngine#252 (review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Renderer T-Improvement Improvement for an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants