Shaderboard
Shaderboard 允许原版资源包后处理光影通过 命名绑定(named bindings) 读取客户端记分板数值。
绑定在光影的 JSON 文件(即定义其 Passes 的文件)中声明。该模组会将每个绑定转换为一个真正的 GLSL uniform block 并附带 GPU 缓冲区,并在每一帧用实时的记分板数值重写这些缓冲区。随后,光影可以按需使用这些数值。
注意: 此模组适用于原版的 /posteffect 命令光影。它不针对 Iris 和 Optifine 等模组的光影。
声明绑定
在 后处理 JSON 文件的根层级添加 "shaderboard:bindings" 数组,位于 "targets" 和 "passes" 旁边。以下是一个示例:
{
"targets": { ... },
"passes": [ ... ],
"shaderboard:bindings":
[
{
"uniform_name": "u_SteveScore",
"type": "shaderboard:scoreboard_objective",
"objective": "example_1",
"target": { "type": "player", "name": "Steve" }
}
]
}
参数说明:
uniform_name - 绑定所创建的 GLSL uniform block 的名称。
type - 绑定类型。即绑定暴露的信息类型。
当 type 为 shaderboard:scoreboard_objective:
objective - 记分板目标名称。
target - 定义要绑定哪个目标的分值。
type - 要绑定的目标类型;本地玩家的分值(local_player)、特定玩家的分值(player)、最高分值(top_player),或固定大小的分值数组(array)。
name - 当 type 为 player 时,此附加字段定义“哪位玩家”。
注意: 这仅仅是众多可能性中的一个示例;从传递分值数组到传递其他客户端信息等等。请参阅 wiki 以获取更多信息。
在 GLSL 中读取绑定的值
重要: 记分板分值是服务端的数据,默认情况下不会同步给客户端。为解决此问题,请使用以下两种解决方案之一:
/scoreboard objectives setdisplay ... - 使原版游戏通过将目标在屏幕上视觉显示来将目标的数值同步给客户端。
/scoreboard objectives shaderboard:sync ... (v2.4.0+) - 此模组在后端同步目标数值给客户端的方法,无需使用 setdisplay。需要在服务端安装此模组。
每个绑定的 uniform_name 都会成为一个 layout(std140) uniform block。其内容由绑定的 值类型 定义。标量记分板目标会产生单个 int:
layout(std140) uniform u_TopScore { int topScore; };
layout(std140) uniform u_SortedScoresAZ { int sortedScores[16]; };
void main()
{
//基础输出颜色
fragColor = texture(InSampler, texCoord);
//...在此处随意使用 'topScore' 和 'sortedScores'...
}
快速演示
此模组包含一个 ID 为 shaderboard:example_1 的示例 /posteffect。您可以按顺序使用以下命令进行尝试:
/posteffect add @p shaderboard:example_1
/scoreboard objectives add example_1 dummy "Example 1"
/scoreboard objectives setdisplay sidebar example_1
/scoreboard players set @p example_1 123
/scoreboard players set Steve example_1 456
此示例光影从 example_1 目标读取记分板数值,并以二进制条纹的形式渲染在屏幕上。
Shaderboard
Shaderboard lets vanilla resource-pack post-effect shaders read client-side scoreboard values through named bindings.
A binding is declared inside a post-effect's JSON file (the same file that defines its passes). This mod turns each binding into a real GLSL uniform block with a GPU buffer, and rewrites those buffers with live scoreboard values every frame. Shaders can then use those values however they like.
Note: This mod is for vanilla /posteffect command shaders. It does not target shaders from mods like Iris and Optifine.
Declaring bindings
Add a "shaderboard:bindings" array at the root of a post-effect JSON, next to "targets" and "passes". Here is an example:
{
"targets": { ... },
"passes": [ ... ],
"shaderboard:bindings":
[
{
"uniform_name": "u_SteveScore",
"type": "shaderboard:scoreboard_objective",
"objective": "example_1",
"target": { "type": "player", "name": "Steve" }
}
]
}
Where:
uniform_name - Name of the GLSL uniform block a binding creates.
type - Binding type. I.e. the type of information a binding exposes.
When type is shaderboard:scoreboard_objective:
objective - Scoreboard objective name.
target - Defines which score of an objective to bind.
type - The type of target to bind to; local player's score (local_player), a specific player's score (player), the top score (top_player), or a fixed-size array of scores (array).
name - When type is player, this additional field defines "which player".
Note: This is just one example of many possibilitis; from passing arrays of scores to passing other client-sided information, etc etc. Please refer to the wiki for more information.
Reading a binding's value in GLSL
Important: Scoreboard scores are server-sided and by default do not synchronize with clients. To resolve this, use one of the two following solutions:
/scoreboard objectives setdisplay ... - Makes the vanilla game synchronize an objective's values with the client by visually displaying it on-screen.
/scoreboard objectives shaderboard:sync ... (v2.4.0+) - This mod's way of synchronizing objective values with clients in the background, without needing setdisplay. Requires installing this mod on the server-side.
Each binding's uniform_name becomes a layout(std140) uniform block. Its contents are defined by the binding's value type. Scalar scoreboard targets produce a single int:
layout(std140) uniform u_TopScore { int topScore; };
layout(std140) uniform u_SortedScoresAZ { int sortedScores[16]; };
void main()
{
//base output color
fragColor = texture(InSampler, texCoord);
//...use 'topScore' and 'sortedScores' however you'd like here...
}
Quick demo
This mod includes an example /posteffect of ID shaderboard:example_1. You may try it out using the following commands in order:
/posteffect add @p shaderboard:example_1
/scoreboard objectives add example_1 dummy "Example 1"
/scoreboard objectives setdisplay sidebar example_1
/scoreboard players set @p example_1 123
/scoreboard players set Steve example_1 456
This example shader reads scoreboard values from the example_1 objective and renders them on-screen as binary stripes.
评论 0
登录后参与评分
还没有评论,来抢沙发吧