[英]OpenGL Reflection shader showing only grey
我是OpenGL的新手,我一直在努力設置天空盒,最后由於這里的一些幫助而對其進行了修復,但是現在我已經嘗試通過編輯一些我發現的東西來設置反射着色器(因此球體將基於我的天空盒的立方體貼圖具有基本的反射效果)將不顯示任何顏色,而是如圖所示的灰色。 http://i.imgur.com/Th56Phg.png
我沒有運氣,這是我的着色器代碼:
頂點着色器
#version 330 core
attribute vec3 position;
attribute vec2 texCoord;
attribute vec3 normal;
out vec3 Normal;
out vec3 Position;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 transform;
void main()
{
gl_Position = transform * vec4(position, 1.0);
Normal = mat3(transpose(inverse(model))) * normal;
Position = vec3(model * vec4(position, 1.0f));
}
片段着色器
#version 330 core
in vec3 Normal;
in vec3 Position;
out vec4 color;
uniform vec3 cameraPos;
uniform samplerCube skybox;
void main()
{
vec3 I = normalize(Position - cameraPos);
vec3 R = reflect(I, normalize(Normal));
color = texture(skybox, R);
}
最后這是我的用法:
glm::mat4 model;
glm::mat4 view = camera.GetViewProjection();
glm::mat4 projection = glm::perspective(70.0f, (float)1600 / (float)1200, 0.1f, 1000.0f);
glUniformMatrix4fv(glGetUniformLocation(refShader.getProg(), "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(refShader.getProg(), "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(refShader.getProg(), "projection"), 1, GL_FALSE, glm::value_ptr(projection));
glUniform3f(glGetUniformLocation(refShader.getProg(), "cameraPos"), camera.getPos().x, camera.getPos().y, camera.getPos().z);
glActiveTexture(GL_TEXTURE3);
glUniform1i(glGetUniformLocation(refShader.getProg(), "skybox"), 3);
shader.Bind();
texture.Bind(0);
shader.Update(transformCube, camera);
cubeMesh.Draw();
glBindTexture(GL_TEXTURE_CUBE_MAP, skyboxTexture);
refShader.Bind();
refShader.Update(transform, camera);
sphereMesh.Draw();
這種操作順序是錯誤的:
glActiveTexture(GL_TEXTURE3);
glUniform1i(glGetUniformLocation(refShader.getProg(), "skybox"), 3);
shader.Bind();
制服是GL中每個程序的狀態,並且glUniform*()
調用始終會影響當前使用的程序的制服。 您似乎試圖在綁定程序之前設置此統一性,因此它將失敗,並且該程序中的統一性仍將保持默認值0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.