Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 11:29
    mosra commented #133
  • 11:15
    mosra milestoned #133
  • 11:13
    mosra commented #563
  • 11:13
    mosra closed #563
  • 11:13

    mosra on master

    Fix tiny english issue in featu… doc: updated credits and change… (compare)

  • 11:11
    mosra labeled #563
  • 11:10
    mosra milestoned #563
  • 10:13
    Build #3878 passed
  • 09:14
    pezcode edited #133
  • 09:10
    pezcode opened #133
  • 06:12
    cmey opened #563
  • 06:10
    cmey forked
    cmey/magnum
  • May 15 17:22
    mosra commented #560
  • May 15 17:20

    mosra on next

    package/ci: Run emscripten-webg… GL,DebugTools: "fix" global sym… TODOs for the stupid annoying E… and 1 more (compare)

  • May 15 17:10

    mosra on next

    GL,DebugTools: "fix" global sym… TODOs for the stupid annoying E… package/ci: Emscripten 2.0.17 t… (compare)

  • May 15 16:54
    mosra commented #560
  • May 15 16:54
    mosra commented #560
  • May 15 16:39
    mosra edited #507
  • May 15 16:38
    mosra edited #507
  • May 15 16:38
    mosra edited #507
irfna
@irfna

Hey, I'm having some issues rendering some basic textured cubes that use the same texture for each side, I end up with weird artifacts that change with every tiny change in the camera angle:

https://i.imgur.com/VH6HOuG.png

Currently using phong shader to test but the FlatGL shader has the same problem. My current vertices are just a copy and paste/rename of cubeSolid() and its dependencies, except I shoved in texture coordinates:

constexpr struct TileBlockVertex2 {
    Vector3 position;
    Vector3 normal;
    Vector2 textureCoordinates;
} TileBlockVertices2[]{
    {{-1.0f, -1.0f,  1.0f}, { 0.0f,  0.0f,  1.0f}, { 0.0f,  0.0f}},
    {{ 1.0f, -1.0f,  1.0f}, { 0.0f,  0.0f,  1.0f}, { 1.0f,  0.0f}},
    {{ 1.0f,  1.0f,  1.0f}, { 0.0f,  0.0f,  1.0f}, { 1.0f,  1.0f}}, /* +Z */
    {{-1.0f,  1.0f,  1.0f}, { 0.0f,  0.0f,  1.0f}, { 0.0f,  1.0f}},

...

And so on, then I'm just using cubeSolid() as is shown in examples. When I test FlatGL, I have a version of the array without the normal vector in it but is otherwise the same. There has to be something small/dumb I'm not seeing that is resulting in these errors, but everything I'm attempting is failing

Vladimír Vondruš
@mosra
hi! could it be just .. the depth test not being enabled?
leading to the (black) backfaces sometimes rendered after the faces that should be in front
irfna
@irfna
    GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);

    ViewRegion();

    GL::Renderer::enable(GL::Renderer::Feature::DepthTest);

    sprites.draw(*_camera);
    terrain.draw(*_camera);
I have actually experimented without depth test, but then some sides and other things are randomly missing as well. There's something really wrong that I can't nail down
I've used various textured cube vertex data from random people online to try different versions, but there's always artifacts and bugs in the cube. I'm able to render sprites on planes just fine, so I'm not sure why cubes are being so silly
 Shaders::PhongGL shader{Shaders::PhongGL::Flag::DiffuseTexture};

 GL::Mesh mesh = MeshTools::compile(cubeSolid());
  auto size = Vector3(TilePixelDimensions) / 4.0f;

  category.shader
  .setTransformationMatrix(transformation*Matrix4::scaling(size))
  .setProjectionMatrix(camera.projectionMatrix())
  .bindDiffuseTexture(*texture)
  .draw(category.mesh);
There's nothing really complicated going on in the code either, but maybe I'm missing a necessary feature or something?
Vladimír Vondruš
@mosra
huh
what's your setup? is it just a pure magnum application or combined with some 3rd party lib that could potentially touch OpenGL as well?
irfna
@irfna
This is a pure magnum setup based on the basic bootstrap project, setup just for testing out rendering sprites and cubes
Vladimír Vondruš
@mosra
ah that could be rather easy to go through, can you post the whole code somewhere? gist, pastebin... i'll look at it
the small stupid mistakes are always the most annoying :D
irfna
@irfna
haha ya. Thanks for the help and looking at this! I'm rounding this up, I guess I could just zip it up and post it somewhere? All I've changed are the CMakeLists.txt and MyApplication.cpp of the bootstrap. Let me toss this on google drive or something
The tricky part is that I have it launching in my c:\lib directory where I have my .dll files compiled, but it's grabbing sprites from a different hardcoded directory, so I'm figuring out how to package this together properly
Vladimír Vondruš
@mosra
i'm on linux anyway, so i'll just grab the code and see :)
even just the cpp file is enough
irfna
@irfna

https://pastebin.com/15p7G9B8

Ok, this is just the cpp file, I have imagepath at the top to be filled out with an image path, and can grab my really poorly drawn images as well

I changed it to using flatGL instead of phong in the mean time, so it will be using the flat shader in the pastebin, the error is clearer with it though I think
Vladimír Vondruš
@mosra
hmmm i get the same issue
investigating...
irfna
@irfna
I really appreciate the help!
Vladimír Vondruš
@mosra

btw, i find this hilariuous:

GetImage("dirt.png")

vs

GetImage(object.png)

had to take a double look until i understood how it can even compile :D

irfna
@irfna
hahaha oops ya I should have fixed that debug output, I was copying and pasting example code
This is more of a test run of various features I need than making the actual game proper
Vladimír Vondruš
@mosra

okay the problem seems to be here:

.setProjectionMatrix(Matrix4::perspectiveProjection(35.0_degf, 4.0f/3.0f, 0.001f, 1000000.0f))

the near/far range is so huge that it's beyond what can be represented in a (I assume) 24bit depth buffer, and so the cube front and back faces get assigned the same depth value, which makes the output depend on the order the GPU processes the triangles and not the actual depth
i went with 0.1f, 10000.0f and it started looking acceptable, but if you see similar artifacts later you might want to narrow it down even further
irfna
@irfna
Ah I see, so I'll have to make sure everything gets scaled down a bunch so I can reduce that value
Vladimír Vondruš
@mosra
more like finding the right range
irfna
@irfna
Thanks, I knew it had to be some small thing like that
Vladimír Vondruš
@mosra
for example if you have everything 10 or 100 units from the camera anyway, then it doesn't make sense to make the near value so low
irfna
@irfna
Ok, I see
Yep, switching to 10.0f to 10000.0f seems to fix the issue completely!
Thanks for the help! Now all I have to do is figure out why the sprite transparency isn't working even when I enable blending haha
Vladimír Vondruš
@mosra
you need to call setBlendFunction() as well :)
irfna
@irfna
Cool, thanks!
Vladimír Vondruš
@mosra
actually i can't seem to get it work myself :D only AlphaMask enabled on the shader did work
what am i doing wrong?
ah, no, actually
Vladimír Vondruš
@mosra
this is it:
    GL::Renderer::enable(GL::Renderer::Feature::DepthTest);

    terrain.draw(*_camera);

    /* Draw sprites after the terrain, so it's obscured by it if it's behind.
       But disable depth writes, so the sprites don't cut into each other */
    GL::Renderer::setDepthMask(false);
    sprites.draw(*_camera);
    GL::Renderer::setDepthMask(true);

    GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
before you had sprites rendered first, and they wrote to the depth buffer so the cube wasn't rendered behind it
the AlphaMask (and no blending, or depth ordering) works as well, but that's a purely binary operation (a pixel either is there or is not), so it looks acceptable only on sufficiently high-DPI screens and won't work for semi-transparent stuff
irfna
@irfna
haha I hadn't actually tested when you said to use setBlendFunction and had to go afk at the time, sorry for making you think I got it to work with that. For sprites, alphamask is all I need for now, although someday I will need to be able to make things semi-transparent
I'll copy and paste that change into my code
Vladimír Vondruš
@mosra
it always ends up being more complicated than it seems at first
irfna
@irfna
Ya, I see what you mean. Luckily the extra complication has been fairly small one line things, it's just knowing that they're necessary that is the issue haha. I tossed setBlendFunction in along with the code snippet you pasted, and the sprite transparency is working great
Thanks a bunch, you cut through some stubborn issues for me just like that
Vladimír Vondruš
@mosra
last thing, while i have the code here -- it crashes asserts on exit due to the global manager that holds OpenGL objects, the ideal fix would be to make it a member of the Application class, so it gets cleaned up before the Application itself destroys the OpenGL context
irfna
@irfna
Alright, thanks! That's an easy enough fix
Mathew
@lectroMathew
PhongMaterialUniform::shininess doesn't make much sense to me: the larger value, the harder surface. Shouldn't it be called hardness then? :D I wonder why GL_SHININESS works in this way...