{"id":20671503,"url":"https://github.com/hopson97/yavge","last_synced_at":"2025-04-19T18:38:57.270Z","repository":{"id":37030130,"uuid":"372024139","full_name":"Hopson97/Yavge","owner":"Hopson97","description":"Yet Another Voxel Graphics Engine - just playing around (tm)","archived":false,"fork":false,"pushed_at":"2024-07-14T21:28:39.000Z","size":18640,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-14T22:34:01.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hopson97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-29T16:45:37.000Z","updated_at":"2024-07-14T21:28:42.000Z","dependencies_parsed_at":"2024-07-14T22:42:25.744Z","dependency_job_id":null,"html_url":"https://github.com/Hopson97/Yavge","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopson97%2FYavge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopson97%2FYavge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopson97%2FYavge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopson97%2FYavge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hopson97","download_url":"https://codeload.github.com/Hopson97/Yavge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224969241,"owners_count":17400208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T20:27:44.281Z","updated_at":"2024-11-16T20:27:45.140Z","avatar_url":"https://github.com/Hopson97.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yavge\n\nYet Another Voxel Game Engine, or Yet Another Voxel Graphics Engine. The choice is yours.\n\nThis was created using OpenGL 4.5 and the direct state access (DSA) API as opposed to the \"binding\" API of OpenGL 3.3.\n\n## Building and Running\n\n### Windows (Visual Studio)\n\nThe easiest way to build is to use [vcpkg](https://vcpkg.io/en/index.html) and install libraries through this:\n\n```bash\nvcpkg install sfml\nvcpkg install glm\nvcpkg integrate install\n```\n\nThen open the Visual Studio project file, and it should build.\n\n### Linux\n\nRequires conan.\n\n```sh\npython3 -m pip install conan==1.61.0\n```\n\nTo build, at the root of the project:\n\n```sh\nsh scripts/build.sh install\n```\n\nThe install argument is only needed for the first time compilation as this is what grabs the libraries from Conan.\n\nSo after the first time, you can simply run:\n\n```\nsh scripts/build.sh\n```\n\nTo run, at the root of the project:\n\n```sh\nsh scripts/run.sh\n```\n\nTo build and run in release mode, simply add the `release` suffix:\n\n```sh\nsh scripts/build.sh release\nsh scripts/run.sh release\n```\n\n## Screenshots\n\nIn order of features added:\n\n### Phong Lighting (Base)\n\n![Phong Lighting](/Screenshots/Base.png \"Phong Lighting\")\n\n### Reflection and Refraction\n\n![Reflection and Refraction](/Screenshots/ReflectRefractMaps.png \"Reflection and Refraction\")\n\n### Fresnel Effect\n\n![Fresnel Effect](/Screenshots/FresnelEffect.png \"Fresnel Effect\")\n\n### Distort Maps (AKA DU/DV maps)\n\n![Distort Maps](/Screenshots/DUDVMaps.png \"Distort Maps\")\n\n### Normal Maps\n\n![Normal Maps](/Screenshots/NormalMaps.png \"Normal Maps\")\n\n## Mistakes Were Made...\n\nAs this was my first time using DSA and more advanced computer graphics techniques, I ran into problems, which will be listed here so I don't run into them again:\n\n### 2D array texture\n\nWith non-dsa, it seemed OK to create the 2D Array Texture as below:\n\n```cpp\nglBindTexture(GL_TEXTURE_2D_ARRAY, m_handle)\n// set up texture params here\nglTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, textureSize, textureSize,\n             numTextures, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);\n```\n\nWhere textureSize is the width and height value and \"numTextures\" is the maximum number of textures this particular texture array would support.\n\nWith DSA, the equal would be something like:\n\n```cpp\n// no binding needed!\n// set up texture params here\nglTextureStorage3D(m_handle, 0, GL_RGBA, textureSize, textureSize, numTextures);\n```\n\nHowever, the issue with this approach is the first and second args, which must be replaced with 1 and GL_RGBA8 respectively:\n\n```cpp\nglTextureStorage3D(m_handle, 1, GL_RGBA8, textureSize, textureSize, numTextures);\n```\n\nThe reasons become clear by looking at the docs:\n\nhttps://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage3D.xhtml\n\nhttps://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexStorage3D.xhtml\n\n\n### Depth Texture \n\nAt some point I was playing around with depth textures, and struggled to render them.\n\nIt turns out the fragment shader must select a single channel from the sampled texture and amplified to actually see it (As without the differences are too small to see).\n\nFor example, typical texture mapping is (Where `tex` is a `uniform sampler2D` and `texCoord` is a vec2 for the texture coords):\n\n```glsl\nvoid main() { \n    outColour = texture(tex, texCoord);\n}\n```\n\nHowever this results in a pure red texture. In order to actually see the depth, the red channel must be extracted and amped as follows:\n\n```glsl\nvoid main() { \n    float depth = texture(tex, texCoord).r;\n    depth = 1.0 - (1.0 - depth) * 50.0;\n    outColour = vec4(depth);\n}\n```\n\n### Multiple texture units\n\nGiven a shader has multiple texture units:\n\n```glsl\nuniform sampler2D tex0;\nuniform sampler2D tex1;\n```\n\nIn pre-dsa, this worked like:\n\n```cpp\nglUniform1i(glGetUniformLocation(program, \"tex0\"), 0);\nglUniform1i(glGetUniformLocation(program, \"tex1\"), 1);\n\n// ...\n\nglActiveTexture(GL_TEXTURE0);\nglBindTexture(GL_TEXTURE_2D, tex0);\n\nglActiveTexture(GL_TEXTURE1);\nglBindTexture(GL_TEXTURE_2D, tex1);\n```\n\nWhich results with textures being mapped to the correct texture unit.\n\nIn DSA, the equal might appear to be:\n\n```cpp\nglUniform1i(glGetUniformLocation(program, \"tex0\"), 0);\nglUniform1i(glGetUniformLocation(program, \"tex1\"), 1);\n\n// ...\n\nglBindTextureUnit(0, tex0);\nglBindTextureUnit(1, tex1);\n```\n\nHowever this will not work. Instead the shader are able to mapped to texture unit directly, which also means the `glUniform1i`/`glGetUniformLocation` is no longer needed, as OpenGL is able to work out the correct mapping from the first arg of `glBindTextureUnit`:\n\n\n```glsl\nlayout(binding = 0) uniform sampler2D tex0;\nlayout(binding = 1) uniform sampler2D tex1;\n```\n\n```cpp\nglBindTextureUnit(0, tex0);\nglBindTextureUnit(1, tex1);\n```\n\nWhich will then result in correct textures being used.\n\n### Mipmaps\n\nBefore DSA, it was not really needed to specify number of mipmaps:\n\n```cpp\nglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);\nglGenerateMipmap(GL_TEXTURE_2D);  \nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);\n// ... etc ...\n```\n\nWith DSA, this must be specified in the second argument of glTextureStorage\u003c\u003eD\n\nFor example:\n```cpp\nglTextureStorage2D(m_handle, 10, GL_RGBA8, width, height);\nglGenerateMipmap(GL_TEXTURE_2D);  \nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);\n// ... etc ...\n```\n\nWhich will then generate 10 mip maps levels. However, this number depends on the texture size. A smaller texture will not allow that many mip maps to be generated, and will instead render as black at far distances.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopson97%2Fyavge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhopson97%2Fyavge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopson97%2Fyavge/lists"}