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

Multiply with var_Color in lightMapping after u_AlphaThreshold check #1417

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

VReaperV
Copy link
Contributor

@VReaperV VReaperV commented Nov 4, 2024

Fixes an issue creating a void effect, where vertex + color/diffuse map produces different results in depth pre-pass generic and lightMapping shaders, due to different check/multiplication order.

Fixes #119. I've also tried moving the multiplication before the check in generic shader, but it ended up making surfaces disappear based on distance to them.

Fixes an issue creating a void effect, where vertex + color/diffuse map produces different results in depth pre-pass `generic` and `lightMapping` shaders, due to different check/multiplication order.
@slipher
Copy link
Member

slipher commented Nov 4, 2024

So what is "alphagen vertex" used for?

Also why does q3map2 even write values other than 1 to the alpha of the vertex color? Seems weird

@VReaperV
Copy link
Contributor Author

VReaperV commented Nov 4, 2024

I suppose it's still used for blending.

@illwieckz
Copy link
Member

illwieckz commented Nov 6, 2024

Also why does q3map2 even write values other than 1 to the alpha of the vertex color? Seems weird

It is used for terrain blending, for example in a single shader you have a rock and a sand stage, and one of the stage receives its alpha channel from the vertex, this makes possible to blend two terrains per surface.

@VReaperV
Copy link
Contributor Author

VReaperV commented Nov 6, 2024

Also why does q3map2 even write values other than 1 to the alpha of the vertex color? Seems weird

It is used for terrain blending, for example in a single shader you have a rock and a sand stage, and one of the stage receives its alpha channel from the vertex, this makes possible to blend two terrains per surface.

Do we have an example of such a shader?

@illwieckz
Copy link
Member

illwieckz commented Nov 6, 2024

The garden in station15 (grass/mud), the outdoor of thunder (rock/sand).

@illwieckz
Copy link
Member

It modifies the way the grass/mud floor is rendered in the garden:

Before:

unvanquished_2024-11-07_173346_000

After:

unvanquished_2024-11-07_173429_000

Now it's possible that is the map that is wrong. I had to edit it to workaround a q3map2 bug, but I remember I struggled to get the effect in the first screenshot, as I didn't seen much correlation between what I did in editor and the result I was getting.

@illwieckz
Copy link
Member

This is how it looks in editor:

20241107-175445-000 netradiant-unvanquished-station15

There is no place where the grass is 0% (mud 100%).

So maybe this branch is right and the map source is wrong.

@illwieckz
Copy link
Member

If I set some 0%, I see the grass surfacing where it is 0%:

20241107-180301-000 netradiant-unvanquished-station15
unvanquished_2024-11-07_180708_000

@illwieckz
Copy link
Member

illwieckz commented Nov 7, 2024

If I add more grass (less mud):

20241107-181951-000 netradiant-unvanquished-station15

I get more grass:

unvanquished_2024-11-07_182334_000

With this branch, what I do in editor is what I get in game.

illwieckz
illwieckz previously approved these changes Nov 7, 2024
Copy link
Member

@illwieckz illwieckz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@slipher
Copy link
Member

slipher commented Nov 8, 2024

There was a discussion in IRC in which SomaZ said that actually the generic shader is the "correct" one, in terms of matching q3 behavior.

Copy link

@SomaZ SomaZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing vertex alpha multiplication to be performed after the alpha discard is wrong (in terms of compatibility). Changing it to be performed before the discard in the other shaders like the generic shader would be the correct fix in terms of compatibility. This should also fix the incorrect void effect illwieckz encountered on station15 with the trees.

@VReaperV
Copy link
Contributor Author

VReaperV commented Nov 8, 2024

There was a discussion in IRC in which SomaZ said that actually the generic shader is the "correct" one, in terms of matching q3 behavior.

The generic shader actually does multiplication after discard.

@VReaperV
Copy link
Contributor Author

VReaperV commented Nov 8, 2024

Changing vertex alpha multiplication to be performed after the alpha discard is wrong (in terms of compatibility). Changing it to be performed before the discard in the other shaders like the generic shader would be the correct fix in terms of compatibility. This should also fix the incorrect void effect illwieckz encountered on station15 with the trees.

I tried that, and the small plants on the ground in station15 in the same area started disappearing based on distance. Although perhaps that is another map bug that was trying to workaround an engine issue.

@slipher
Copy link
Member

slipher commented Nov 8, 2024

I tried that, and the small plants on the ground in station15 in the same area started disappearing based on distance. Although perhaps that is another map bug that was trying to workaround an engine issue.

Probably it's the same issue as the trees, with the alpha volumes, which are intended to affect only the ground, doing collateral damage to the plant models? If there are a lot of bad alpha volumes, maybe it would be easier to put alphaGen identity in the plant shaders rather than moving all of them.

Changes like this which break the current version of our assets can be targeted to the for-0.56.0/sync branch.

@illwieckz
Copy link
Member

illwieckz commented Nov 8, 2024

Actually multiplying before testing makes sense if one wants to combine alphaGen vertex with alphaFunc GE128, which is what does the textures/station15_custom/ter_mudmoss1 shader.

This may look weird, but it allows to do alpha blending with a strong cutoff: instead of linearly blending from moss to mud, only values above 50% makes mud appear, and everything elle displays full moss.

The fact I didn't felt something was meaningful between what was done in the editor and what was gotten in game was because I did not notice that cut-off. Now that I know about it, what I get in game is what I do in editor while taking such cut-off in consideration (only using alpha brushes higher than 50%).

@illwieckz
Copy link
Member

I tried that, and the small plants on the ground in station15 in the same area started disappearing based on distance. Although perhaps that is another map bug that was trying to workaround an engine issue.

Probably it's the same issue as the trees, with the alpha volumes, which are intended to affect only the ground, doing collateral damage to the plant models.

Yes, it's likely the same problem, as we see on above screenshot some plants are in some alpha volumes. It can be worked around by having smaller alpha volume that only hits the brushes intersections to mark them. Doing a large alpha brush is just a lazy way to mark all brushes intersections from a whole area.

Also for the tree, the alpha brush can just be made less high, but that would not work for plants.

Actually I'm happy we start grasping what's going on after all those years.

@illwieckz illwieckz dismissed their stale review November 8, 2024 11:08

This now looks wrong.

@VReaperV
Copy link
Contributor Author

VReaperV commented Nov 9, 2024

I've added a commit that reverts the change to lightMapping and changes the generic shader instead, but now the plant isn't rendered. Maybe you could look at thr map if it's a map bug.

@slipher
Copy link
Member

slipher commented Nov 10, 2024

LGTM for putting on the 0.56 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

partial void effect on station15 tree model
4 participants