packtpublishing / 3d-graphics-rendering-cookbook Goto Github PK
View Code? Open in Web Editor NEW3D Graphics Rendering Cookbook, published by Packt.
License: MIT License
3D Graphics Rendering Cookbook, published by Packt.
License: MIT License
void MultiMeshRenderer::updateIndirectBuffers(VulkanRenderDevice& vkDev, size_t currentImage, bool* visibility)
{
VkDrawIndirectCommand* data = nullptr;
vkMapMemory(vkDev.device, indirectBuffersMemory_[currentImage], 0, 2 * sizeof(VkDrawIndirectCommand), 0, (void **)&data);
for (uint32_t i = 0 ; i < maxShapes_ ; i++)
{
const uint32_t j = shapes[i].meshIndex;
const uint32_t lod = shapes[i].LOD;
data[i] = {
.vertexCount = meshData_.meshes_[j].getLODIndicesCount(lod),
.instanceCount = visibility ? (visibility[i] ? 1u : 0u) : 1u,
.firstVertex = 0,
.firstInstance = i
};
}
vkUnmapMemory(vkDev.device, indirectBuffersMemory_[currentImage]);
}
the size passed to vkMapMemory is set to 2*sizeof(VkDrawIndirectCommand)
, should this be maxShapes_ * sizeof(VkDrawIndirectCommand)
?
After bootstrapping, running
C:\3D-Graphics-Rendering-Cookbook\Chapter5\GL01_Grid\build> cmake .. -G "Visual Studio 16 2019" -A x64
then
C:\3D-Graphics-Rendering-Cookbook\Chapter5\GL01_Grid\build> cmake --build . --config Release
yields:
C:\3D-Graphics-Rendering-Cookbook\Chapter5\GL01_Grid\src\main.cpp(5,10): fatal error C1083: Cannot open include file: 'shared/glFramework/GLFWApp.h': No such file or directory [C:\3D-Graphics-Rendering-Cookbook\Chapter5\GL01_Grid\build\Ch5_SampleGL01_Grid.vcxproj]
3D-Graphics-Rendering-Cookbook/data/shaders/chapter03/GL03_duck.vert
Lines 38 to 39 in 86c2eed
I am a bit confused about why we use vector * matrix
order in the first line and matrix * vector
in the second line. In GLSL, they give different results.
I think it should be changed to vtx.normal = normalMatrix * getNormal(gl_VertexID);
.
Thanks!
After building everything,
========== Build: 57 succeeded, 0 failed, 16 up-to-date, 3 skipped ==========
But when running : \build\Chapter3\VK01_GLSLang\Debug>Ch3_SampleVK01_GLSLang_Debug.exe, the window closes immediately, and when executing it in command prompt, the following error occurs :
I/O error. Cannot open shader file 'data/shaders/chapter03/VK01.vert'
I/O error. Cannot open shader file 'data/shaders/chapter03/VK01.frag'
Both shaders files are present in the data/ directory.
Thank you for this awesome book. I discovered this black spot in the PBR implementation and wonder what the cause is.
It's present in the Vulkan and OpenGL implementation and was captured on an Nvidia GTX 1060 on Linux.
Just for the record:
Seems to be fixed with this change in the PBR.sp
shader
vec2 brdfSamplePoint = clamp(vec2(pbrInputs.NdotV, 1.0 pbrInputs.perceptualRoughness), vec2(0.001, 0.001), vec2(0.009, 0.009));
I was trying to generate the solution through CMake, but I constantly received this error
CMake Error at CMakeLists.txt:125 (set_property):
set_property could not find TARGET zlibstatic. Perhaps it has not yet been created.
While issuing this commands in the root directory of the project
python bootstrap.py
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A x64
The only way to let the generation complete successfully, in my case, was by turning on the flag "ASSIMP_BUILD_ZLIB" in CMake.
Is it something excpected with Visual Studio 2022?
If not, what can I check to see if I have all the dependencies installed correctly?
CMake Error at CMakeLists.txt:125 (set_property):
set_property could not find TARGET zlibstatic. Perhaps it has not yet been
created.
Can't i use it on Ubuntu 21.04?
for example Ch8_SampleGL02_SSAO needs
GLSceneData sceneData1("data/meshes/test.meshes", "data/meshes/test.scene", "data/meshes/test.materials");
GLSceneData sceneData2("data/meshes/test2.meshes", "data/meshes/test2.scene", "data/meshes/test2.materials");
none of them are there.
Some QA before publishing please, I did not buy your to debug your build process!
missing data/meshs/*
bistro_all.materials
bistro_all.meshes
bistro_all.scene
test.materials
test.meshes
test.scene
test.meshes.instances
test_graph.materials
test_graph.meshes
test_graph.scene
test2.materials
test2.meshes
test2.scene
cube.material
cube.meshes
cube.scene
test.boxes
test_graph.boxes
test2.boxes
test.meshes.drawdata
test_duck.materials
test_duck.meshes
test_duck.scene
When loading a gltf file through createTexturedVertexBuffer()
the resulting texture is y-flipped.
To reproduce:
make_unique<ModelRenderer>
to "/data/rubber_duck/textures/Duck_baseColor.png"The result, the texture does not match the duck geometry, which can be seen around its eyes.
This may be fixed e.g. by the following change:
diff --git a/shared/UtilsVulkan.cpp b/shared/UtilsVulkan.cpp
index 38b50a5..d322bc3 100644
--- a/shared/UtilsVulkan.cpp
+++ b/shared/UtilsVulkan.cpp
@@ -2408,7 +2408,7 @@ bool createTexturedVertexBuffer(VulkanRenderDevice& vkDev, const char* filename,
{
const aiVector3D v = mesh->mVertices[i];
const aiVector3D t = mesh->mTextureCoords[0][i];
- vertices.push_back({ .pos = vec3(v.x, v.z, v.y), .tc = vec2(t.x, t.y) });
+ vertices.push_back({ .pos = vec3(v.x, v.z, v.y), .tc = vec2(t.x, 1.0-t.y) });
}
std::vector<unsigned int> indices;
An alternate fix would be to y-flip the image texture, or invert the v coordinate the fragment shader.
The computer shader that is used to generate the BRDF LUT texture generates texture coordinates this way:
vec2 uv;
uv.x = float(gl_GlobalInvocationID.x) / float(BRDF_W);
uv.y = float(gl_GlobalInvocationID.y) / float(BRDF_H);
this will lead to uv.x == 0
and uv.y == 0
when gl_GlobalInvocationID == vec2(0, 0)
. This in turn will lead to division by zero in
float G_Vis = (G * dotVH) / (dotNH * dotNV);
and yields an incorrect BRDF LUT texture.
Other resources like LearnOpenGL generate the BRDF LUT texture with a fragment shader. This causes the texture coordinates to be interpolated and will avoid a division by zero.
Running
cmake .. -G "Unix Makefiles"
cmake --build . --config Release
Results in the following error while compiling ImGuizmo
3D-Graphics-Rendering-Cookbook/deps/src/ImGuizmo/ImGuizmo.cpp:2546:21: error: expected ';' at end of declaration
bool boxes[27]{};
Generating an XCode project with cmake .. -G "Xcode"
, opening the XCode project and compiling gives the same error
I think both of them come from the fact that CLang 13 has partial support for C++20
Installing GCC 12 and forcing it's usage with
CC=gcc-12 CXX=gcc-12 cmake .. -G "Unix Makefiles"
cmake --build . --config Release
shows the following error when linking EtcLib
ld: symbol(s) not found for architecture arm64
Just wondering if someone had any luck at compiling the project
While I am generating using cmake in Windows, I get the following error:
CMake Error at CMakeLists.txt:125 (set_property):
set_property could not find TARGET zlibstatic. Perhaps it has not yet been
created.
I tried installing zlib using conda, but it is not working. Any help please? Thank you.
Here:
void main()
{
mat4 model = in_Model[gl_DrawID];
mat4 MVP = proj * view * model;
vec3 pos = getPosition(gl_VertexID);
gl_Position = MVP * vec4(pos, 1.0);
tc = getTexCoord(gl_VertexID);
mat3 normalMatrix = transpose( inverse(mat3(model)) );
normal = normalMatrix * getNormal(gl_VertexID);
worldPos = ( in_Model[gl_DrawID] * vec4(pos, 1.0) ).xyz;
}
Usually when you calculate normal matrix you need to use inverse of view model matrix.
After following the procedure in README.md
mkdir build
cd build
cmake ..
I was told by the errors to do the following
sudo apt-get install mercurial
sudo apt-get install libxrandr-dev
sudo apt-get install libxinerama-dev
sudo apt-get install libxcursor-dev
Then, after trying cmake .. again, I got the following error that indicates that a file is missing:
CMake Error at CMake/CommonMacros.txt:35 (add_executable):
Cannot find source file:
/home/evannibbe/ComputerScience/ComputerGraphics/deps/src/etc2comp/EtcTool/EtcFile.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
Chapter2/08_ETC2Comp/CMakeLists.txt:7 (SETUP_APP)
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
However, when I search for that file myself, I find it!
evannibbe@xxx:~/ComputerScience/ComputerGraphics/3D-Graphics-Rendering-Cookbook/deps/src/etc2comp/EtcTool$ ls
Args.txt CMakeLists.txt EtcComparison.cpp EtcFile.h EtcMemTest.cpp EtcSourceImage.h Makefile
CMakeFiles EtcAnalysis.cpp EtcComparison.h EtcFileHeader.cpp EtcMemTest.h EtcTool.cpp
cmake_install.cmake EtcAnalysis.h EtcFile.cpp EtcFileHeader.h EtcSourceImage.cpp EtcTool.h
This seems to mean that I must copy the deps folder one folder level upward (I just used ln -s 3D-Graphics-Rendering-Cookbook/deps ./deps with the current working directory one higher), which is annoying, but allows everything to work.
Now that MoltenVK supports Vulkan 1.2, is it feasible to use this book with macOS?
Just purchased a copy of this book and am reading through it. Really like the structure of the book and content, however I have a question about the renderer concept and design that's used in the book.
The book describes the different renderers and how to leverage that pattern. It also describes using the frustum to cull by turning off geometry by setting the instance count to 0.
That works fine for a geometry & textures that fit on the GPU, however, how can the renderer pattern be used for a very large landscape with lots of trees etc.? I have a quadtree for culling, and can't seem to find a way to fit that into the pattern.
Ideally, I'd want to leverage the quadtree for culling, and be able to stream geometry (and textures) into and out of the GPU based on some algorithm based on the camera and distance.
Any suggestions on how the renderer pattern could be modified for that?
Thanks!
I am relatively new to CMake. I have an issue with launching chapters related to Optick. When executing them, it throws an error saying that OptickCored.dll cannot be found.
I also tried with a simpler project. Here is the source tree:
The first CMakeLists is:
`cmake_minimum_required(VERSION 3.7)
project( OptickTest )
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(optick)
add_subdirectory(src)
`
and the one inside the src folder is:
`cmake_minimum_required(VERSION 3.7)
add_executable( OptickTest "main.cpp" )
target_link_libraries( OptickTest OptickCore )`
I could handle libraries such as GFLW, but this one gives me trouble. I don't understand why it cannot find the dll.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.