OpenGL works again, Vulkan can be switched to, fixed most of the vulkan validation errors, better shadows, soft shadows, emissive lighting, and multiple different opacity rendering methods
This commit is contained in:
parent
0d41f3e15b
commit
5b231d6920
54 changed files with 1102 additions and 268 deletions
|
|
@ -23,6 +23,9 @@ layout(set = 0, binding = 0) uniform sampler2D posSampler;
|
|||
layout(set = 0, binding = 1) uniform sampler2D albedoSampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D normalsSampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D pbrSampler;
|
||||
layout(set = 0, binding = 4) uniform sampler2D emissiveSampler;
|
||||
layout(set = 0, binding = 5) uniform sampler2D TranslucencySampler;
|
||||
layout(set = 0, binding = 6) uniform sampler2D OpacitySampler;
|
||||
|
||||
layout(scalar, set = 1, binding = 0) readonly buffer Lights {
|
||||
Light lights[];
|
||||
|
|
@ -32,6 +35,7 @@ layout(scalar, set = 2, binding = 0) uniform SceneInfo {
|
|||
float ambientLightIntensity;
|
||||
vec3 ambientLightColor;
|
||||
uint numLights;
|
||||
mat4 viewMatrix;
|
||||
} sceneInfo;
|
||||
|
||||
float distributionGGX(vec3 N, vec3 H, float roughness) {
|
||||
|
|
@ -126,6 +130,10 @@ void main() {
|
|||
vec3 normal = texture(normalsSampler, inTextCoord).rgb;
|
||||
vec3 worldPos = texture(posSampler, inTextCoord).rgb;
|
||||
vec3 pbr = texture(pbrSampler, inTextCoord).rgb;
|
||||
vec3 emissive = texture(emissiveSampler, inTextCoord).rgb;
|
||||
vec3 translucency = texture(TranslucencySampler, inTextCoord).rgb;
|
||||
float emissiveness = emissive.r;
|
||||
|
||||
|
||||
float roughness = pbr.g;
|
||||
float metallic = pbr.b;
|
||||
|
|
@ -146,9 +154,9 @@ void main() {
|
|||
}
|
||||
}
|
||||
vec3 ambient = sceneInfo.ambientLightColor * albedo * sceneInfo.ambientLightIntensity;
|
||||
vec3 color = ambient + Lo;
|
||||
outFragColor = vec4(Lo + ambient + vec3(emissiveness), 1.0f);
|
||||
|
||||
outFragColor = vec4(color, 1.0f);
|
||||
// outFragColor = vec4(color, 1.0f);
|
||||
if (length(normal) < 0.001) {
|
||||
outFragColor = vec4(albedo,1.0f);
|
||||
return;
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -27,7 +27,11 @@ layout(set = 0, binding = 0) uniform sampler2D posSampler;
|
|||
layout(set = 0, binding = 1) uniform sampler2D albedoSampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D normalsSampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D pbrSampler;
|
||||
layout(set = 0, binding = 4) uniform sampler2DArray shadowSampler;
|
||||
layout(set = 0, binding = 4) uniform sampler2D emissiveSampler;
|
||||
layout(set = 0, binding = 5) uniform sampler2D TranslucencySampler;
|
||||
layout(set = 0, binding = 6) uniform sampler2D OpacitySampler;
|
||||
layout(set = 0, binding = 7) uniform sampler2DArray shadowSampler;
|
||||
|
||||
|
||||
layout(scalar, set = 1, binding = 0) readonly buffer Lights {
|
||||
Light lights[];
|
||||
|
|
@ -62,7 +66,7 @@ float chebyshevUpperBound(vec2 moments, float t) {
|
|||
return p_max;
|
||||
}
|
||||
|
||||
float calcVisibility(vec4 worldPosition, uint cascadeIndex) {
|
||||
float calcVisibility(vec4 worldPosition, uint cascadeIndex, float ShadowBias) {
|
||||
vec4 shadowMapPosition = shadows.cascadeshadows[cascadeIndex].projViewMatrix * worldPosition;
|
||||
|
||||
shadowMapPosition.xyz /= shadowMapPosition.w;
|
||||
|
|
@ -76,14 +80,25 @@ float calcVisibility(vec4 worldPosition, uint cascadeIndex) {
|
|||
|
||||
if (uv.x < 0.0 || uv.x > 1.0 ||
|
||||
uv.y < 0.0 || uv.y > 1.0 ||
|
||||
depth < 0.0 || depth > 1.0) {
|
||||
depth < ShadowBias || depth > 1.0) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
vec2 moments = texture(shadowSampler, vec3(uv, cascadeIndex)).rg;
|
||||
float shadow = 0.0;
|
||||
|
||||
float visibility = chebyshevUpperBound(moments, depth);
|
||||
return visibility;
|
||||
vec2 texelSize = 1.0 / textureSize(shadowSampler, 0).rg;
|
||||
for(int x = -1; x <= 1; ++x)
|
||||
{
|
||||
for(int y = -1; y <= 1; ++y)
|
||||
{
|
||||
vec2 moments = texture(shadowSampler, vec3((uv + vec2(x, y) * texelSize), cascadeIndex)).rg;
|
||||
float visibility = chebyshevUpperBound(moments, depth);
|
||||
shadow += depth - ShadowBias > visibility ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= 9.0;
|
||||
|
||||
return 1 - shadow;
|
||||
}
|
||||
|
||||
float distributionGGX(vec3 N, vec3 H, float roughness) {
|
||||
|
|
@ -150,7 +165,7 @@ vec3 calculatePointLight(Light light, vec3 worldPos, vec3 V, vec3 N, vec3 F0, ve
|
|||
return (kD * albedo / PI + specular) * radiance * NdotL;
|
||||
}
|
||||
|
||||
vec3 calculateDirectionalLight(Light light, vec3 V, vec3 N, vec3 F0, vec3 albedo, float metallic, float roughness) {
|
||||
vec3 calculateDirectionalLight(Light light, vec3 V, vec3 N, vec3 F0, vec3 albedo, float metallic, float roughness, float translucency) {
|
||||
vec3 L = normalize(-light.position);
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
|
|
@ -170,7 +185,9 @@ vec3 calculateDirectionalLight(Light light, vec3 V, vec3 N, vec3 F0, vec3 albedo
|
|||
kD *= 1.0 - metallic;
|
||||
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
return (kD * albedo / PI + specular) * radiance * NdotL;
|
||||
vec3 shadowValue = (kD * albedo / PI + specular) * radiance * NdotL;
|
||||
vec3 lightValue = (kD * albedo / PI + specular) * radiance;
|
||||
return (shadowValue * (1 - translucency)) + (lightValue * translucency);
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
|
@ -179,6 +196,20 @@ void main() {
|
|||
vec4 worldPosW = texture(posSampler, inTextCoord);
|
||||
vec3 worldPos = worldPosW.xyz;
|
||||
vec3 pbr = texture(pbrSampler, inTextCoord).rgb;
|
||||
vec3 emissive = texture(emissiveSampler, inTextCoord).rgb;
|
||||
vec3 Opacity = texture(OpacitySampler, inTextCoord).rgb;
|
||||
vec3 translucency = texture(TranslucencySampler, inTextCoord).rgb;
|
||||
|
||||
float emissiveness = emissive.r;
|
||||
float translucencyf = translucency.r;
|
||||
|
||||
// outFragColor = vec4(emissive,1);
|
||||
// return;
|
||||
|
||||
float ShadowBias = 0.05f;
|
||||
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf/3.0;
|
||||
|
||||
float roughness = pbr.g;
|
||||
float metallic = pbr.b;
|
||||
|
|
@ -186,6 +217,8 @@ void main() {
|
|||
vec3 N = normalize(normal);
|
||||
vec3 V = normalize(sceneInfo.camPos - worldPos);
|
||||
|
||||
|
||||
|
||||
vec3 F0 = vec3(0.04);
|
||||
F0 = mix(F0, albedo, metallic);
|
||||
|
||||
|
|
@ -196,18 +229,19 @@ void main() {
|
|||
cascadeIndex = i + 1;
|
||||
}
|
||||
}
|
||||
float shadow = calcVisibility(vec4(worldPos, 1), cascadeIndex);
|
||||
float shadow = calcVisibility(vec4(worldPos, 1), cascadeIndex,ShadowBias);
|
||||
|
||||
vec3 Lo = vec3(0.0);
|
||||
for (uint i = 0; i < sceneInfo.numLights; i++) {
|
||||
Light light = lights.lights[i];
|
||||
if (light.directional == 1) {
|
||||
Lo += calculateDirectionalLight(light, V, N, F0, albedo, metallic, roughness) * shadow;
|
||||
Lo += calculateDirectionalLight(light, V, N, F0, albedo, metallic, roughness,translucencyf) * shadow;
|
||||
} else {
|
||||
Lo += calculatePointLight(light, worldPos, V, N, F0, albedo, metallic, roughness);
|
||||
}
|
||||
}
|
||||
vec3 ambient = sceneInfo.ambientLightColor * albedo * sceneInfo.ambientLightIntensity;
|
||||
if(emissive.x > 0 || emissive.y > 0 || emissive.z > 0) ambient = emissive;
|
||||
outFragColor = vec4(Lo + ambient, 1.0f);
|
||||
|
||||
if (DEBUG_SHADOWS == 1) {
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
layout(constant_id = 0) const int USE_AA = 0;
|
||||
|
||||
const float GAMMA_CONST = 0.4545;
|
||||
const float GAMMA_CONST = 0.8545;
|
||||
const float SPAN_MAX = 8.0;
|
||||
const float REDUCE_MIN = 1.0/128.0;
|
||||
const float REDUCE_MUL = 1.0/32.0;
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -10,17 +10,25 @@ layout(location = 4) in vec2 inTextCoords;
|
|||
|
||||
layout(location = 0) out vec4 outAlbedo;
|
||||
|
||||
|
||||
struct Material {
|
||||
vec4 diffuseColor;
|
||||
uint hasTexture;
|
||||
uint textureIdx;
|
||||
uint hasNormalMap;
|
||||
uint normalMapIdx;
|
||||
uint hasRoughMap;
|
||||
uint roughMapIdx;
|
||||
float roughnessFactor;
|
||||
float metallicFactor;
|
||||
vec4 diffuseColor; //16
|
||||
uint hasTexture; //20
|
||||
uint textureIdx; //24
|
||||
uint hasNormalMap; //28
|
||||
uint normalMapIdx; //32
|
||||
uint hasRoughMap; //36
|
||||
uint roughMapIdx; //40
|
||||
float roughnessFactor; //44
|
||||
float metallicFactor; //48
|
||||
vec4 emissiveColour; //64
|
||||
uint hasEmissiveMap; //68
|
||||
uint emissiveMapIdx; //72
|
||||
uint hasTranslucencyMap; //76
|
||||
uint translucencyMapIdx; //80
|
||||
float translucencyFactor; //84
|
||||
uint hasOpacityMap; //88
|
||||
uint OpacityMapIdx; //92
|
||||
float OpacityFactor; //96
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform{
|
||||
|
|
@ -36,13 +44,23 @@ layout(push_constant) uniform pc{
|
|||
void main()
|
||||
{
|
||||
|
||||
|
||||
Material material = matUniform.materials[push_constants.materialIdx];
|
||||
if(material.hasTexture == 1){
|
||||
vec4 texColor = texture(textSampler[material.textureIdx],inTextCoords);
|
||||
if(texColor.a < 0.4){discard;}
|
||||
outAlbedo = texColor;
|
||||
} else{
|
||||
outAlbedo = material.diffuseColor;
|
||||
}
|
||||
vec4 Opacity = vec4(outAlbedo.a,outAlbedo.a,outAlbedo.a,1);
|
||||
if(material.OpacityFactor != 1) Opacity = vec4(material.OpacityFactor, material.OpacityFactor, material.OpacityFactor, 1);
|
||||
if(material.hasOpacityMap > 0 && material.OpacityMapIdx < MAX_TEXTURES){
|
||||
Opacity = texture(textSampler[material.OpacityMapIdx], inTextCoords);
|
||||
}
|
||||
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf/3;
|
||||
if(opacityf < 0.4){discard;}
|
||||
|
||||
outAlbedo = vec4(outAlbedo.rgb, opacityf);
|
||||
}
|
||||
Binary file not shown.
|
|
@ -12,17 +12,29 @@ layout(location = 1) out vec4 outAlbedo ;
|
|||
layout(location = 0) out vec4 outPos;
|
||||
layout(location = 2) out vec4 outNormal;
|
||||
layout(location = 3) out vec4 outPBR;
|
||||
layout(location = 4) out vec4 outEmissive;
|
||||
layout(location = 5) out vec4 outTranslucency;
|
||||
layout(location = 6) out vec4 outOpacity;
|
||||
|
||||
struct Material {
|
||||
vec4 diffuseColor;
|
||||
uint hasTexture;
|
||||
uint textureIdx;
|
||||
uint hasNormalMap;
|
||||
uint normalMapIdx;
|
||||
uint hasRoughMap;
|
||||
uint roughMapIdx;
|
||||
float roughnessFactor;
|
||||
float metallicFactor;
|
||||
vec4 diffuseColor; //16
|
||||
uint hasTexture; //20
|
||||
uint textureIdx; //24
|
||||
uint hasNormalMap; //28
|
||||
uint normalMapIdx; //32
|
||||
uint hasRoughMap; //36
|
||||
uint roughMapIdx; //40
|
||||
float roughnessFactor; //44
|
||||
float metallicFactor; //48
|
||||
vec4 emissiveColour; //64
|
||||
uint hasEmissiveMap; //68
|
||||
uint emissiveMapIdx; //72
|
||||
uint hasTranslucencyMap; //76
|
||||
uint translucencyMapIdx; //80
|
||||
float translucencyFactor; //84
|
||||
uint hasOpacityMap; //88
|
||||
uint OpacityMapIdx; //92
|
||||
float OpacityFactor; //96
|
||||
};
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform {
|
||||
Material materials[];
|
||||
|
|
@ -56,6 +68,17 @@ void main()
|
|||
outAlbedo = material.diffuseColor;
|
||||
}
|
||||
|
||||
vec4 Opacity = vec4(outAlbedo.a,outAlbedo.a,outAlbedo.a,1);
|
||||
if(material.OpacityFactor != 1) Opacity = vec4(material.OpacityFactor, material.OpacityFactor, material.OpacityFactor, 1);
|
||||
if(material.hasOpacityMap > 0 && material.OpacityMapIdx < MAX_TEXTURES){
|
||||
Opacity = texture(textSampler[material.OpacityMapIdx], inTextCoords);
|
||||
}
|
||||
outOpacity = Opacity;
|
||||
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf/3;
|
||||
|
||||
outAlbedo = vec4(outAlbedo.rgb, opacityf);
|
||||
|
||||
if(outAlbedo.a < 0.5) discard;
|
||||
|
||||
|
|
@ -75,6 +98,18 @@ void main()
|
|||
metallicFactor = material.metallicFactor;
|
||||
}
|
||||
|
||||
vec4 emissive = material.emissiveColour;
|
||||
if (material.hasEmissiveMap > 0 && material.emissiveMapIdx < MAX_TEXTURES) {
|
||||
emissive = texture(textSampler[material.emissiveMapIdx], inTextCoords);
|
||||
}
|
||||
outEmissive = emissive;
|
||||
|
||||
vec4 Translucency = vec4(material.translucencyFactor,material.translucencyFactor,material.translucencyFactor,1);
|
||||
if(material.hasTranslucencyMap > 0 && material.translucencyMapIdx < MAX_TEXTURES){
|
||||
Translucency = texture(textSampler[material.translucencyMapIdx], inTextCoords);
|
||||
}
|
||||
outTranslucency = Translucency;
|
||||
|
||||
outPBR = vec4(ao, roughnessFactor, metallicFactor, 1.0f);
|
||||
|
||||
}
|
||||
Binary file not shown.
|
|
@ -11,15 +11,24 @@ layout(location = 4) in vec2 inTextCoords;
|
|||
layout(location = 0) out vec4 outAlbedo;
|
||||
|
||||
struct Material {
|
||||
vec4 diffuseColor;
|
||||
uint hasTexture;
|
||||
uint textureIdx;
|
||||
uint hasNormalMap;
|
||||
uint normalMapIdx;
|
||||
uint hasRoughMap;
|
||||
uint roughMapIdx;
|
||||
float roughnessFactor;
|
||||
float metallicFactor;
|
||||
vec4 diffuseColor; //16
|
||||
uint hasTexture; //20
|
||||
uint textureIdx; //24
|
||||
uint hasNormalMap; //28
|
||||
uint normalMapIdx; //32
|
||||
uint hasRoughMap; //36
|
||||
uint roughMapIdx; //40
|
||||
float roughnessFactor; //44
|
||||
float metallicFactor; //48
|
||||
vec4 emissiveColour; //64
|
||||
uint hasEmissiveMap; //68
|
||||
uint emissiveMapIdx; //72
|
||||
uint hasTranslucencyMap; //76
|
||||
uint translucencyMapIdx; //80
|
||||
float translucencyFactor; //84
|
||||
uint hasOpacityMap; //88
|
||||
uint OpacityMapIdx; //92
|
||||
float OpacityFactor; //96
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform{
|
||||
|
|
@ -37,9 +46,18 @@ void main()
|
|||
Material material = matUniform.materials[push_constants.materialIdx];
|
||||
if(material.hasTexture == 1){
|
||||
vec4 texColor = texture(textSampler[material.textureIdx],inTextCoords);
|
||||
if(texColor.a < 0.9){discard;}
|
||||
outAlbedo = texColor;
|
||||
} else{
|
||||
outAlbedo = material.diffuseColor;
|
||||
}
|
||||
vec4 Opacity = vec4(outAlbedo.a,outAlbedo.a,outAlbedo.a,1);
|
||||
if(material.OpacityFactor != 1) Opacity = vec4(material.OpacityFactor, material.OpacityFactor, material.OpacityFactor, 1);
|
||||
if(material.hasOpacityMap > 0 && material.OpacityMapIdx < MAX_TEXTURES){
|
||||
Opacity = texture(textSampler[material.OpacityMapIdx], inTextCoords);
|
||||
}
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf/3;
|
||||
if(opacityf < 0.9){discard;}
|
||||
|
||||
outAlbedo = vec4(outAlbedo.rgb, opacityf);
|
||||
}
|
||||
Binary file not shown.
|
|
@ -12,6 +12,9 @@ layout(location = 1) out vec4 outAlbedo ;
|
|||
layout(location = 0) out vec4 outPos;
|
||||
layout(location = 2) out vec4 outNormal;
|
||||
layout(location = 3) out vec4 outPBR;
|
||||
layout(location = 4) out vec4 outEmissive;
|
||||
layout(location = 5) out vec4 outTranslucency;
|
||||
layout(location = 6) out vec4 outOpacity;
|
||||
|
||||
const float bayerMatrix[16] = float[](
|
||||
0.0 / 16.0, 8.0 / 16.0, 2.0 / 16.0, 10.0 / 16.0,
|
||||
|
|
@ -21,15 +24,24 @@ const float bayerMatrix[16] = float[](
|
|||
);
|
||||
|
||||
struct Material {
|
||||
vec4 diffuseColor;
|
||||
uint hasTexture;
|
||||
uint textureIdx;
|
||||
uint hasNormalMap;
|
||||
uint normalMapIdx;
|
||||
uint hasRoughMap;
|
||||
uint roughMapIdx;
|
||||
float roughnessFactor;
|
||||
float metallicFactor;
|
||||
vec4 diffuseColor; //16
|
||||
uint hasTexture; //20
|
||||
uint textureIdx; //24
|
||||
uint hasNormalMap; //28
|
||||
uint normalMapIdx; //32
|
||||
uint hasRoughMap; //36
|
||||
uint roughMapIdx; //40
|
||||
float roughnessFactor; //44
|
||||
float metallicFactor; //48
|
||||
vec4 emissiveColour; //64
|
||||
uint hasEmissiveMap; //68
|
||||
uint emissiveMapIdx; //72
|
||||
uint hasTranslucencyMap; //76
|
||||
uint translucencyMapIdx; //80
|
||||
float translucencyFactor; //84
|
||||
uint hasOpacityMap; //88
|
||||
uint OpacityMapIdx; //92
|
||||
float OpacityFactor; //96
|
||||
};
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform {
|
||||
Material materials[];
|
||||
|
|
@ -67,6 +79,19 @@ void main()
|
|||
int y = int(gl_FragCoord.y) % Intensity;
|
||||
float threshold = bayerMatrix[y * Intensity + x];
|
||||
if(outAlbedo.a < threshold || outAlbedo.a < 0.05f) discard;*/
|
||||
|
||||
vec4 Opacity = vec4(outAlbedo.a,outAlbedo.a,outAlbedo.a,1);
|
||||
if(material.OpacityFactor != 1) Opacity = vec4(material.OpacityFactor, material.OpacityFactor, material.OpacityFactor, 1);
|
||||
if(material.hasOpacityMap > 0 && material.OpacityMapIdx < MAX_TEXTURES){
|
||||
Opacity = texture(textSampler[material.OpacityMapIdx], inTextCoords);
|
||||
}
|
||||
outOpacity = Opacity;
|
||||
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf/3;
|
||||
|
||||
outAlbedo = vec4(outAlbedo.rgb, opacityf);
|
||||
|
||||
if(outAlbedo.a < 0.75) discard;
|
||||
|
||||
|
||||
|
|
@ -86,6 +111,18 @@ void main()
|
|||
metallicFactor = material.metallicFactor;
|
||||
}
|
||||
|
||||
vec4 emissive = material.emissiveColour;
|
||||
if (material.hasEmissiveMap > 0 && material.emissiveMapIdx < MAX_TEXTURES) {
|
||||
emissive = texture(textSampler[material.emissiveMapIdx], inTextCoords);
|
||||
}
|
||||
outEmissive = emissive;
|
||||
|
||||
vec4 Translucency = vec4(material.translucencyFactor,material.translucencyFactor,material.translucencyFactor,1);
|
||||
if(material.hasTranslucencyMap > 0 && material.translucencyMapIdx < MAX_TEXTURES){
|
||||
Translucency = texture(textSampler[material.translucencyMapIdx], inTextCoords);
|
||||
}
|
||||
outTranslucency = Translucency;
|
||||
|
||||
outPBR = vec4(ao, roughnessFactor, metallicFactor, outAlbedo.a);
|
||||
|
||||
}
|
||||
Binary file not shown.
|
|
@ -10,18 +10,26 @@ layout(location = 4) in vec2 inTextCoords;
|
|||
|
||||
layout(location = 0) out vec4 outAlbedo;
|
||||
|
||||
struct Material{
|
||||
vec4 diffuseColor;
|
||||
uint hasTexture;
|
||||
uint textureIdx;
|
||||
uint hasNormalMap;
|
||||
uint normalMapIdx;
|
||||
uint hasRoughMap;
|
||||
uint roughMapIdx;
|
||||
float roughnessFactor;
|
||||
float metallicFactor;
|
||||
struct Material {
|
||||
vec4 diffuseColor; //16
|
||||
uint hasTexture; //20
|
||||
uint textureIdx; //24
|
||||
uint hasNormalMap; //28
|
||||
uint normalMapIdx; //32
|
||||
uint hasRoughMap; //36
|
||||
uint roughMapIdx; //40
|
||||
float roughnessFactor; //44
|
||||
float metallicFactor; //48
|
||||
vec4 emissiveColour; //64
|
||||
uint hasEmissiveMap; //68
|
||||
uint emissiveMapIdx; //72
|
||||
uint hasTranslucencyMap; //76
|
||||
uint translucencyMapIdx; //80
|
||||
float translucencyFactor; //84
|
||||
uint hasOpacityMap; //88
|
||||
uint OpacityMapIdx; //92
|
||||
float OpacityFactor; //96
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform{
|
||||
Material materials[];
|
||||
} matUniform;
|
||||
|
|
@ -37,9 +45,19 @@ void main()
|
|||
Material material = matUniform.materials[push_constants.materialIdx];
|
||||
if(material.hasTexture == 1){
|
||||
vec4 texColor = texture(textSampler[material.textureIdx],inTextCoords);
|
||||
if(texColor.a >= 0.9){discard;}
|
||||
outAlbedo = texColor;
|
||||
} else{
|
||||
outAlbedo = material.diffuseColor;
|
||||
}
|
||||
vec4 Opacity = vec4(outAlbedo.a,outAlbedo.a,outAlbedo.a,1);
|
||||
if(material.OpacityFactor != 1) Opacity = vec4(material.OpacityFactor, material.OpacityFactor, material.OpacityFactor, 1);
|
||||
if(material.hasOpacityMap > 0 && material.OpacityMapIdx < MAX_TEXTURES){
|
||||
Opacity = texture(textSampler[material.OpacityMapIdx], inTextCoords);
|
||||
}
|
||||
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf/3;
|
||||
if(opacityf >= 0.9){discard;}
|
||||
|
||||
outAlbedo = vec4(outAlbedo.rgb, opacityf);
|
||||
}
|
||||
Binary file not shown.
|
|
@ -12,6 +12,9 @@ layout(location = 1) out vec4 outAlbedo ;
|
|||
layout(location = 0) out vec4 outPos;
|
||||
layout(location = 2) out vec4 outNormal;
|
||||
layout(location = 3) out vec4 outPBR;
|
||||
layout(location = 4) out vec4 outEmissive;
|
||||
layout(location = 5) out vec4 outTranslucency;
|
||||
layout(location = 6) out vec4 outOpacity;
|
||||
|
||||
const float bayerMatrix[16] = float[](
|
||||
0.0 / 16.0, 8.0 / 16.0, 2.0 / 16.0, 10.0 / 16.0,
|
||||
|
|
@ -22,16 +25,26 @@ const float bayerMatrix[16] = float[](
|
|||
|
||||
|
||||
struct Material {
|
||||
vec4 diffuseColor;
|
||||
uint hasTexture;
|
||||
uint textureIdx;
|
||||
uint hasNormalMap;
|
||||
uint normalMapIdx;
|
||||
uint hasRoughMap;
|
||||
uint roughMapIdx;
|
||||
float roughnessFactor;
|
||||
float metallicFactor;
|
||||
vec4 diffuseColor; //16
|
||||
uint hasTexture; //20
|
||||
uint textureIdx; //24
|
||||
uint hasNormalMap; //28
|
||||
uint normalMapIdx; //32
|
||||
uint hasRoughMap; //36
|
||||
uint roughMapIdx; //40
|
||||
float roughnessFactor; //44
|
||||
float metallicFactor; //48
|
||||
vec4 emissiveColour; //64
|
||||
uint hasEmissiveMap; //68
|
||||
uint emissiveMapIdx; //72
|
||||
uint hasTranslucencyMap; //76
|
||||
uint translucencyMapIdx; //80
|
||||
float translucencyFactor; //84
|
||||
uint hasOpacityMap; //88
|
||||
uint OpacityMapIdx; //92
|
||||
float OpacityFactor; //96
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform {
|
||||
Material materials[];
|
||||
} matUniform;
|
||||
|
|
@ -64,6 +77,17 @@ void main()
|
|||
outAlbedo = material.diffuseColor;
|
||||
}
|
||||
|
||||
vec4 Opacity = vec4(outAlbedo.a,outAlbedo.a,outAlbedo.a,1);
|
||||
if(material.OpacityFactor != 1) Opacity = vec4(material.OpacityFactor, material.OpacityFactor, material.OpacityFactor, 1);
|
||||
if(material.hasOpacityMap > 0 && material.OpacityMapIdx < MAX_TEXTURES){
|
||||
Opacity = texture(textSampler[material.OpacityMapIdx], inTextCoords);
|
||||
}
|
||||
outOpacity = Opacity;
|
||||
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf/3;
|
||||
|
||||
outAlbedo = vec4(outAlbedo.rgb, opacityf);
|
||||
|
||||
if(outAlbedo.a >= 0.75 || outAlbedo.a < 0.05f) discard;
|
||||
|
||||
|
|
@ -83,6 +107,18 @@ void main()
|
|||
metallicFactor = material.metallicFactor;
|
||||
}
|
||||
|
||||
vec4 emissive = material.emissiveColour;
|
||||
if (material.hasEmissiveMap > 0 && material.emissiveMapIdx < MAX_TEXTURES) {
|
||||
emissive = texture(textSampler[material.emissiveMapIdx], inTextCoords);
|
||||
}
|
||||
outEmissive = emissive;
|
||||
|
||||
vec4 Translucency = vec4(material.translucencyFactor,material.translucencyFactor,material.translucencyFactor,1);
|
||||
if(material.hasTranslucencyMap > 0 && material.translucencyMapIdx < MAX_TEXTURES){
|
||||
Translucency = texture(textSampler[material.translucencyMapIdx], inTextCoords);
|
||||
}
|
||||
outTranslucency = Translucency;
|
||||
|
||||
outPBR = vec4(ao, roughnessFactor, metallicFactor, outAlbedo.a);
|
||||
|
||||
}
|
||||
Binary file not shown.
|
|
@ -9,17 +9,25 @@ layout (location = 1) in flat uint inMaterialIdx;
|
|||
layout(location = 0) out vec2 outFragColor;
|
||||
|
||||
struct Material {
|
||||
vec4 diffuseColor;
|
||||
uint hasTexture;
|
||||
uint textureIdx;
|
||||
uint hasNormalMap;
|
||||
uint normalMapIdx;
|
||||
uint hasRoughMap;
|
||||
uint roughMapIdx;
|
||||
float roughnessFactor;
|
||||
float metallicFactor;
|
||||
vec4 diffuseColor; //16
|
||||
uint hasTexture; //20
|
||||
uint textureIdx; //24
|
||||
uint hasNormalMap; //28
|
||||
uint normalMapIdx; //32
|
||||
uint hasRoughMap; //36
|
||||
uint roughMapIdx; //40
|
||||
float roughnessFactor; //44
|
||||
float metallicFactor; //48
|
||||
vec4 emissiveColour; //64
|
||||
uint hasEmissiveMap; //68
|
||||
uint emissiveMapIdx; //72
|
||||
uint hasTranslucencyMap; //76
|
||||
uint translucencyMapIdx; //80
|
||||
float translucencyFactor; //84
|
||||
uint hasOpacityMap; //88
|
||||
uint OpacityMapIdx; //92
|
||||
float OpacityFactor; //96
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler2D textSampler[MAX_TEXTURES];
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform {
|
||||
Material materials[];
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@ layout (location = 0) out vec2 outTextCoords;
|
|||
layout (location = 1) out flat uint outMaterialIdx;
|
||||
|
||||
layout(set = 0, binding = 0) uniform ProjUniforms {
|
||||
mat4 projViewMatrices[SHADOW_MAP_CASCADE_COUNT];
|
||||
mat4 projViewMatrices[SHADOW_MAP_CASCADE_COUNT];
|
||||
} projUniforms;
|
||||
|
||||
void main()
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
outTextCoords = inTextCoords[i];
|
||||
outMaterialIdx = inMaterialIdx[i];
|
||||
gl_Layer = gl_InvocationID;
|
||||
gl_Position = projUniforms.projViewMatrices[gl_InvocationID] * gl_in[i].gl_Position;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
outTextCoords = inTextCoords[i];
|
||||
outMaterialIdx = inMaterialIdx[i];
|
||||
gl_Layer = gl_InvocationID;
|
||||
gl_Position = projUniforms.projViewMatrices[gl_InvocationID] * gl_in[i].gl_Position;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
|
|
@ -7,5 +7,5 @@ layout(location = 1) out vec4 outColor;
|
|||
layout(set = 2, binding = 0) uniform samplerCube skyboxSampler;
|
||||
|
||||
void main() {
|
||||
outColor = texture(skyboxSampler, outTexCoords);// * vec4(0.0,0.05,0.1,1);
|
||||
outColor = texture(skyboxSampler, outTexCoords) * vec4(0.0,0.05,0.1,1);
|
||||
}
|
||||
Binary file not shown.
|
|
@ -14,5 +14,5 @@ void main() {
|
|||
outTexCoords = inPosition;
|
||||
mat4 skyView = mat4(mat3(uboView.view));
|
||||
vec4 pos = uboProj.proj * skyView * vec4(inPosition, 1.0);
|
||||
gl_Position = vec4(pos.xy, pos.w, pos.w);
|
||||
gl_Position = vec4(pos.xy, 0.0, pos.w);
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue