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

@@ -11,20 +11,16 @@ uniform vec4 u_sunAmbientColor;
uniform sampler2D u_albedoTexture;
void main() {
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
//gl_FragColor = u_customColor * vec4(v_finalColor, 1.0) * texture2D(u_albedoTexture, v_texcoord);
//gl_FragColor = vec4(v_finalColor, 1.0) * texture2D(u_albedoTexture, v_texcoord);
//gl_FragColor = texture2D(u_albedoTexture, v_texcoord);
//gl_FragColor = vec4( v_normal, 1.0 );
//gl_FragColor = texture2D(u_albedoTexture, v_texcoord);
// !!! NO AREF
// vec3 color = texture2D(u_albedoTexture, v_texcoord).rgb * v_finalColor;
vec3 color = texture2D(u_albedoTexture, v_texcoord).rgb;
color = color * ( u_sunAmbientColor.rgb + v_finalColor.x );
color = color + v_finalColor.y;
//vec3 color = texture2D(u_albedoTexture, v_texcoord).rgb;
//color = color * ( u_sunAmbientColor.rgb + v_finalColor.x );
//color = color + v_finalColor.y;
vec3 color = texture2D(u_albedoTexture, v_texcoord).rgb * v_finalColor;
gl_FragColor = vec4(color.x, color.y, color.z, 1.0);
}

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);
}

View File

@@ -0,0 +1,63 @@
#version 120
attribute vec3 a_position;
attribute vec3 a_normal;
attribute vec2 a_texcoord;
attribute vec4 a_boneIds;
attribute vec4 a_weights;
varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_texcoord;
varying vec3 v_finalColor;
uniform mat4 u_modelMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_modelViewProjection;
uniform vec4 u_sunDirection;
uniform vec4 u_sunColor;
uniform vec4 u_sunAmbientColor;
uniform vec4 u_cameraPos;
uniform mat4 u_boneMatrices[128];
// #TODO: should use own uniforms
#define u_ligthPosition u_sunDirection.xyz
#define u_ligthRadius u_sunDirection.w
// Calculate blinn-phong per-vertex lighting
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 );
float lightlength = length( lightPos - worldPos );
float attenuation = max( 0.0, 1.0 - lightlength / u_ligthRadius );
diff = diff * attenuation;
spec = spec * attenuation;
return u_sunAmbientColor.rgb + (u_sunColor.rgb * diff) + (u_sunColor.rgb * spec);
}
void main() {
// calculate bone transform
mat4 skinMatrix = a_weights.x * u_boneMatrices[ int( a_boneIds.x ) ]
+ a_weights.y * u_boneMatrices[ int( a_boneIds.y ) ]
+ a_weights.z * u_boneMatrices[ int( a_boneIds.z ) ]
+ a_weights.w * u_boneMatrices[ int( a_boneIds.w ) ];
// Position
v_position = vec3( skinMatrix * vec4( a_position, 1.0 ) );
v_position = vec3( u_modelMatrix * vec4( v_position, 1.0 ) );
v_normal = vec3( mat3(u_modelMatrix) * a_normal );
v_texcoord = a_texcoord;
v_finalColor = CalcPhongLighting( v_position, v_normal, u_ligthPosition );
gl_Position = u_projectionMatrix * u_viewMatrix * vec4( v_position, 1.0 );
}