Conversation
|
This is extracted from the time-of-day / weather prototype #1913 |
|
Play this branch at https://play.threadbare.game/branches/endlessm/reinstate-clouds-shadow. (This launches the game from the start, not directly at the change(s) in this pull request.) |
Replace the clouds overlay effect with a new implementation. See node editor descriptions or script comments for implementation details.
e82c4ff to
db79216
Compare
scenes/game_elements/fx/clouds_shadow/components/clouds_shadow.gdshader
Outdated
Show resolved
Hide resolved
| @tool | ||
| extends Parallax2D | ||
|
|
||
| @export_tool_button("Random Clouds") var randomize_button: Callable = randomize |
There was a problem hiding this comment.
I don't quite follow how this button is supposed to be used.
Suppose that I have res://scenes/world_map/frays_end.tscn open in my editor. If I click this button, the clouds in the editor change, but when I run the scene they are back to the seed=0 clouds.
However, if I have both res://scenes/world_map/frays_end.tscn and res://scenes/game_elements/fx/clouds_shadow/clouds_shadow.tscn open. Then:
- Switch to the frays end tab
- Click Random Clouds
- Save Fray's End - no change on disk
- Switch back to the
clouds_shadow.tscnscene; observe that the clouds have changed to match Fray's End - Save that scene; observe that the seed has been persisted here.
If I set all of the ShaderMaterial, NoiseTexture2D and FastNoiseLite as resource_local_to_scene = true (I don't understand why all three have to be) then this doesn't happen: changing the seed in Fray's End does not persist. But then it does nothing in the editor.
I think it's fine either way - the worst that happens is that the random clouds are inadvertently changed occasionally - but maybe we want to do the NOTIFICATION_EDITOR_PRE_SAVE trick in clouds_shadow.gd to reset the seed? Or we can just leave it.
There was a problem hiding this comment.
Good catch, since in my prototype branch I was calling to the randomize() function directly, and testing the button only in the clouds_shadow.tscn scene, I didn't notice. I guess there is no other way than exporting a proxy "seed" property and then the noise resource is set to this value.
scenes/game_elements/fx/clouds_shadow/components/clouds_shadow.gdshader
Outdated
Show resolved
Hide resolved
| editor_description = "Start with a small noise texture that is then upscaled to a square. The size of this ColorRect. | ||
|
|
||
| The texture width is about 2/3 of its height to look flattened, matching the game perspective. This way the shadow seems to be projected on the ground. | ||
| " |
There was a problem hiding this comment.
I like this use of editor description!
….gdshader Co-authored-by: Will Thompson <wjt@endlessaccess.org>
….gdshader Co-authored-by: Will Thompson <wjt@endlessaccess.org>
|
|
||
| // Apply contrast to define the shadow silhouette. | ||
| // The result may be outside of the 0-1 range. | ||
| shadow = shadow * contrast + 0.5; |
There was a problem hiding this comment.
@wjt very good point, I was keeping the contrast operation separate so I can comment it out, but is better to simplify and not add 0.5 and then immediately substract it. My reference for the contrast operation was https://github.com/patriciogonzalezvivo/lygia/blob/main/color/contrast.glsl
There was a problem hiding this comment.
Ah OK! Sorry, If you think it's better as it was, that's fine. That reference is useful.
There was a problem hiding this comment.
Not at all, shader code should be optimized. The same happens when doing brightness + contrast operation, is preferred to do them both at once https://github.com/patriciogonzalezvivo/lygia/blob/main/color/brightnessContrast.glsl
There was a problem hiding this comment.
TBH I'm sure the shader compiler is smart enough to optimise out the + 0.5 - 0.5; I was more concerned about the shader interpreter in my mind :)

Replace the clouds overlay effect with a new implementation, and reinstate it in Fray's End.
See node editor descriptions or script comments for implementation details.
Fix #380