Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need a reliable way to detect if a given surface is one of a bsp model #302

Closed
illwieckz opened this issue Mar 12, 2020 · 0 comments
Closed

Comments

@illwieckz
Copy link
Member

illwieckz commented Mar 12, 2020

Render is basically doing this to pick which glsl code to use to render a given texture:

if lightmapping is enabled and surface has lightmap:
	render_with_lightmap_as_map()
else if entity is not world:
	render_with_lightgrid_as_model()
else:
	render_with_lightgrid_as_map()

Real code there:

if ( !r_vertexLighting->integer && tess.lightmapNum >= 0 && tess.lightmapNum <= tr.lightmaps.currentElements )
{
Render_lightMapping( stage );
}
else if ( backEnd.currentEntity != &tr.worldEntity )
{
// FIXME: This can be reached if r_vertexLighting == 0 and tess.lightmapNum is invalid which doesn't seem right
Render_vertexLighting_DBS_entity( stage );
}
else
{
Render_vertexLighting_DBS_world( stage );
}

The issue is:

If a bsp model has light map, light mapping is enabled the model is rendered with the same code used to render the whole map in all case, which is good.

But if such bsp model is not a world model (for example a func_rotating entity), if light mapping is disabled, such bsp model is rendered with the c++ code and glsl code for the non-bsp models (like player models, weapons…).

So basically we have this:

kind world lm enabled lm disabled
bsp model yes lightmap world lightgrid world
bsp model no lightmap world lightgrid entity
game model no lightgrid entity lightgrid entity

When bsp models are rendered as game models, such unwanted glsl computation may be done, like rim lighting.

Although, we see non-world bsp model are handled fine by both lightmap, lightgrid world and lightgrid entity shaders, meaning there is maybe not a strong need for so much copypaste (see #301 for ongoing merge effort).

To improve the code I would like to have a reliable way to know if a model is a bsp model or not. I don't think it's reliable to detect if surface has lightmap since map may be built without.

To make the bug obvious, I temporarily modified the lightgrid entity glsl shader (vertexLighting_DBS_entity_fp.glsl) to set red channel to full, this to paint in red every surface rendered by this code.

Light map enabled:

map entities as models

Light map disabled:

map entities as models

Light map enabled:

map entities as models

Light map disabled:

map entities as models

Light map enabled:

map entities as models

Light map disabled:

map entities as models

@illwieckz illwieckz changed the title map bsp models are rendered as game models if light mapping is disabled need a reliable way to detect if a model is a bsp model Mar 12, 2020
@illwieckz illwieckz changed the title need a reliable way to detect if a model is a bsp model need a reliable way to detect if a given surface is one of a bsp model Mar 12, 2020
illwieckz added a commit to illwieckz/Daemon that referenced this issue Apr 11, 2020
Make possible to test if a surface comes for a map model,
even if if not world model or there is no lightmap.
illwieckz added a commit that referenced this issue Apr 13, 2020
Make possible to test if a surface comes for a map model,
even if if not world model or there is no lightmap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant