Skip to content

Commit ea9226a

Browse files
committed
Fix flw_hideLightningFlashesOption and update docs
- Add uniforms to glsl api docs - Expand on api concepts
1 parent 0fd1ee7 commit ea9226a

File tree

12 files changed

+194
-8
lines changed

12 files changed

+194
-8
lines changed

common/src/backend/resources/assets/flywheel/flywheel/internal/uniforms/options.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ layout(std140) uniform _FlwOptionsUniforms {
1515
uint flw_textBackgroundForChatOnlyOption;
1616
float flw_darknessPulsingOption;
1717
float flw_damageTiltOption;
18-
uint hideLightningFlashesOption;
18+
uint flw_hideLightningFlashesOption;
1919
};

docs/flywheel/api/concepts.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ client/server synchronization.
2020

2121
## Visuals
2222

23-
Visuals are the analog to Renderers in vanilla Minecraft. Each Entity/BlockEntity/Effect that is rendered will have a
24-
corresponding Visual. This way, Visuals can maintain state independent of the client representation of the game object,
23+
Visuals are the analog to Renderers in vanilla Minecraft. Each game object that is rendered will have a
24+
corresponding Visual object. This way, Visuals can maintain state independent of the client representation of the game
25+
object,
2526
and update in parallel to other Visuals of the same type.
2627

27-
Statefulness and parallelism are the core motivation behind this abstraction.
28+
Statefulness and parallelism are the core motivations behind this abstraction.
29+
30+
::: danger IMPLEMENTATION CONTRACT
31+
Your Visual _must_ be in a correct state upon construction, where all created Instances are be at their expected
32+
position. The most common bug when implementing Visuals is having your instances appear at the render origin.
33+
:::
2834

2935
## Instances
3036

@@ -37,6 +43,11 @@ instance shader.
3743

3844
Users of Flywheel are encouraged to only update Instances when necessary.
3945

46+
::: warning
47+
Ensure you `.delete()` all Instances you create when your Visual is deleted. Failure to do so will result in orphaned
48+
instances that continue to be rendered.
49+
:::
50+
4051
## Render Origin
4152

4253
The render origin is an integer coordinate in world space which serves as the origin for rendering.
@@ -46,3 +57,25 @@ Such an approach is not viable for Flywheel, as that would require every instanc
4657
Flywheel maintains a render origin that is nearby, but not necessarily exactly at, the camera position. As the camera
4758
moves in the level Flywheel will update the render origin once it gets too far away. All instances are deleted and all
4859
visuals are recreated when the render origin updates.
60+
61+
::: tip
62+
To map from world space to render space, subtract the render origin from the world space position. e.g.
63+
64+
```java
65+
BlockPos renderSpacePos = worldSpacePos.subtract(visualizationContext.renderOrigin());
66+
```
67+
68+
:::
69+
70+
## Plans
71+
72+
Plans are Flywheel's way to expose the thread pool to Visuals. Plans are created once, and executed many times.
73+
When executed, Plans receive a generic context object, a reference to the Executor they're running on, and a Runnable
74+
to call when all the work in the Plan is complete. This simple abstraction allows for incredibly complex composition
75+
of tasks and allows for easy parallelization of work.
76+
77+
Implementing `DynamicVisual` and `TickableVisual` requires you to construct Plans that will be executed every frame or
78+
tick, respectively.
79+
80+
_Most_ Visuals will not need the full complexity of Plans, so the Flywheel lib provides `Simple` counterparts to both
81+
interfaces.

docs/flywheel/api/glsl-api.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,24 @@ Some functions/variables are only available for specific shader stages.
1212

1313
::: code-group
1414

15-
<<< snippets/common.glsl
16-
<<< snippets/material.glsl
17-
<<< snippets/vertex.glsl
18-
<<< snippets/fragment.glsl
15+
<<< stage/common.glsl
16+
<<< stage/material.glsl
17+
<<< stage/vertex.glsl
18+
<<< stage/fragment.glsl
19+
20+
:::
21+
22+
### Uniforms
23+
24+
In addition to the stage-specific variables above, every stage has access to the following uniforms.
25+
All uniforms are included in the prelude and do not have to be manually included.
26+
27+
::: code-group
28+
29+
<<< uniforms/fog.glsl
30+
<<< uniforms/frame.glsl
31+
<<< uniforms/level.glsl
32+
<<< uniforms/options.glsl
33+
<<< uniforms/player.glsl
1934

2035
:::
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vec4 flw_fogColor;
2+
vec2 flw_fogRange;
3+
int flw_fogShape;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
struct FrustumPlanes {
2+
vec4 xyX;// <nx.x, px.x, ny.x, py.x>
3+
vec4 xyY;// <nx.y, px.y, ny.y, py.y>
4+
vec4 xyZ;// <nx.z, px.z, ny.z, py.z>
5+
vec4 xyW;// <nx.w, px.w, ny.w, py.w>
6+
vec2 zX;// <nz.x, pz.x>
7+
vec2 zY;// <nz.y, pz.y>
8+
vec2 zZ;// <nz.z, pz.z>
9+
vec2 zW;// <nz.w, pz.w>
10+
};
11+
12+
FrustumPlanes flw_frustumPlanes;
13+
14+
mat4 flw_view;
15+
mat4 flw_viewInverse;
16+
mat4 flw_viewPrev;
17+
mat4 flw_projection;
18+
mat4 flw_projectionInverse;
19+
mat4 flw_projectionPrev;
20+
mat4 flw_viewProjection;
21+
mat4 flw_viewProjectionInverse;
22+
mat4 flw_viewProjectionPrev;
23+
24+
ivec3 flw_renderOrigin;
25+
vec3 flw_cameraPos;
26+
vec3 flw_cameraPosPrev;
27+
vec3 flw_cameraLook;
28+
vec3 flw_cameraLookPrev;
29+
vec2 flw_cameraRot;
30+
vec2 flw_cameraRotPrev;
31+
32+
vec2 flw_viewportSize;
33+
float flw_aspectRatio;
34+
float flw_defaultLineWidth;
35+
float flw_viewDistance;
36+
37+
uint flw_ticks;
38+
float flw_partialTick;
39+
float flw_renderTicks;
40+
float flw_renderSeconds;
41+
float flw_systemSeconds;
42+
uint flw_systemMillis;
43+
44+
/** 0 means no fluid. Use FLW_CAMERA_IN_FLUID_* defines to detect fluid type. */
45+
uint flw_cameraInFluid;
46+
/** 0 means no block. Use FLW_CAMERA_IN_BLOCK_* defines to detect block type. */
47+
uint flw_cameraInBlock;
48+
49+
uint FLW_CAMERA_IN_FLUID_WATER;
50+
uint FLW_CAMERA_IN_FLUID_LAVA;
51+
uint FLW_CAMERA_IN_FLUID_UNKNOWN;
52+
53+
uint FLW_CAMERA_IN_BLOCK_POWDER_SNOW;
54+
uint FLW_CAMERA_IN_BLOCK_UNKNOWN;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
vec4 flw_skyColor;
2+
vec4 flw_cloudColor;
3+
4+
vec3 flw_light0Direction;
5+
vec3 flw_light1Direction;
6+
7+
/** The current day number of the level. */
8+
uint flw_levelDay;
9+
/** The current fraction of the current day that has elapsed. */
10+
float flw_timeOfDay;
11+
12+
uint flw_levelHasSkyLight;
13+
14+
float flw_sunAngle;
15+
16+
float flw_moonBrightness;
17+
/** There are normally only 8 moon phases. */
18+
uint flw_moonPhase;
19+
20+
uint flw_isRaining;
21+
float flw_rainLevel;
22+
uint flw_isThundering;
23+
float flw_thunderLevel;
24+
25+
float flw_skyDarken;
26+
27+
uint flw_constantAmbientLight;
28+
29+
/** Use FLW_DIMENSION_* ids to determine the dimension. May eventually be implemented for custom dimensions. */
30+
uint flw_dimension;
31+
32+
uint FLW_DIMENSION_OVERWORLD;
33+
uint FLW_DIMENSION_NETHER;
34+
uint FLW_DIMENSION_END;
35+
uint FLW_DIMENSION_UNKNOWN;

0 commit comments

Comments
 (0)