MaterialBinTool
MCBE RenderDragon着色器提取工具
简介
一个从RenderDragon的.material.bin文件中提取着色器的工具
还不支持把着色器重新打包回.material.bin文件所以暂时没啥用
使用
- 安装Java8或更高版本
- 解压出apk中的assets/renderer/materials目录
java -jar MaterialBinTool-0.2.0-all.jar 解压出的materials目录的路径
MCBE RenderDragon着色器提取工具
一个从RenderDragon的.material.bin文件中提取着色器的工具
还不支持把着色器重新打包回.material.bin文件所以暂时没啥用
java -jar MaterialBinTool-0.2.0-all.jar 解压出的materials目录的路径
Shader Code部分
public void readFrom(ByteBuf buf) {
type = ByteBufUtil.readString(buf);
platform = ByteBufUtil.readString(buf);
//与enum中的序号对应
typeId = buf.readByte();
platformId = buf.readByte();
short shaderInputCount = buf.readShortLE();
shaderInputList = new ArrayList<>(shaderInputCount);
for (int i = 0; i < shaderInputCount; ++i) {
ShaderInput shaderInput = new ShaderInput();
shaderInput.readFrom(buf);
shaderInputList.add(shaderInput);
}
unknownBytes0 = ByteBufUtil.readBytes(buf, 8);
//这里提取出来的是经过bgfx的shaderc编译后的着色器
code = ByteBufUtil.readByteArray(buf);
}
对应的枚举类
enum ShaderCodeType {
Vertex,
Fragment,
Compute,
Unknown
}
enum ShaderCodePlatform {
Direct3D_SM40,
Direct3D_SM50,
Direct3D_SM60,
Direct3D_SM65,
Direct3D_XB1,
Direct3D_XBX,
GLSL_120,
GLSL_430,
ESSL_100,
ESSL_300,
ESSL_310,
Metal,
Vulkan,
Nvn,
Pssl,
}
ShaderInput中的unknownByte0,unknownByte1估计是表示的是哪个attribute,但用的不是它们在枚举中的索引 bgfx的shaderc_hlsl.cpp中有这段
static const RemapInputSemantic s_remapInputSemantic[bgfx::Attrib::Count + 1] =
{
{ bgfx::Attrib::Position, "POSITION", 0 },
{ bgfx::Attrib::Normal, "NORMAL", 0 },
{ bgfx::Attrib::Tangent, "TANGENT", 0 },
{ bgfx::Attrib::Bitangent, "BITANGENT", 0 },
{ bgfx::Attrib::Color0, "COLOR", 0 },
{ bgfx::Attrib::Color1, "COLOR", 1 },
{ bgfx::Attrib::Color2, "COLOR", 2 },
{ bgfx::Attrib::Color3, "COLOR", 3 },
{ bgfx::Attrib::Indices, "BLENDINDICES", 0 },
{ bgfx::Attrib::Weight, "BLENDWEIGHT", 0 },
{ bgfx::Attrib::TexCoord0, "TEXCOORD", 0 },
{ bgfx::Attrib::TexCoord1, "TEXCOORD", 1 },
{ bgfx::Attrib::TexCoord2, "TEXCOORD", 2 },
{ bgfx::Attrib::TexCoord3, "TEXCOORD", 3 },
{ bgfx::Attrib::TexCoord4, "TEXCOORD", 4 },
{ bgfx::Attrib::TexCoord5, "TEXCOORD", 5 },
{ bgfx::Attrib::TexCoord6, "TEXCOORD", 6 },
{ bgfx::Attrib::TexCoord7, "TEXCOORD", 7 },
{ bgfx::Attrib::Count, "", 0 },
};
猜测这两个字节应该是这样对应attribute的,试了一下应该没有例外情况
enum class Attribute(val index: Byte, val subIndex: Byte) {
Position(0, 0),
Normal(1, 0),
Tangent(2, 0),
Bitangent(3, 0),
Color0(4, 0),
Color1(4, 1),
Color2(4, 2),
Color3(4, 3),
Indices(5, 0),
Weights(6, 0),
TexCoord0(7, 0),
TexCoord1(7, 1),
TexCoord2(7, 2),
TexCoord3(7, 3),
TexCoord4(7, 4),
TexCoord5(7, 5),
TexCoord6(7, 6),
TexCoord7(7, 7),
//bgfx中没有8,但是反汇编.so和解包的时候都有8
TexCoord8(7, 8),
}
unknownBool1大概是表明是否是InstanceData,bgfx启用Instancing时,传i_data0之类的attribute与一般的attribute不一样,有一个专门的InstanceDataBuffer什么的,并且确实只有InstanceData这个值是true 这些都是写在varying.def.sc中的,还有后面的precision和interpolation限定符也写在这里面。 但这里面貌似不能写宏定义什么的,所以所有的variant的ShaderInput都一模一样,即便某些input在部分variant代码中根本没有出现。并且hash值也是通过这个文件计算的,这就使得虽然各个variant的varying变量并不完全相同,但所有variant着色器的hash一模一样,
A new readme file has been created that's translated from the original Chinese versions. Both READMEs include a link to each other. This should make the project easier to understand for the English speakers like myself. Note: It was mostly translated automatically, but I made sure that the translations made sense, and stayed accurate to the project's functions.
According to the README file, the following would be added to defines.json
.
"flagModes": {
"SourceInputType0": {
"Constant": [],
"Sampled": ["SOURCE_INPUT_0_SAMPLED"]
},
"SourceInputType1": {
"Constant": [],
"Sampled": ["SOURCE_INPUT_1_SAMPLED"]
},
"SourceInputType2": {
"Constant": [],
"Sampled": ["SOURCE_INPUT_2_SAMPLED"]
}
}
However, the program does not properly read it. Instead, it would read something like this.
"flagModes": {
"SourceInputType0": ["SOURCE_INPUT_0_SAMPLED"],
"SourceInputType1": ["SOURCE_INPUT_1_SAMPLED"],
"SourceInputType2": ["SOURCE_INPUT_2_SAMPLED"]
}
This pull request fixes that.
Whenever I attempt to use a uniform in the fragment shader, it acts as if all its values are zero (never set).
After digging into the Direct3D shader assembly, I notice that the one Minecraft has uses CB1 constant buffer in the fragment shader (dcl_constantbuffer CB1[1], immediateIndexed
), while the one made when compiling uses CB0 (dcl_constantbuffer CB0[2], immediateIndexed
). This same constant buffer is used in the Vertex shaders. Maybe that has something to do with it?
shaderc.exe
可在Release v0.5.0中下载