fixed inputs, added phong lighting
This commit is contained in:
parent
f172f1cf37
commit
70b68ad947
@ -11,6 +11,8 @@ in vec3 normal;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
const vec3 lightDir = normalize(vec3(0.5, -1, -1));
|
||||
|
||||
vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 normal, in vec3 lightDir, in vec3 halfVec){
|
||||
float diffuseComponent = max(dot(normal, lightDir), 0);
|
||||
float specularComponent = max(dot(halfVec, normal), 0);
|
||||
@ -19,7 +21,7 @@ vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 n
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 worldCoord = texCoord*worldSize + camera.xy;
|
||||
vec2 worldCoord = texCoord*worldSize + camera.xy*worldSize.y/screenSize;
|
||||
ivec2 nbRevolutions = ivec2(floor(worldCoord / worldSize));
|
||||
if(abs(mod(nbRevolutions.y, 2)) > 0.5)
|
||||
{
|
||||
@ -28,6 +30,7 @@ void main()
|
||||
}
|
||||
worldCoord = worldCoord - nbRevolutions*worldSize;
|
||||
vec3 texColor = texelFetch(colorMap, ivec2(worldCoord)).xyz;
|
||||
float pseudoLighting = 0.4+dot(normal, normalize(vec3(-0.5))); // TODO : use phong lighting
|
||||
outColor = vec4(texColor*pseudoLighting, 1.0);
|
||||
|
||||
vec3 lighting = phongLighting(texColor, vec3(0.5), 10, vec3(1), normal, lightDir, normalize(lightDir+vec3(0, 0, -1)));
|
||||
outColor = vec4(texColor*0.2 + 0.8*lighting, 1.0);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ out vec3 normal;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
texCoord = inTexCoord.xy;
|
||||
texCoord = vec2(inTexCoord.x/2, inTexCoord.y);
|
||||
normal = inNormal.xyz;
|
||||
gl_Position = mvp * vec4(inPosition*camera.z, 1.0);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
float clockAngle = atan2(relUV.y, relUV.x);
|
||||
float depthAngle = glm::length(relUV)*3.1416f*MAGIC_RATIO;
|
||||
float r = sin(depthAngle);
|
||||
return glm::vec3(r*cos(clockAngle), r*sin(clockAngle), cos(depthAngle));
|
||||
return glm::vec3(r*cos(clockAngle), r*sin(clockAngle), cos(depthAngle)-1);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
virtual void renderGL(Scene *scene);
|
||||
virtual void resizeGL(int w, int h);
|
||||
|
||||
void cameraMove(int x, int y) { m_camera.x -= x; m_camera.y += y; }
|
||||
void cameraMove(int x, int y) { m_camera.x -= x/m_camera.z; m_camera.y += y/m_camera.z; }
|
||||
void cameraZoom(int nbScrolls);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user