ported the University CGI demo from WINDOWS + GLUT + GLEW + GLU + OpenGL 4 to LINUX WAYLAND + EGL + GLES 2 with minimal cuts
This commit is contained in:
60
resources/fragmentShader_gourard.glsl
Executable file
60
resources/fragmentShader_gourard.glsl
Executable file
@@ -0,0 +1,60 @@
|
||||
#version 300 es
|
||||
|
||||
/*this will affect all the float guys (float, vecN, matN )*/
|
||||
precision mediump float;
|
||||
|
||||
in vec3 fragPos; //vertice in coordinata del mondo
|
||||
in vec3 fragNormal;
|
||||
in vec2 frag_uv; //coordinate 2d di texure
|
||||
in vec3 fragBaryc;
|
||||
|
||||
in vec3 T;
|
||||
in vec3 B;
|
||||
in vec3 N;
|
||||
|
||||
uniform vec3 lightCol;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 eyePos;
|
||||
|
||||
//uniform vec3 diffuseColor;
|
||||
uniform sampler2D colorMap; //campionatore 2d
|
||||
uniform sampler2D normalMap; //campionatore 2d
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
|
||||
float illuminazione(vec3 lucePos, vec3 fragPos, vec3 eyePos, vec3 fragNormal){
|
||||
fragNormal = normalize(fragNormal);
|
||||
|
||||
vec3 aLuceDir = normalize(lucePos - fragPos);
|
||||
vec3 allOcchioDir = normalize(eyePos - fragPos);
|
||||
float lightDistance = length(lucePos - fragPos);
|
||||
vec3 rimbalzoDir = normalize(reflect(-aLuceDir,fragNormal));
|
||||
rimbalzoDir = reflect(-aLuceDir,fragNormal);
|
||||
float attenuation = 1.0f / (0.01 * lightDistance);
|
||||
|
||||
float diffuseFactor = max(dot(aLuceDir, fragNormal), 0.0);
|
||||
|
||||
float specularFactor = pow(max(dot(rimbalzoDir, allOcchioDir), 0.0), 500.0f);
|
||||
|
||||
return attenuation * ( specularFactor + diffuseFactor );
|
||||
//return attenuation * diffuseFactor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 Nor = normalize(N);
|
||||
vec3 Tan = normalize(T);
|
||||
vec3 Bit = normalize(B);
|
||||
mat3 TBN = mat3(Tan,Bit,Nor);
|
||||
vec4 texColor = texture(colorMap,frag_uv);
|
||||
vec3 normalPix = texture(normalMap,frag_uv).rgb;
|
||||
normalPix = normalPix * 2.0 - 1.0;
|
||||
normalPix = normalize(TBN * normalPix);
|
||||
normalPix = normalize(TBN * vec3(0,0,1));
|
||||
|
||||
vec3 result = texColor.rgb * illuminazione(lightPos, fragPos, eyePos, normalPix);
|
||||
//FragColor = vec4(normalPix, 1.0f);
|
||||
FragColor = vec4(texColor.xyz * illuminazione(lightPos, fragPos, eyePos, fragNormal), 1.0f);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user