着色板

着色板

一个Minecraft模组,通过命名绑定将客户端计分板数值暴露给后处理效果着色器。

Shaderboard

Shaderboard 让原版资源包后处理着色器能够通过命名绑定读取客户端侧记分板数值。

绑定在后处理的 JSON 文件(即定义其渲染通道的同一文件)中声明。本模组将每个绑定转换为带有 GPU 缓冲区的真实 GLSL uniform 块,并在每一帧用实时记分板数值重写这些缓冲区。着色器随后可以任意使用这些数值。

注意: 本模组适用于原版 /posteffect 命令着色器。它不适用于 Iris 和 Optifine 等模组的着色器。


声明绑定

在后处理 JSON 的根层级,与 "targets" 和 "passes" 并列添加一个 "shaderboard:bindings" 数组。示例如下:

{
	"targets": { ... },
	"passes": [ ... ],

	"shaderboard:bindings":
	[
		{
			"uniform_name": "u_TopScore",
			"type": "shaderboard:scoreboard_objective",
			"objective": "example_1",
			"target": { "type": "top_player" }
		},
		{
			"uniform_name": "u_MyScore",
			"type": "shaderboard:scoreboard_objective",
			"objective": "example_1",
			"target": { "type": "local_player" }
		},
		{
			"uniform_name": "u_SteveScore",
			"type": "shaderboard:scoreboard_objective",
			"objective": "example_1",
			"target": { "type": "player", "name": "Steve" }
		}
	]
}

字段说明:

  • uniform_name - 绑定所创建的 GLSL uniform 块的名称。
  • type - 绑定类型,即绑定所暴露的信息类型。

当 type 为 shaderboard:scoreboard_objective 时:

  • objective - 记分板目标名称。
  • target - 定义绑定目标的哪个分数。
    • type - 绑定的目标类型。本地玩家的分数(local_player)、特定玩家的分数(player),或最高玩家的分数(top_player)。
    • name - 当 type 为 player 时,此附加字段定义“哪个玩家”。

在 GLSL 中读取绑定值

每个绑定的 uniform_name 会变成一个 layout(std140) uniform 块,数值以 float 形式传入:

layout(std140) uniform u_TopScore { float topScore; };

void main()
{
	//base output color
	fragColor = texture(InSampler, texCoord);

	//...use 'topScore' however you'd like here...
}

快速演示

本模组包含一个 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 目标读取记分板数值,并将其以二进制条纹的形式渲染到屏幕上。