implemented light into cpp,
bug: everything is dark, need to calculate the normal matrix once in cpp and not for every pixel
This commit is contained in:
@@ -6,10 +6,11 @@ precision mediump float;
|
||||
|
||||
uniform mat3 n_matrix;
|
||||
uniform sampler2D texture;
|
||||
uniform mat4 m_matrix;
|
||||
|
||||
uniform struct Light {
|
||||
vec3 position;
|
||||
vec3 intensities;
|
||||
vec3 position;
|
||||
vec3 intensities;
|
||||
} light;
|
||||
|
||||
uniform bool b_transparent;
|
||||
@@ -20,13 +21,13 @@ varying vec3 v_normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
vec3 normal = normalize(n_matrix * v_normal);
|
||||
mat3 normalMatrix = transpose(inverse(mat3(m_matrix)));
|
||||
vec3 normal = normalize(n_matrix * v_normal);
|
||||
|
||||
vec3 surfaceToLight = light.position - v_position;
|
||||
|
||||
float brightness = dot(normal, surfaceToLight) / (length(surfaceToLight) * length(normal));
|
||||
brightness = clamp(brightness, 0, 1);
|
||||
vec3 surfaceToLight = light.position - v_position;
|
||||
|
||||
float brightness = dot(normal, surfaceToLight) / (length(surfaceToLight) * length(normal));
|
||||
brightness = clamp(brightness, 0, 1);
|
||||
|
||||
// Set fragment color from texture
|
||||
vec4 surfaceColor = vec4(texture2D(texture, v_texcoord));
|
||||
|
Reference in New Issue
Block a user