added environment map reflections
This commit is contained in:
@@ -32,17 +32,26 @@ layout(location = 0) out vec4 outColor;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 position = texture(positionTexture, inUV).rgb;
|
vec4 gposition = texture(positionTexture, inUV);
|
||||||
vec3 normal = texture(normalTexture, inUV).rgb;
|
vec4 gnormal = texture(normalTexture, inUV);
|
||||||
vec3 albedo = texture(albedoTexture, inUV).rgb;
|
vec4 galbedo = texture(albedoTexture, inUV);
|
||||||
|
vec4 gspec = texture(specularTexture, inUV);
|
||||||
|
|
||||||
vec3 spec = texture(specularTexture, inUV).rgb;
|
vec3 position = gposition.xyz;
|
||||||
float metallicFactor = spec.b;
|
vec3 normal = gnormal.xyz;
|
||||||
float roughnessFactor = spec.g;
|
vec3 albedo = galbedo.xyz;
|
||||||
float ao = spec.r;
|
vec3 spec = gspec.xyz;
|
||||||
|
|
||||||
|
float metallicFactor = gspec.w;
|
||||||
|
float roughnessFactor = galbedo.w;
|
||||||
|
float ao = gnormal.w;
|
||||||
|
|
||||||
vec3 V = normalize(cameraPos - position);
|
vec3 V = normalize(cameraPos - position);
|
||||||
|
|
||||||
|
vec3 F0 = vec3(0.04);
|
||||||
|
F0 = mix(F0, albedo, metallicFactor);
|
||||||
|
float reflectance = max(max(F0.x,F0.y),F0.z);
|
||||||
|
|
||||||
vec3 Lo = vec3(0);
|
vec3 Lo = vec3(0);
|
||||||
for(int i = 0; i < PushConstants.lightCount; ++i)
|
for(int i = 0; i < PushConstants.lightCount; ++i)
|
||||||
{
|
{
|
||||||
@@ -54,9 +63,6 @@ void main()
|
|||||||
float attenuation = 1.0 / (distance * distance);
|
float attenuation = 1.0 / (distance * distance);
|
||||||
vec3 radiance = l.color.xyz * attenuation * l.intensity;
|
vec3 radiance = l.color.xyz * attenuation * l.intensity;
|
||||||
|
|
||||||
vec3 F0 = vec3(0.04);
|
|
||||||
F0 = mix(F0, albedo, metallicFactor);
|
|
||||||
|
|
||||||
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
|
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
|
||||||
float NDF = DistributionGGX(normal, H, roughnessFactor);
|
float NDF = DistributionGGX(normal, H, roughnessFactor);
|
||||||
float G = GeometrySmith(normal, V, L, roughnessFactor);
|
float G = GeometrySmith(normal, V, L, roughnessFactor);
|
||||||
@@ -70,14 +76,18 @@ void main()
|
|||||||
kD *= 1.0 - metallicFactor;
|
kD *= 1.0 - metallicFactor;
|
||||||
|
|
||||||
float NdotL = max(dot(normal, L), 0.0);
|
float NdotL = max(dot(normal, L), 0.0);
|
||||||
Lo += (kD * albedo / PI + specular) * radiance * NdotL;
|
Lo += clamp((kD * albedo / PI + specular) * radiance * NdotL, vec3(0), vec3(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 ambient = vec3(0.2) * albedo * ao;
|
vec3 ambient = vec3(0.2) * albedo;
|
||||||
|
|
||||||
vec3 color = ambient + Lo;
|
vec3 color = ambient + Lo;
|
||||||
// color += vec3();
|
|
||||||
color = color / (color + vec3(1.0));
|
|
||||||
|
|
||||||
|
//color = color + spec * reflectance;
|
||||||
|
color = mix(color, spec, reflectance);
|
||||||
|
|
||||||
|
//color = color / (color + vec3(1.0));
|
||||||
|
|
||||||
|
//outColor = vec4(color, 1.0);
|
||||||
outColor = vec4(color, 1.0);
|
outColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-7
@@ -43,6 +43,8 @@ layout(set = 0, binding = 1) uniform LightBuffer {
|
|||||||
layout(align = 16) Light lights[];
|
layout(align = 16) Light lights[];
|
||||||
} LightsBuffers;
|
} LightsBuffers;
|
||||||
|
|
||||||
|
layout (set = 0, binding = 2) uniform samplerCube skybox;
|
||||||
|
|
||||||
layout(set = 2, binding = 3) buffer MaterialBuffer {
|
layout(set = 2, binding = 3) buffer MaterialBuffer {
|
||||||
layout(align = 16) Material materials[];
|
layout(align = 16) Material materials[];
|
||||||
} MaterialBuffers;
|
} MaterialBuffers;
|
||||||
@@ -52,11 +54,12 @@ layout(set = 2, binding = 4) uniform sampler2D texSampler[];
|
|||||||
layout(location = 0) in vec2 uv;
|
layout(location = 0) in vec2 uv;
|
||||||
layout(location = 1) smooth in mat3 TBN;
|
layout(location = 1) smooth in mat3 TBN;
|
||||||
layout(location = 4) in vec4 outpos;
|
layout(location = 4) in vec4 outpos;
|
||||||
|
layout(location = 5) in vec3 cameraPos;
|
||||||
|
|
||||||
layout (location = 0) out vec4 gPosition;
|
layout (location = 0) out vec4 gPosition;
|
||||||
layout (location = 1) out vec3 gNormal;
|
layout (location = 1) out vec4 gNormal;
|
||||||
layout (location = 2) out vec3 gAlbedo;
|
layout (location = 2) out vec4 gAlbedo;
|
||||||
layout (location = 3) out vec3 gSpecular;
|
layout (location = 3) out vec4 gSpecular;
|
||||||
|
|
||||||
float near = 0.001;
|
float near = 0.001;
|
||||||
float far = 50.0;
|
float far = 50.0;
|
||||||
@@ -95,12 +98,19 @@ void main() {
|
|||||||
outSpecular.r = 1;
|
outSpecular.r = 1;
|
||||||
} else {
|
} else {
|
||||||
outSpecular = LinearToSRGB(texture(texSampler[material.metallicRoughnessTexture], uv)).xyz;
|
outSpecular = LinearToSRGB(texture(texSampler[material.metallicRoughnessTexture], uv)).xyz;
|
||||||
|
|
||||||
|
gNormal.w = outSpecular.x;
|
||||||
|
gAlbedo.w = outSpecular.y;
|
||||||
|
gSpecular.w = outSpecular.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
float depth = LinearizeDepth(gl_FragCoord.z) / far; // divide by far for demonstration
|
vec3 I = normalize(outpos.xyz - cameraPos);
|
||||||
|
vec3 R = reflect(I, normalize(outNormal));
|
||||||
|
//R = R * -1;
|
||||||
|
outSpecular = texture(skybox, R).rgb;
|
||||||
|
|
||||||
gPosition = outpos;
|
gPosition = outpos;
|
||||||
gNormal = outNormal;
|
gNormal.xyz = outNormal;
|
||||||
gAlbedo = outColor;
|
gAlbedo.xyz = outColor;
|
||||||
gSpecular = outSpecular;
|
gSpecular.xyz = outSpecular;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ layout(location = 0) out vec2 uv;
|
|||||||
layout(location = 1) smooth out mat3 TBN;
|
layout(location = 1) smooth out mat3 TBN;
|
||||||
|
|
||||||
layout(location = 4) out vec4 outpos;
|
layout(location = 4) out vec4 outpos;
|
||||||
|
layout(location = 5) out vec3 cameraPos;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@@ -83,4 +84,6 @@ void main()
|
|||||||
|
|
||||||
gl_Position = Camera.projection * Camera.view * PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0);
|
gl_Position = Camera.projection * Camera.view * PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0);
|
||||||
outpos = PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0);
|
outpos = PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0);
|
||||||
|
|
||||||
|
cameraPos = inverse(Camera.view)[3].xyz;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user