zesterer / euc

A software rendering crate that lets you write shaders with Rust
Apache License 2.0
294 stars 15 forks source link

Possible regression in euc 0.4.1 #9

Closed CryZe closed 5 years ago

CryZe commented 5 years ago

I'm seeing some weird artifacts with euc 0.4.1:

Before: score_split_2d9fac28

After: score_split_3d370ce9

The 4 of the main points meter has a weird line going through it.

zesterer commented 5 years ago

Interesting. How are those numbers currently rendered?

CryZe commented 5 years ago

I'm getting the glyphs from rusttype and then triangulate them with lyon. So they are basically just normal meshes. There shouldn't be a gap there as the two adjacent triangles there don't have a gap, as they are sharing the same vertices.

zesterer commented 5 years ago

euc's vertex shader now expects [f32; 4] as part of the return type, but I see that's not happening in your code. What happens if you emit 1.0 as the last value?

CryZe commented 5 years ago

That's what I'm doing here. I didn't push the changes yet. Without a fourth f32 value, it wouldn't build.

zesterer commented 5 years ago

Would it be possible to put together a setup that demonstrates the problem such that I can try to figure out what's going on? I have a few suspicions, but it's difficult for me to confirm them without a way to test them.

CryZe commented 5 years ago

I'll try to replicate it in a small-ish test.

CryZe commented 5 years ago

Okay, this is really odd. If I disable alpha blending, the problem goes away O.o

CryZe commented 5 years ago

It seems like the color values are completely out of range.

CryZe commented 5 years ago

Yeah, that's a line where the input color is NaN apparently.

zesterer commented 5 years ago

I suspect that a NaN is generated somewhere in the rasterizer for a 0-width triangle or something like that, and that this gets propagated to the blending code.

CryZe commented 5 years ago

Here's the code as a gist: https://gist.github.com/CryZe/ab4544126b6e0b6660364066cc818714

CryZe commented 5 years ago

It's a white line in this because I do .min(255.0) at the end.

CryZe commented 5 years ago

The line is at y=362, x>=198, x<=208

CryZe commented 5 years ago

The triangle that causes it seems to be this one:

    let mesh = [
        Vertex {
            position: Vec2 {
                x: 0.39804077,
                y: -0.21000671,
            },
            texcoord: Vec2 {
                x: 0.0,
                y: 0.36832988,
            },
        },
        Vertex {
            position: Vec2 {
                x: 0.27268982,
                y: -0.21000671,
            },
            texcoord: Vec2 {
                x: 0.0,
                y: 0.36832988,
            },
        },
        Vertex {
            position: Vec2 {
                x: 0.44769287,
                y: -0.21000671,
            },
            texcoord: Vec2 {
                x: 0.0,
                y: 0.36832988,
            },
        },
    ];
CryZe commented 5 years ago

And yeah, looks like that's a straight line as all y coordinates are the same.

zesterer commented 5 years ago

Okay, I've found the bug. As suspected, it was a NaN that got propagated throughout the texture projection code. I'm pushing a fix now (I'll publish a new version too).

zesterer commented 5 years ago

euc 0.4.2 now includes the patch.

CryZe commented 5 years ago

Looks like that fixed it in all of my tests. Thank you for figuring this out :D