Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Animation API] Black flickering while a model is rotating. #4960

Closed
se7kn8 opened this issue May 30, 2018 · 6 comments
Closed

[Animation API] Black flickering while a model is rotating. #4960

se7kn8 opened this issue May 30, 2018 · 6 comments

Comments

@se7kn8
Copy link

se7kn8 commented May 30, 2018

Continued from: http://www.minecraftforge.net/forum/topic/64596-animation-api-rendering-issue/

As can be seen in this video, there is an issue with the Animation API. Always when the rotation goes back to its original state, the texture turns black. I tested this with my custom block and the block from the forgedebugmodelanimation test mod. (Sometimes I have to break and place the block again or rejoin the world to reproduce the issue again)

Forced crash (to provide some system details): https://pastebin.com/G2Kn6Khx

@Aeronica
Copy link

Aeronica commented May 31, 2018

I've gone back with a test mod and found the build where this issue started.

fastTESR artifacts for the Forge Animation System begin starting with this build 14.22.0.2474
Build 2474:
bs2609: Improve generation of normals for vanilla models (#4313)
bs2609: Patch block model renderer to use location-aware light value (#4303)

14.22.0.2473 is okay, no "Black Flickering" rendering artifacts present in this version for the Forge Animation System

Giphy
Streamable video showing the flickering

This is the asm and armature I used in my animated model to create a bell like motion. If anyone wants to look at my test mod look for OneShot related classes and jsons TestMod

asm
{
    "parameters": {
    	"world_cycle": [ "/", "#cycle_length" ],
        "end_anim": [ "compose", [ "+", "#cycle_length" ] , "#click_time" ],
        "trigger_anim": [ "-", "#end_anim" ],
        "progress": [ "-/", "#click_time", "#cycle_length" ]        
    },
    "clips": {
        "rest": "#identity",        
        "trigger": [ "trigger_positive", [ "apply", "testmod:block/one_shot_bell@trigger", "#progress" ], "#trigger_anim", "!transition:rest" ],       
        "free_run": [ "apply", "testmod:block/one_shot_bell@trigger", "#world_cycle" ]      
    },
    "states": [
        "rest",
        "trigger",
        "free_run"
    ],
    "transitions": {
        "rest": "trigger",
        "trigger": [ "rest", "trigger" ],
        "free_run": [ "rest", "trigger" ]

    },
    "start_state": "free_run"
}
armature
{
    "joints": {
        "bell_conn": { "0": [ 1.0 ] },
        "bell_top": { "1": [ 1.0 ] },
        "bell_main": { "2": [ 1.0 ] },      
        "bell_mouth1": { "3": [ 1.0 ] },      
        "bell_mouth2": { "4": [ 1.0 ] },      
        "bell_mouth3": { "5": [ 1.0 ] },      
        "bell_mouth4": { "6": [ 1.0 ] },      
        "axle_horiz": { "7": [ 1.0 ] },    
        "axle_vert1": { "8": [ 1.0 ] },    
        "axle_vert2": { "9": [ 1.0 ] },    
        "clapper": { "10": [ 1.0 ] }      
    },
    "clips": {
        "rest": {
            "loop": false,
            "joint_clips": {},
            "events": {}
        },     
        "trigger": {
            "loop": true,
            "joint_clips": {
		       	"bell_conn": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],
		       	"bell_top": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],
		       	"bell_main": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],
		       	"bell_mouth1": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],	                		        	        
		       	"bell_mouth2": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],	                		        	        
		       	"bell_mouth3": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],	                		        	        
		       	"bell_mouth4": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],	                		        	        
		       	"axle_horiz": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],
		       	"axle_vert1": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],
		       	"axle_vert2": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [ 0, 45, 0, 330, 0, 30, 0, 350,0, 10, 0, 355, 0 ]
			        }
		        ],			        	                		        	        		        		                		        	        
		       	"clapper": [
					{
	                    "variable": "axis_x",
	                    "type": "uniform",
	                    "interpolation": "linear",
	                    "samples": [ 1 ]
					},
			        {
			            "variable": "angle",
			            "type": "uniform",
			            "interpolation": "linear",
			            "samples": [  0, 45, 40, 0, 330, 335, 0, 30, 20, 0, 350, 345, 0, 10, 5, 0, 355, 350, 0 ]
			        }
		        ]	                		        	        
			},
		"events": {}		    
		}
    }
}

@se7kn8
Copy link
Author

se7kn8 commented May 31, 2018

@bs2609 Because the changes are from you, can you look at this?

@se7kn8
Copy link
Author

se7kn8 commented May 31, 2018

Okay, I figured out from where the bug is coming from:
It's the Math.round which you can find here. We could just remove the Math.round but then we remove the fix for #4178.

@Aeronica
Copy link

#4313 closed the #4178 issue. So it appears those were combined.

@bs2609
Copy link
Contributor

bs2609 commented May 31, 2018

For easy reference, here's how the normal values are produced:

public static void fillNormal(int[] faceData, EnumFacing facing)
{
Vector3f v1 = getVertexPos(faceData, 3);
Vector3f t = getVertexPos(faceData, 1);
Vector3f v2 = getVertexPos(faceData, 2);
v1.sub(t);
t.set(getVertexPos(faceData, 0));
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
int x = ((byte) Math.round(v1.x * 127)) & 0xFF;
int y = ((byte) Math.round(v1.y * 127)) & 0xFF;
int z = ((byte) Math.round(v1.z * 127)) & 0xFF;
int normal = x | (y << 0x08) | (z << 0x10);
for(int i = 0; i < 4; i++)
{
faceData[i * 7 + 6] = normal;
}
}
private static Vector3f getVertexPos(int[] data, int vertex)
{
int idx = vertex * 7;
float x = Float.intBitsToFloat(data[idx]);
float y = Float.intBitsToFloat(data[idx + 1]);
float z = Float.intBitsToFloat(data[idx + 2]);
return new Vector3f(x, y, z);
}

else
{
normal = new float[4][4];
Vector3f v1 = new Vector3f(position[3]);
Vector3f t = new Vector3f(position[1]);
Vector3f v2 = new Vector3f(position[2]);
v1.sub(t);
t.set(position[0]);
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
for(int v = 0; v < 4; v++)
{
normal[v][0] = v1.x;
normal[v][1] = v1.y;
normal[v][2] = v1.z;
normal[v][3] = 0;
}
}

@bs2609
Copy link
Contributor

bs2609 commented May 31, 2018

Right I see what the problem is now >_>
Will make a PR to fix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants