Skip to content

How to make PBR Materials working with OptiFine

Protoxy edited this page Nov 21, 2022 · 2 revisions

This is for everyone. Modder that used PBR materials and Normal map for glTF models, should inform their users to watch this tutorial.

Download and Install OptiFine

https://optifine.net/downloads

Double click downloaded OptiFine .jar file to extract OptiFine Mod into mods folder.

optifine extract

For Fabric users, please also download and install OptiFabric.

https://www.curseforge.com/minecraft/mc-mods/optifabric

Run Minecraft and close it to make shaderpacks folder exist in your Game Dir.

Choose one of the shaderpack list below, and put downloaded shaderpack into shaderpacks folder.

BSL Shaders

https://bitslablab.com/bslshaders/

Preview

Most BSL based shaderpack will work properly with MCglTF.

https://bitslablab.com/bslshaders/#extras

Patch entity.properties

In this section, you need to use the Zip Archiver you familiar to fix entity.properties.

entity.properties is located at shaders of shaderpack zip file.

Extract entity.properties for editing as describe below with the desired text editor you prefered, and then put it back into the shaderpack zip file once finish.

Find this line

entity.10100=minecraft:item_frame minecraft:painting minecraft:glow_item_frame

Remove minecraft:item_frame and minecraft:glow_item_frame

entity.10100=minecraft:painting

What this patch done is preventing normal mapped model in the Item Frame have weird lighting result after Minecraft version 1.12.2.

Patch materialGbuffers.glsl

This issue had been fix since BSL v8.2. You don't need to apply this patch anymore.

In this section, you need to use the Zip Archiver you familiar to fix materialGbuffers.glsl.

materialGbuffers.glsl is located at shaders/lib/surface/ of shaderpack zip file.

Extract materialGbuffers.glsl for editing as describe below with the desired text editor you prefered, and then put it back into the shaderpack zip file once finish.

Replace this line

vec4 specularMap = texture2DGradARB(specular, newCoord, dcdx, dcdy);

With these line

#ifdef PARALLAX
vec4 specularMap = texture2DGradARB(specular, newCoord, dcdx, dcdy);
#else
vec4 specularMap = texture2D(specular, texCoord);
#endif

Replace this line

normalMap = texture2DGradARB(normals, newCoord, dcdx, dcdy).xyz * 2.0 - 1.0;

With these line

#ifdef PARALLAX
normalMap = texture2DGradARB(normals, newCoord, dcdx, dcdy).xyz * 2.0 - 1.0;
#else
normalMap = texture2D(normals, texCoord).xyz * 2.0 - 1.0;
#endif

Replace these line

ao = texture2DGradARB(normals, newCoord, dcdx, dcdy).z;

normalMap = vec3(texture2DGradARB(normals, newCoord, dcdx, dcdy).xy, 0.0) * 2.0 - 1.0;

With these line

#ifdef PARALLAX
ao = texture2DGradARB(normals, newCoord, dcdx, dcdy).z;

normalMap = vec3(texture2DGradARB(normals, newCoord, dcdx, dcdy).xy, 0.0) * 2.0 - 1.0;
#else
ao = texture2D(normals, texCoord).z;

normalMap = vec3(texture2D(normals, texCoord).xy, 0.0) * 2.0 - 1.0;
#endif

What this patch done is preventing Normal Map and Specular Map got shifted and stretched even when Parallax Occlusion Mapping is turn off.

Shader Setting

In Minecraft Options/Video Settings/Shaders, select the BSL shader pack and then click Shader Options.

Shaders

In Shader Options/Material, turn on Advanced Materials and make sure the Material Format match the mod that dependent on MCglTF you used. (In most case SEUS/Old PBR)

Material

Optionally in Normals & Parallax, if you don't like Normal Map effect fade out when looking downward in first person, you can turn off Normal Dampening.

Normal Dampening

Now it is done. Enjoy the 3D models which provided by your Mod author that looked like it was coming from 3A Game.

AstraLex Shaders (BSL Edit)

https://lextermina7.wixsite.com/astralex

Preview

Patch gbuffers_entities.glsl

This patch is applied to the AstraLex Shaders v51.0 and above, similar to the issue that had been described above.

In this section, you need to use the Zip Archiver you familiar to fix gbuffers_entities.glsl.

gbuffers_entities.glsl is located at shaders/program/ of shaderpack zip file.

Extract gbuffers_entities.glsl for editing as describe below with the desired text editor you prefered, and then put it back into the shaderpack zip file once finish.

Find this line

float skipAdvMat  =float(entityId == 10100 || entityId == 10002 || entityId == 10312 || entityId == 10315);

Remove || entityId == 10312

float skipAdvMat  =float(entityId == 10100 || entityId == 10002 || entityId == 10315);

What this patch done is preventing normal mapped model in the Item Frame have weird lighting result after Minecraft version 1.12.2.

Shader Setting

In Minecraft Options/Video Settings/Shaders, select the AstraLex Shaders pack and then click Shader Options.

Shaders

In Shader Options/Advanced Materials, make sure Advanced Materials is on and the Material Format match the mod that dependent on MCglTF you used. (In most case Seus PBR (Old PBR))

Material

Then navigate into Reflections, turn on Specular Reflection and Rough Reflection.

Specular Reflections Rough Reflections

Optionally in Shader Options/Advanced Materials, if you don't like Normal Map effect fade out when looking downward in first person, you can turn off Normal Dampening.

Normal Dampening

Now it is done. Enjoy the 3D models which provided by your Mod author that looked like it was coming from 3A Game.

Complementary Shaders

https://www.complementary.dev/shaders-v4/

Preview

Shader Setting

In Minecraft Options/Video Settings/Shaders, select the Complementary Shaders pack and then click Shader Options.

Shaders

In Shader Options, change RP Support to either labPBR (RP Required) or SEUS PBR (RP Required) based on the mod that dependent on MCglTF you used. (In most case SEUS PBR (RP Required))

Material

Now it is done. Enjoy the 3D models which provided by your Mod author that looked like it was coming from 3A Game.

DrDestens MinecraftShaders

https://www.curseforge.com/minecraft/customization/drdestens-minecraftshaders

Preview

This shaderpack dose not take the sky for reflection, so the PBR effect is a little bit off.

Patch vertex_transform.glsl and vertex_transform_simple.glsl

This patch is based on DrDestens MinecraftShaders v1.5.6, it has been confirm by DrDestens and may be fixed in the future.

In this section, you need to use the Zip Archiver you familiar to fix vertex_transform.glsl and vertex_transform_simple.glsl.

vertex_transform.glsl and vertex_transform_simple.glsl are located at shaders/lib/ of shaderpack zip file.

Extract vertex_transform.glsl and vertex_transform_simple.glsl for editing as describe below with the desired text editor you prefered, and then put it back into the shaderpack zip file once finish.

Replace these line

mat3 getTBN(vec4 tangentAttribute) {
	vec3 normal  = normalize(gl_NormalMatrix * gl_Normal);
	vec3 tangent = normalize(gl_NormalMatrix * (tangentAttribute.xyz / tangentAttribute.w));
	return mat3(tangent, cross(tangent, normal), normal);
}

With these line

mat3 getTBN(vec4 tangentAttribute) {
	vec3 normal  = normalize(gl_NormalMatrix * gl_Normal);
	vec3 tangent = normalize(gl_NormalMatrix * tangentAttribute.xyz);
	vec3 binormal = normalize(gl_NormalMatrix * cross(tangentAttribute.xyz, gl_Normal.xyz) * tangentAttribute.w);
	return mat3(tangent, binormal, normal);
}

What this patch done is to get a correct lighting result on normal mapped model.

Shader Setting

In Minecraft Options/Video Settings/Shaders, select the DrDestens MinecraftShaders pack and then click Shader Options.

Shaders

In Shader Options/Physically Based Rendering, turn on PBR and make sure the PBR Format match the mod that dependent on MCglTF you used. (In most case SEUS/Old PBR)

PBR PBR Format

Turn off Normal Mapping Fix, otherwise you will get weird lighting result of normal mapped Item model in Item Frame.

Normal Mapping Fix

Optionally, you can set PBR Blend higher to gain more reflection on the surface.

PBR Blend

Now it is done. Despite the result is not as perfect as BSL based shader, but you can run PBR Material smoothly on low end computer.