Minor changes

This commit is contained in:
Gamemaker1998
2025-01-25 18:45:02 +01:00
parent 463e3d925e
commit a73f43bb31
3 changed files with 10 additions and 10 deletions
+3 -1
View File
@@ -70,6 +70,7 @@ using namespace slang;
void Renderer::createShaders() void Renderer::createShaders()
{ {
/*
Slang::ComPtr<IGlobalSession> globalSession; Slang::ComPtr<IGlobalSession> globalSession;
SlangGlobalSessionDesc desc = {}; SlangGlobalSessionDesc desc = {};
createGlobalSession(&desc, globalSession.writeRef()); createGlobalSession(&desc, globalSession.writeRef());
@@ -82,7 +83,7 @@ void Renderer::createShaders()
const char* searchPaths[] = {"res/shaders/"}; const char* searchPaths[] = {"res/shaders/"};
sessionDesc.searchPaths = searchPaths; sessionDesc.searchPaths = searchPaths;
sessionDesc.searchPathCount = 1; sessionDesc.searchPathCount = 1;
/* ... fill in `sessionDesc` ... */ /* ... fill in `sessionDesc` ...
Slang::ComPtr<ISession> session; Slang::ComPtr<ISession> session;
globalSession->createSession(sessionDesc, session.writeRef()); globalSession->createSession(sessionDesc, session.writeRef());
@@ -104,6 +105,7 @@ void Renderer::createShaders()
int targetIndex = 0; // only one target int targetIndex = 0; // only one target
Slang::ComPtr<IBlob> kernelBlob; Slang::ComPtr<IBlob> kernelBlob;
linkedProgram->getEntryPointCode(entryPointIndex, targetIndex, kernelBlob.writeRef(), diagnostics.writeRef()); linkedProgram->getEntryPointCode(entryPointIndex, targetIndex, kernelBlob.writeRef(), diagnostics.writeRef());
*/
} }
void Renderer::render(Camera cam, RenderParameter param) {} void Renderer::render(Camera cam, RenderParameter param) {}
+6 -8
View File
@@ -13,8 +13,8 @@ void Model::transform(glm::mat4 matrix)
{ {
auto e0 = positions[indices[i + 1]] - positions[indices[i + 0]]; auto e0 = positions[indices[i + 1]] - positions[indices[i + 0]];
auto e1 = positions[indices[i + 2]] - positions[indices[i + 0]]; auto e1 = positions[indices[i + 2]] - positions[indices[i + 0]];
es.push_back(e0); edges.push_back(e0);
es.push_back(e1); edges.push_back(e1);
faceNormals.push_back(glm::cross(e0, e1)); faceNormals.push_back(glm::cross(e0, e1));
} }
@@ -25,14 +25,14 @@ std::optional<IntersectionInfo> Model::intersect(const Ray ray) const
std::optional<IntersectionInfo> intersection = {}; std::optional<IntersectionInfo> intersection = {};
float distance = 0; float distance = 0;
for(size_t posIndex=0, eIndex=0, normalIndex=0; posIndex <indices.size(); posIndex+=3, eIndex+=2, normalIndex++) for(size_t posIndex=0, edgeIndex=0, normalIndex=0; posIndex <indices.size(); posIndex+=3, edgeIndex+=2, normalIndex++)
{ {
const auto p0 = positions[indices[posIndex]]; const auto p0 = positions[indices[posIndex]];
const auto p1 = positions[indices[posIndex+1]]; const auto p1 = positions[indices[posIndex+1]];
const auto p2 = positions[indices[posIndex+2]]; const auto p2 = positions[indices[posIndex+2]];
const auto e0 = es[eIndex]; const auto e0 = edges[edgeIndex];
const auto e1 = es[eIndex +1]; const auto e1 = edges[edgeIndex+1];
const auto n = faceNormals[normalIndex]; const auto n = faceNormals[normalIndex];
@@ -43,7 +43,7 @@ std::optional<IntersectionInfo> Model::intersect(const Ray ray) const
const float fraction = 1.0f / glm::dot(s1, e0); const float fraction = 1.0f / glm::dot(s1, e0);
const auto resultVector = glm::vec3(glm::dot(s2, e1), glm::dot(s1, s), glm::dot(s2, ray.direction)) * fraction; const auto resultVector = glm::vec3(glm::dot(s2, e1), glm::dot(s1, s), glm::dot(s2, ray.direction)) * fraction;
const double b3 = 1 - resultVector.y - resultVector.z; const float b3 = 1.0f - resultVector.y - resultVector.z;
if(b3 < 0 || b3 > 1) if(b3 < 0 || b3 > 1)
continue; continue;
@@ -52,8 +52,6 @@ std::optional<IntersectionInfo> Model::intersect(const Ray ray) const
if(resultVector.z < 0 || resultVector.z > 1) if(resultVector.z < 0 || resultVector.z > 1)
continue; continue;
if(std::abs(1.0f - (resultVector.y + resultVector.z + b3)) > 1e-7)
continue;
if(resultVector.x < 1e-6) if(resultVector.x < 1e-6)
continue; continue;
+1 -1
View File
@@ -22,7 +22,7 @@ public:
AABB boundingBox; AABB boundingBox;
std::vector<glm::vec3> positions; std::vector<glm::vec3> positions;
std::vector<uint32_t> indices; std::vector<uint32_t> indices;
std::vector<glm::vec3> es; std::vector<glm::vec3> edges;
std::vector<glm::vec3> faceNormals; std::vector<glm::vec3> faceNormals;
void transform(glm::mat4 matrix); void transform(glm::mat4 matrix);
std::optional<IntersectionInfo> intersect(Ray ray) const; std::optional<IntersectionInfo> intersect(Ray ray) const;