This commit is contained in:
2026-03-07 07:48:16 +03:00
parent a998771486
commit 95daf12fc5
48 changed files with 4613 additions and 66 deletions

View File

@@ -23,20 +23,21 @@ uniform vec4 u_cameraPos;
#define u_ligthRadius u_sunDirection.w
// Calculate blinn-phong per-vertex lighting
float CalcPhongLighting( vec3 worldPos, vec3 normal, vec3 lightPos ) {
vec3 CalcPhongLighting( vec3 worldPos, vec3 normal, vec3 lightPos ) {
vec3 lightDir = normalize( lightPos - worldPos );
vec3 viewDir = normalize( u_cameraPos.xyz - worldPos );
vec3 halfVec = normalize( lightDir + viewDir );
float diff = max( dot( normal, lightDir ), 0.0 );
float spec = pow( max( dot( normal, halfVec ), 0.0 ), 32.0 );
v_finalColor.x = diff;
float lightlength = length( lightPos - worldPos );
float attenuation = max( 0.0, 1.0 - lightlength / u_ligthRadius );
float spec = pow( max( dot( normal, halfVec ), 0.0 ), 128.0 ) * 1.0;
diff = diff * attenuation;
spec = spec * attenuation;
v_finalColor.y = spec;
return diff + spec;
return u_sunAmbientColor.rgb + (u_sunColor.rgb * diff) + (u_sunColor.rgb * spec);
}
void main() {
@@ -44,10 +45,7 @@ void main() {
v_normal = vec3( mat3(u_modelMatrix) * a_normal );
v_texcoord = a_texcoord;
CalcPhongLighting( v_position, v_normal, u_ligthPosition );
//v_finalColor = u_sunAmbientColor.rgb + CalcPhongLighting( v_position, v_normal, u_ligthPosition );
v_finalColor = CalcPhongLighting( v_position, v_normal, u_ligthPosition );
gl_Position = u_modelViewProjection * vec4(a_position, 1);
}