alpinestudios / oogabooga

ooga booga
Other
194 stars 230 forks source link

Flickering artifact line on edge of sprite after rotating sprite #27

Open Flynnvolt opened 2 weeks ago

Flynnvolt commented 2 weeks ago

image

Getting this weird flickering line artifact on my sprite's edge after I rotate it.

I can't seem to figure out how to fix it.

I am probably just doing something wrong but I thought id ask anyway.

help would be appreciated.

Thanks.

my is code here: sprite stuff: https://github.com/Flynnvolt/TowerOfTheSky/blob/master/TowerOfTheSky/AnimationData.c and main game file: https://github.com/Flynnvolt/TowerOfTheSky/blob/master/TowerOfTheSky/TowerOfTheSky.c

the only code that should matter from the main game file "TowerOfTheSky.c" is below:

outside of game loop:

// Spells sprites[SPRITE_fireball_sheet] = (SpriteData){ .image = load_image_from_disk(STR("Resources/Sprites/fireball_sprite_sheet.png"), get_heap_allocator())};

setup_fireball_anim(); // Setup fireball animation so it can be used.

In game loop:

// Fireball Test Vector2 position = v2(20, 20); float32 scale_ratio = 4.0; float32 rotation_degrees = 45.0; update_animation(& Fireball, position, scale_ratio, rotation_degrees);

asbott commented 2 weeks ago

I think the source of this might be the same as for your other problem. It's potentially fixed in the latest update I just pushed, 0.01.007. Go ahead and merge that and let me know if these problems persist.

Flynnvolt commented 2 weeks ago

I merged and I am still having this problem

asbott commented 2 weeks ago

I just cloned your repo and I am not getting the same issue.

Could you send me the output logs in the terminal?

Flynnvolt commented 2 weeks ago

Ooga booga program started Program memory grew to 5120 kb Program memory grew to 8192 kb [INFO]: Ooga booga version is 0.01.007 [VERBOSE]: d3d11 gfx_init [INFO]: Successfully initialized default audio device. Channels: 8, sample_rate: 96000, bits: 32 [VERBOSE]: D3D11 debug is active [VERBOSE]: Created D3D11 device [INFO]: D3D11 adapter is: NVIDIA GeForce RTX 2080 [VERBOSE]: Present mode is flip discard, 3 buffers [INFO]: Created swap chain of size 116x0 [VERBOSE]: Shaders compiled [VERBOSE]: Shaders created [INFO]: D3D11 init done [VERBOSE]: CPU has sse1: true [VERBOSE]: CPU has sse2: true [VERBOSE]: CPU has sse3: true [VERBOSE]: CPU has ssse3: true [VERBOSE]: CPU has sse41: true [VERBOSE]: CPU has sse42: true [VERBOSE]: CPU has avx: true [VERBOSE]: CPU has avx2: true [VERBOSE]: CPU has avx512: false [VERBOSE]: Primary Monitor: NVIDIA GeForce RTX 2080 240hz 1920x1080 dpi: 96 [VERBOSE]: Created a D3D11 image of width 32 and height 32. [VERBOSE]: Created a D3D11 image of width 28 and height 38. [VERBOSE]: Created a D3D11 image of width 9 and height 9. [VERBOSE]: Created a D3D11 image of width 17 and height 21. [VERBOSE]: Created a D3D11 image of width 32 and height 23. [VERBOSE]: Created a D3D11 image of width 96 and height 32. [VERBOSE]: Created a D3D11 image of width 96 and height 32. Program memory grew to 16384 kb [VERBOSE]: Created a D3D11 image of width 2048 and height 2048. [INFO]: Resized swap chain from 116x0 to 1920x1080 [VERBOSE]: Grew quad vbo to 131072 bytes. [INFO]: 5.42 FPS 184.41ms [INFO]: 1032.42 FPS 0.97ms [INFO]: 992.16 FPS 1.01ms Ooga booga program exit with code 0 PS C:\Game Project\TowerOfTheSky>

asbott commented 2 weeks ago

https://github.com/user-attachments/assets/f0a07b0a-4904-46be-a8d1-a6214547f3df

Weird, it looks like this for me. Is there anything I need to do to reproduce it?

asbott commented 2 weeks ago

Do you have the latest drivers ?

Flynnvolt commented 2 weeks ago

That's pretty much what mine looks like minus the line bug thing not being there.

as for nvidia drivers I am up to date:

image

Flynnvolt commented 2 weeks ago

wait yours starts up in a window but mine is the whole screen do you have the latest of my repo? maybe you have a bigger monitor?

asbott commented 2 weeks ago

wait yours starts up in a window but mine is the whole screen do you have the latest of my repo? maybe you have a bigger monitor?

Yes I have a bigger monitor

asbott commented 2 weeks ago

Does the artifact appear on all the frames in the fireball animation or only one of them?

Flynnvolt commented 2 weeks ago

the line only appears on frame 2 and 3 of the fireball animation

asbott commented 2 weeks ago

Okay so it's slightly undersampling to the previous frame. This is a super annoying problem that might be due to float precision or sampling just being bad.

This is not a solution, but can you tell me if this solve that specific case?

float64 px_width  = 1.0/(float64)anim_info->anim_sheet->width;
float64 px_height = 1.0/(float64)anim_info->anim_sheet->height;

// Draw the sprite sheet with the UV box for the current frame and apply rotation
Draw_Quad *quad = draw_image_xform(anim_info -> anim_sheet, rotation_matrix, v2(frame_width_scaled, frame_height_scaled), COLOR_WHITE);
quad -> uv.x1 = (float32)(anim_sheet_pos_x) / (float32)anim_info -> anim_sheet -> width + px_width*0.1;
quad -> uv.y1 = (float32)(anim_sheet_pos_y) / (float32)anim_info -> anim_sheet -> height + px_height*0.1;
quad -> uv.x2 = (float32)(anim_sheet_pos_x + anim_info -> anim_frame_width) / (float32)anim_info -> anim_sheet -> width;
quad -> uv.y2 = (float32)(anim_sheet_pos_y + anim_info -> anim_frame_height) / (float32)anim_info -> anim_sheet -> height;
Flynnvolt commented 2 weeks ago

that fixed it

asbott commented 2 weeks ago

that fixed it

I wouldn't rely on that, because now it might cause slight oversampling on other images.

If you do this instead (float64 operations instead of float32), will that make any difference?

Draw_Quad *quad = draw_image_xform(anim_info -> anim_sheet, rotation_matrix, v2(frame_width_scaled, frame_height_scaled), COLOR_WHITE);
quad -> uv.x1 = (float64)(anim_sheet_pos_x) / (float64)anim_info -> anim_sheet -> width;
quad -> uv.y1 = (float64)(anim_sheet_pos_y) / (float64)anim_info -> anim_sheet -> height;
quad -> uv.x2 = (float64)(anim_sheet_pos_x + anim_info -> anim_frame_width) / (float64)anim_info -> anim_sheet -> width;
quad -> uv.y2 = (float64)(anim_sheet_pos_y + anim_info -> anim_frame_height) / (float64)anim_info -> anim_sheet -> height;
Flynnvolt commented 2 weeks ago

that fixed it

I wouldn't rely on that, because now it might cause slight oversampling on other images.

If you do this instead (float64 operations instead of float32), will that make any difference?

Draw_Quad *quad = draw_image_xform(anim_info -> anim_sheet, rotation_matrix, v2(frame_width_scaled, frame_height_scaled), COLOR_WHITE);
quad -> uv.x1 = (float64)(anim_sheet_pos_x) / (float64)anim_info -> anim_sheet -> width;
quad -> uv.y1 = (float64)(anim_sheet_pos_y) / (float64)anim_info -> anim_sheet -> height;
quad -> uv.x2 = (float64)(anim_sheet_pos_x + anim_info -> anim_frame_width) / (float64)anim_info -> anim_sheet -> width;
quad -> uv.y2 = (float64)(anim_sheet_pos_y + anim_info -> anim_frame_height) / (float64)anim_info -> anim_sheet -> height;

this broke it again

asbott commented 2 weeks ago

Alright, I guess just stick with the one that works for now. This seems like a very sad gpu-specific driver issue, and it's very hard to debug this when I'm not able to reproduce it. I'll leave this issue open in case anyone else may be able to contribute with any ideas.

Flynnvolt commented 2 weeks ago

Alright, I guess just stick with the one that works for now. This seems like a very sad gpu-specific driver issue, and it's very hard to debug this when I'm not able to reproduce it. I'll leave this issue open in case anyone else may be able to contribute with any ideas.

Dang that is really wierd, anyways thanks for the help.