Multiple Demo Changes

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2021-07-25 10:48:35 +02:00
parent f9018c9878
commit 7e25e7198d
13 changed files with 1009 additions and 33 deletions
Binary file not shown.
+112
View File
@@ -0,0 +1,112 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
#include "shaders://_builtins/constants.glsl"
#include "shaders://_builtins/srgb_ops.glsl"
#include "shaders://_builtins/PBR.glsl"
#include "shaders://_builtins/types.glsl"
struct Light {
vec3 color;
uint intensity;
};
struct Scene {
uint lightsCount;
};
vec3 directional_light = vec3(1.0);
layout( push_constant ) uniform constants
{
mat4 render_matrix;
uint indexBufferIndex;
uint vertexBufferIndex;
uint materialBufferIndex;
} PushConstants;
layout(set = 0, binding = 0) uniform SceneData {
layout(align = 16) Scene mesh;
} SceneBuffers[];
layout(set = 0, binding = 1) uniform LightBuffer {
layout(align = 16) Light lights[];
} LightsBuffers;
layout (set = 0, binding = 2) uniform samplerCube skybox;
layout(set = 2, binding = 3) buffer MaterialBuffer {
layout(align = 16) Material materials[];
} MaterialBuffers;
layout(set = 2, binding = 4) uniform sampler2D texSampler[];
layout(location = 0) in vec2 uv;
layout(location = 1) smooth in mat3 TBN;
layout(location = 4) in vec4 outpos;
layout(location = 5) in vec3 cameraPos;
layout (location = 0) out vec4 gPosition;
layout (location = 1) out vec4 gNormal;
layout (location = 2) out vec4 gAlbedo;
layout (location = 3) out vec4 gSpecular;
void main() {
Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ];
vec3 outNormal;
if(material.normalTexture == 0) {
outNormal = TBN[2].xyz;
} else {
vec3 sampled_normal = LinearToSRGB(texture(texSampler[material.normalTexture], uv)).rgb;
sampled_normal = 2.0 * sampled_normal - vec3(1.0);
outNormal = normalize(TBN * sampled_normal);
}
//float intensity = dot(outNormal, normalize(directional_light)) + 0.2;
vec3 outColor;
if(material.albedoTexture == 0) {
outColor = material.baseColor.xyz;
} else {
outColor = texture(texSampler[material.albedoTexture], uv).xyz;
}
// outColor = vec3(1.0, 0.0, 0.0);
vec3 outSpecular;
if(material.metallicRoughnessTexture == 0) {
outSpecular.b = material.metallicFactor;
outSpecular.g = material.roughnessFactor;
outSpecular.r = 1.0;
} else {
outSpecular = LinearToSRGB(texture(texSampler[material.metallicRoughnessTexture], uv)).xyz;
}
float metallicFactor = outSpecular.z;
float roughnessFactor = outSpecular.y;
float ao = outSpecular.x;
gNormal.w = ao;
gAlbedo.w = roughnessFactor;
gPosition.w = metallicFactor;
float reflectance = 1.0 - roughnessFactor;
gSpecular.w = reflectance;
vec3 I = normalize(outpos.xyz - cameraPos);
vec3 R = reflect(I, normalize(outNormal));
//R = R * -1;
outSpecular = texture(skybox, R).rgb;
if(material.emissiveTexture != 0) {
gSpecular.w = 1.0;
outSpecular += texture(texSampler[material.emissiveTexture], uv).rgb * material.emissiveFactor.xyz;
}
gPosition.xyz = outpos.xyz;
gNormal.xyz = outNormal;
gAlbedo.xyz = outColor;
gSpecular.xyz = outSpecular;
}
+89
View File
@@ -0,0 +1,89 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
struct Material {
vec4 baseColor;
uint albedoTexture;
uint normalTexture;
float metallicFactor;
float roughnessFactor;
uint metallicRoughnessTexture;
};
struct Vertex {
vec4 position;
vec4 normal;
vec2 uv[2];
vec4 tangent;
vec4 bitangent; // No longer needed. // TODO remove
};
struct Light {
vec3 color;
uint intensity;
};
struct Scene {
uint lightsCount;
};
struct Mesh {
uint asd;
};
layout( push_constant ) uniform constants
{
mat4 render_matrix;
uint indexBufferIndex;
uint vertexBufferIndex;
uint materialBufferIndex;
} PushConstants;
layout(set = 1, binding = 0) uniform CameraParam {
mat4 projection;
mat4 view;
} Camera;
layout(set = 2, binding = 0) buffer MeshBuffer {
layout(align = 16) Mesh mesh;
} MeshBuffers[];
layout(set = 2, binding = 1) buffer VertexBuffer {
layout(align = 16) Vertex vertices[];
} VertexBuffers[];
layout(set = 2, binding = 2) buffer IndexBuffer {
uint indices[];
} IndexBuffers[];
layout(set = 2, binding = 4) uniform sampler2D texSampler[];
layout(location = 0) out vec2 uv;
layout(location = 1) smooth out mat3 TBN;
layout(location = 4) out vec4 outpos;
layout(location = 5) out vec3 cameraPos;
void main()
{
uint index = IndexBuffers[ PushConstants.indexBufferIndex ].indices[gl_VertexIndex];
Vertex vertex = VertexBuffers[ PushConstants.vertexBufferIndex ].vertices[ index ];
uv = vertex.uv[0];
mat3 model = transpose(inverse(mat3(PushConstants.render_matrix)));
vec3 T = normalize(model * vec3(vertex.tangent));
vec3 N = normalize(model * vec3(vertex.normal));
vec3 B = normalize(model * vec3(vertex.bitangent));
/* T = normalize(T - dot(T, N) * N); // Re-orthoganize T with respect to N */
/* vec3 B = normalize(cross(N, T)); */
TBN = mat3(T, B, N);
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);
cameraPos = inverse(Camera.view)[3].xyz;
}
+9 -5
View File
@@ -65,11 +65,14 @@ void main() {
//float intensity = dot(outNormal, normalize(directional_light)) + 0.2;
vec3 outColor;
vec4 outColor;
if(material.albedoTexture == 0) {
outColor = material.baseColor.xyz;
outColor = material.baseColor;
} else {
outColor = texture(texSampler[material.albedoTexture], uv).xyz;
outColor = texture(texSampler[material.albedoTexture], uv);
}
if(outColor.a < 0.5) {
discard;
}
vec3 outSpecular;
@@ -89,7 +92,8 @@ void main() {
gAlbedo.w = roughnessFactor;
gPosition.w = metallicFactor;
float reflectance = 1.0 - roughnessFactor;
// float reflectance = roughnessFactor * metallicFactor;
float reflectance = 1 - roughnessFactor;
gSpecular.w = reflectance;
vec3 I = normalize(outpos.xyz - cameraPos);
@@ -105,6 +109,6 @@ void main() {
gPosition.xyz = outpos.xyz;
gNormal.xyz = outNormal;
gAlbedo.xyz = outColor;
gAlbedo.xyz = outColor.xyz;
gSpecular.xyz = outSpecular;
}