MCglTF

MCglTF

598k Downloads

[1.20.4-Fabric] All textures of other entities turn to white when a gltf entity is caught on the frustum

singlerr opened this issue · 8 comments

commented

As I mentioned at here, displayed colors(or textures) of entities become white if the frustum of client catches a gltf model entity. See below:

Image

I had researched about this issue little bit and found that RenderedModel#COLOR_MAP_INDEX,RenderedModel#NORMAL_MAP_INDEX,RenderedModel#SPECULAR_MAP_INDEX and RenderedModel#mc_midTexcoord, RenderedModel#at_tangent mismatches with Iris Shaders.

For example, at RenderedGltfModel

	static {
		if(FabricLoader.getInstance().isModLoaded("iris")) {
			mc_midTexCoord = 7; // but iris accepts only 12!
			at_tangent = 8; // but iris accepts only 13!

As IrisRenderingHook#setupAndRender utilizes variables above, I suspect this function has key of the issue.

		if(normals != -1) {
				RenderedGltfModel.NORMAL_MAP_INDEX = GL13.GL_TEXTURE2 + GL20.glGetUniformi(currentProgram, normals);
				if(specular != -1) {
					RenderedGltfModel.SPECULAR_MAP_INDEX = GL13.GL_TEXTURE1 + GL20.glGetUniformi(currentProgram, specular);
					
					GL13.glActiveTexture(RenderedGltfModel.NORMAL_MAP_INDEX);
					int currentTextureNormal = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					GL13.glActiveTexture(RenderedGltfModel.SPECULAR_MAP_INDEX);
					int currentTextureSpecular = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					GL13.glActiveTexture(GL13.GL_TEXTURE0);
					currentTextureColor = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					
					commands.forEach(Runnable::run);
					
					GL13.glActiveTexture(RenderedGltfModel.NORMAL_MAP_INDEX);
					GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTextureNormal);
					GL13.glActiveTexture(RenderedGltfModel.SPECULAR_MAP_INDEX);
					GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTextureSpecular);
				}
				else {
					RenderedGltfModel.SPECULAR_MAP_INDEX = -1;
					
					GL13.glActiveTexture(RenderedGltfModel.NORMAL_MAP_INDEX);
					int currentTextureNormal = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					GL13.glActiveTexture(GL13.GL_TEXTURE0);
					currentTextureColor = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					
					commands.forEach(Runnable::run);
					
					GL13.glActiveTexture(RenderedGltfModel.NORMAL_MAP_INDEX);
					GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTextureNormal);
				}
			}
			else {
				RenderedGltfModel.NORMAL_MAP_INDEX = -1;
				if(specular != -1) {
					RenderedGltfModel.SPECULAR_MAP_INDEX = GL13.GL_TEXTURE1 + GL20.glGetUniformi(currentProgram, specular);
					
					GL13.glActiveTexture(RenderedGltfModel.SPECULAR_MAP_INDEX);
					int currentTextureSpecular = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					GL13.glActiveTexture(GL13.GL_TEXTURE0);
					currentTextureColor = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					
					commands.forEach(Runnable::run);
					
					GL13.glActiveTexture(RenderedGltfModel.SPECULAR_MAP_INDEX);
					GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTextureSpecular);
				}
				else {
					RenderedGltfModel.SPECULAR_MAP_INDEX = -1;
					
					GL13.glActiveTexture(GL13.GL_TEXTURE0);
					currentTextureColor = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
					
					commands.forEach(Runnable::run);
				}
			}
			
			GL13.glActiveTexture(GL13.GL_TEXTURE0);
			GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTextureColor);
		}

Sadly I couldn't have resolved the issue. I hope someone to solve it.

commented

Hey, any luck with that issue?

commented

@Arcomit hi, check out my fork. I've tried another normal and specular texture unit. It seems little bit fixed

commented

ok!
why use GL13.GL_TEXTURE2 with GL20.glGetUniformi(currentProgram, normals) instead of GL13.GL_TEXTURE0 combined with GL20.glGetUniformi(currentProgram, normals)?

commented

int normals = GL20.glGetUniformLocation(currentProgram, "normals");
GL20.glGetUniformi(currentProgram, normals);
this should retrieve the texture unit index bound to the "normals" uniform.
the problem might not be with the index itself, but rather that it’s not being applied to the model we’re rendering.