mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(renderer): add roughness-based specular lighting to blocks
This commit is contained in:
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = true
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'air'
|
||||
name = 'air'
|
||||
roughness = 1.0
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'dirt'
|
||||
name = 'dirt'
|
||||
roughness = 1.0
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = true
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'grass'
|
||||
name = 'grass'
|
||||
roughness = 0.9
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'grass_block'
|
||||
name = 'grass_block'
|
||||
roughness = 0.9
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = false
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'leaf'
|
||||
name = 'leaf'
|
||||
roughness = 0.7
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = false
|
||||
is_transitional = false
|
||||
is_transparent = false
|
||||
name = 'log'
|
||||
name = 'log'
|
||||
roughness = 0.7
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'sand'
|
||||
name = 'sand'
|
||||
roughness = 0.8
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'snowy_grass_block'
|
||||
name = 'snowy_grass_block'
|
||||
roughness = 0.9
|
||||
@@ -7,4 +7,5 @@ is_liquid = false
|
||||
is_passable = false
|
||||
is_transitional = true
|
||||
is_transparent = false
|
||||
name = 'stone'
|
||||
name = 'stone'
|
||||
roughness = 0.75
|
||||
@@ -8,3 +8,4 @@ is_transparent = false
|
||||
is_discard = false
|
||||
is_blend = false
|
||||
is_transitional = false
|
||||
roughness = 1.0
|
||||
@@ -7,4 +7,5 @@ is_liquid = true
|
||||
is_passable = true
|
||||
is_transitional = false
|
||||
is_transparent = true
|
||||
name = 'water'
|
||||
name = 'water'
|
||||
roughness = 0.02
|
||||
@@ -4,6 +4,7 @@ in vec2 tc;
|
||||
in vec3 normal;
|
||||
in vec3 vert_pos;
|
||||
in vec4 FragPosLightSpace;
|
||||
in float roughness;
|
||||
flat in int tex_layer;
|
||||
out vec4 color;
|
||||
layout (binding = 0) uniform sampler2D shadowMap;
|
||||
@@ -12,9 +13,10 @@ layout (binding = 1) uniform sampler2DArray samp;
|
||||
uniform float ambientStrength;
|
||||
uniform vec3 sunlightColor;
|
||||
uniform vec3 sunlightDir;
|
||||
uniform vec3 cameraPos;
|
||||
uniform bool shader_on;
|
||||
uniform int shadowMode;
|
||||
|
||||
uniform float specularStrength;
|
||||
uniform float lightSizeUV;
|
||||
uniform float minRadius;
|
||||
uniform float maxRadius;
|
||||
@@ -271,17 +273,56 @@ void main(void) {
|
||||
|
||||
vec3 lightDir = normalize(-sunlightDir);
|
||||
|
||||
vec3 ambient = ambientStrength * sunlightColor;
|
||||
|
||||
vec3 norm = normalize(normal);
|
||||
|
||||
vec3 V =
|
||||
normalize(cameraPos - vert_pos);
|
||||
|
||||
vec3 H =
|
||||
normalize(lightDir + V);
|
||||
|
||||
vec3 ambient = ambientStrength * sunlightColor;
|
||||
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
|
||||
vec3 diffuse = diff * sunlightColor;
|
||||
|
||||
float r =
|
||||
clamp(roughness, 0.0, 1.0);
|
||||
|
||||
float shininess =
|
||||
mix(
|
||||
512.0,
|
||||
4.0,
|
||||
r
|
||||
);
|
||||
float ks =
|
||||
mix(
|
||||
0.8,
|
||||
0.02,
|
||||
r
|
||||
);
|
||||
|
||||
float spec = 0.0;
|
||||
|
||||
if(diff > 0.0)
|
||||
{
|
||||
spec =
|
||||
ks *
|
||||
pow(
|
||||
max(dot(norm,H),0.0),
|
||||
shininess
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
vec3 specular = spec * sunlightColor * specularStrength;
|
||||
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, norm, lightDir);
|
||||
|
||||
color = vec4((ambient + (1.0 - shadow) * (diffuse)) * objectColor.rgb, objectColor.a);
|
||||
color = vec4((ambient + (1.0 - shadow) * (diffuse)) * objectColor.rgb + (1.0-shadow) * specular, objectColor.a);
|
||||
|
||||
//color = varyingColor;
|
||||
}
|
||||
|
||||
@@ -4,11 +4,14 @@ layout (location = 0) in vec3 pos;
|
||||
layout (location = 1) in vec2 texCoord;
|
||||
layout (location = 2) in float layer;
|
||||
layout (location = 3) in vec3 aNormal;
|
||||
layout (location = 4) in float Roughness;
|
||||
|
||||
out vec2 tc;
|
||||
out vec3 normal;
|
||||
out vec3 vert_pos;
|
||||
flat out int tex_layer;
|
||||
out vec4 FragPosLightSpace;
|
||||
out float roughness;
|
||||
|
||||
mat4 buildRotateX(float rad);
|
||||
mat4 buildRotateY(float rad);
|
||||
@@ -28,7 +31,7 @@ void main(void) {
|
||||
tc = texCoord;
|
||||
|
||||
tex_layer = int(layer);
|
||||
|
||||
roughness = Roughness;
|
||||
normal = mat3(norm_matrix) * aNormal;
|
||||
FragPosLightSpace = lightSpaceMatrix * vec4(pos, 1.0);
|
||||
gl_Position = proj_matrix * viewPos;
|
||||
|
||||
Reference in New Issue
Block a user