提示画像ですが座標(0,50,-1)に座標にポイントライトがあるのですがこれを使って立方体に光を当てたいのですがなぜか立方体の下から光が当たってしまいます。これはなぜでしょうか?立方体の位置は(0,0,-1)です。
参考サイト: https://learnopengl.com/Lighting/Light-casters
Fragment Shader
/*######################################################################### # ###########################################################################*/ #version 420 //#extension GL_ARB_explicit_uniform_location : require layout(location = 3) in vec3 vPosition; layout(location = 4) in vec2 vUV; layout(location = 5) in vec3 vNormal; struct Material { sampler2D texture; vec3 specular; float shininess; }; struct Light { vec3 position; vec3 ambient; vec3 diffuse; vec3 specular; float constant; float linear; float quadratic; }; uniform Material material; //マテリアル uniform Light light; //ライト uniform vec3 uViewPosition; //カメラ座標 out vec4 fragment; void main() { // ambient vec3 ambient = light.ambient * texture(material.texture,vUV).rgb; // diffuse vec3 norm = normalize(vNormal); vec3 lightDir = normalize(-light.position - vPosition); float diff = max(dot(norm, lightDir), 0.0); vec3 diffuse = light.diffuse * diff * texture(material.texture,vUV).rgb; // specular vec3 viewDir = normalize(uViewPosition - vPosition); vec3 reflectDir = reflect(-lightDir, norm); float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); vec3 specular = light.specular * spec * material.specular; float distance = length(light.position - vPosition); float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance)); ambient *= attenuation; diffuse *= attenuation; specular *= attenuation; vec3 result = ambient + diffuse + specular; fragment = vec4(result, 1.0); }
Main.cpp
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Cube cube.shader->setEnable(); cube.setPosition(cubePos); cube.setScale(glm::vec3(25, 25, 25)); cube.shader->setUniform3f("light.position", lightPos); cube.shader->setUniform3f("light.ambient", glm::vec3( 0.2f, 0.2f, 0.2f)); cube.shader->setUniform3f("light.diffuse", glm::vec3( 0.5f, 0.5f, 0.5f)); cube.shader->setUniform3f("light.specular", glm::vec3(100.0f, 100.0f, 100.0f)); cube.shader->setUniform1f("light.constant", 1.0f); cube.shader->setUniform1f("light.linear", 0.000009f); cube.shader->setUniform1f("light.quadratic", 0.00032f); cube.shader->setUniform3f("material.specular", glm::vec3(1,1,1)); cube.shader->setUniform1f("material.shininess", 64.0f); cube.shader->setUniform3f("uViewPosition", FrameWork::Camera::getPosition()); cube.Renderer(); cube.shader->setDisable(); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
あなたの回答
tips
プレビュー