82 lines
2.4 KiB
GLSL
Executable File
82 lines
2.4 KiB
GLSL
Executable File
#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 fragBoundPos;
|
|
in vec3 fragBaryc;
|
|
/* does gles2 already includes it and considers it a redeclaration
|
|
in vec4 gl_FragCoord;
|
|
*/
|
|
|
|
in mat3 TBN;
|
|
|
|
uniform vec3 lightCol;
|
|
uniform vec3 lightPos;
|
|
uniform vec3 eyePos;
|
|
uniform float time;
|
|
|
|
|
|
//uniform vec3 diffuseColor;
|
|
uniform sampler2D colorMap; //campionatore 2d
|
|
uniform sampler2D normalMap; //campionatore 2d
|
|
|
|
out vec4 FragColor;
|
|
/*
|
|
int nScanLines = 16;
|
|
*/
|
|
float f_nScanLines = 16.0;
|
|
|
|
float PI = 3.14159265358979323846264338327950288;
|
|
|
|
|
|
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));
|
|
float attenuation = 1.0f / (0.01 * lightDistance);
|
|
|
|
float diffuseFactor = max(dot(aLuceDir, fragNormal), 0.0);
|
|
|
|
float specularFactor = pow(max(dot(rimbalzoDir, allOcchioDir), 0.0), 100.0f);
|
|
|
|
return attenuation * ( specularFactor + diffuseFactor);
|
|
}
|
|
|
|
void main()
|
|
{
|
|
|
|
vec4 texColor = texture(colorMap,frag_uv);
|
|
vec3 normalPix = texture(normalMap,frag_uv).rgb;
|
|
normalPix = normalPix * 2.0 - 1.0;
|
|
normalPix = normalize(TBN * normalPix);
|
|
|
|
float sinExp = 500.0 * (0.05 + 0.95 * sin( 3.14159265359 * 0.25 * (time * time)));
|
|
//float sinExp = 500.0;
|
|
float clampBound = 0.25;
|
|
|
|
vec3 result = 0.7 * vec3(1,0.5,1);
|
|
float locy = fragBoundPos.y;
|
|
locy = mod(locy, 1.0f / f_nScanLines);
|
|
float dist = abs(pow(locy - (time / f_nScanLines), 0.1));
|
|
float glowFac = (1.0 / clampBound) * abs(clamp(
|
|
pow(sin(dist * PI), sinExp), -clampBound, clampBound));
|
|
|
|
float scrDist = sin( PI * ( 1.0 - clamp(pow(gl_FragCoord.z , 100.0), 0.0, 1.0)));
|
|
result *= scrDist;
|
|
FragColor = vec4(result, 1.0f);
|
|
FragColor*=glowFac;
|
|
//FragColor = vec4(abs(fragNormal.x) * glowFac ,abs(fragNormal.y) * glowFac , abs(fragNormal.z) * glowFac , 1.0f * scrDist);
|
|
|
|
float baryThreshold = 0.05f;
|
|
if(fragBaryc.x > baryThreshold && fragBaryc.y > baryThreshold && fragBaryc.z > baryThreshold) {
|
|
FragColor = vec4(0.05 * FragColor.xyz, 0);
|
|
}
|
|
}
|