は、私は、計算シェーダを使用して光線追跡を学ぶためにこのサイトを次のようしています。私は彼の歩みを正しく追ってきたと思うが、私は間違った結果を得ている。私は自分の行列計算を間違えたと思う。透視投影OpenGLと計算シェーダ
追加情報として、[1]
、[[ここに画像の説明を入力] [1]!]:
視点のための私のコードは、上記tranformationsの
//Getting the perspective projection using glm::perspective
glm::mat4 projection = glm::perspective(60.0f, 1024.0f/768.0f, 1.0f, 2.0f);
//My Camera Position
glm::vec3 camPos=glm::vec3(3.0, 2.0, 7.0);
//My View matrix using glm::lookAt
glm::mat4 view = glm::lookAt(camPos, glm::vec3(0.0, 0.5, 0.0),glm::vec3(0.0, 1.0, 0.0));
//Calculating inverse of the view*projection
glm::mat4 inv = glm::inverse(view*projection);
//Calculating the rays from camera position to the corners of the frustum as detailed in the site.
glm::vec4 ray00=glm::vec4(-1, -1, 0, 1) * inv;
ray00 /= ray00.w;
ray00 -= glm::vec4(camPos,1.0);
glm::vec4 ray10 = glm::vec4(+1, -1, 0, 1) * inv;
ray10 /= ray10.w;
ray10 -= glm::vec4(camPos,1.0);
glm::vec4 ray01=glm::vec4(-1, 1, 0, 1) * inv;
ray01 /= ray01.w;
ray01 -= glm::vec4(camPos,1.0);
glm::vec4 ray11 = glm::vec4(+1, +1, 0, 1) * inv;
ray11 /= ray11.w;
ray11 -= glm::vec4(camPos,1.0);
の検索結果をprojection-
//Dispatch Shaders.
glDispatchCompute ((GLuint)1024.0/16, (GLuint)768.0f/8 , 1);
また、値を渡しています
//Querying the location for ray00 and assigning the value. Similarly for the rest
GLuint ray00Id = glGetUniformLocation(computeS, "ray00");
glUniform3f(ray00Id, ray00.x, ray00.y, ray00.z);
GLuint ray01Id = glGetUniformLocation(computeS, "ray01");
glUniform3f(ray01Id, ray01.x, ray01.y, ray01.z);
GLuint ray10Id = glGetUniformLocation(computeS, "ray10");
glUniform3f(ray10Id, ray10.x, ray10.y, ray10.z);
GLuint ray11Id = glGetUniformLocation(computeS, "ray11");
glUniform3f(ray11Id, ray11.x, ray11.y, ray11.z);
GLuint camId = glGetUniformLocation(computeS, "eye");
glUniform3f(camId, camPos.x, camPos.y, camPos.z);
次のアンサーはderhassの提案を使用しています。
私のイメージは今のようになります。 Latest Image
対応するlwjglコードを実行し、行列とベクトルを比較することをお勧めします。また、均一な場所(!= -1)の有効性をチェックするか、[明示的な場所](https://www.opengl.org/wiki/Layout_Qualifier_%28GLSL%29#Explicit_uniform_location)を使用してください – elect
私はすでに制服それらは正しいです。あなたの提案に従って、私は彼らに明示的な場所を与えましたが、結果は変わりません。私はlwjlコードを実行し、行列を比較しようとします。 – AlexanderTG