New meshes and tangents
Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
@@ -21,7 +21,15 @@ struct Scene {
|
||||
uint lightsCount;
|
||||
};
|
||||
|
||||
vec3 directional_light = vec3(-1.0,-1.0,-1.0);
|
||||
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;
|
||||
@@ -31,17 +39,42 @@ layout(set = 0, binding = 1) uniform LightBuffer {
|
||||
layout(align = 16) Light lights[];
|
||||
} LightsBuffers;
|
||||
|
||||
// layout(set = 2, binding = 4) uniform sampler2D texSampler[];
|
||||
layout(set = 2, binding = 3) buffer MaterialBuffer {
|
||||
layout(align = 16) Material materials[];
|
||||
} MaterialBuffers;
|
||||
|
||||
layout(location = 0) in vec3 normal;
|
||||
layout(location = 1) in vec3 color;
|
||||
layout(location = 2) flat in Material material;
|
||||
layout(set = 2, binding = 4) uniform sampler2D texSampler[];
|
||||
|
||||
layout(location = 0) in vec2 uv;
|
||||
layout(location = 1) smooth in mat3 TBN;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
float intensity = ((dot(normalize(normal), normalize(directional_light)) +1)/2.0)+0.05;
|
||||
Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ];
|
||||
mat3 normalMatrix = transpose(inverse(mat3(PushConstants.render_matrix)));
|
||||
|
||||
// outColor = vec4(color * intensity, 1.0);
|
||||
outColor = vec4(color * intensity, 1.0);
|
||||
vec3 out_normal;
|
||||
// if(material.normalTexture == 0) {
|
||||
// out_normal = normalize(normalMatrix * TBN[2].xyz);
|
||||
// } else {
|
||||
vec3 sampled_normal = texture(texSampler[material.normalTexture], uv).rgb;
|
||||
sampled_normal = 2.0 * sampled_normal - vec3(1.0);
|
||||
out_normal = normalize(normalMatrix * TBN * sampled_normal);
|
||||
// }
|
||||
|
||||
|
||||
float intensity = dot(out_normal, normalize(directional_light)) + 0.2;
|
||||
|
||||
vec3 inColor;
|
||||
if(material.albedoTexture == 0) {
|
||||
inColor = material.baseColor.xyz;
|
||||
} else {
|
||||
inColor = texture(texSampler[material.albedoTexture], uv).xyz;
|
||||
}
|
||||
|
||||
// outColor = vec4(inColor * intensity, 1.0);
|
||||
// outColor = vec4(inColor, 1.0);
|
||||
// outColor = vec4(vec3(intensity), 1.0);
|
||||
outColor = vec4(out_normal, 1.0);
|
||||
}
|
||||
|
||||
+13
-17
@@ -15,8 +15,9 @@ struct Material {
|
||||
struct Vertex {
|
||||
vec4 position;
|
||||
vec4 normal;
|
||||
vec4 color;
|
||||
vec2 uv[2];
|
||||
vec4 tangent;
|
||||
vec4 bitangent; // No longer needed. // TODO remove
|
||||
};
|
||||
|
||||
struct Light {
|
||||
@@ -57,31 +58,26 @@ layout(set = 2, binding = 2) buffer IndexBuffer {
|
||||
uint indices[];
|
||||
} IndexBuffers[];
|
||||
|
||||
layout(set = 2, binding = 3) buffer MaterialBuffer {
|
||||
layout(align = 16) Material materials[];
|
||||
} MaterialBuffers;
|
||||
|
||||
layout(set = 2, binding = 4) uniform sampler2D texSampler[];
|
||||
|
||||
layout(location = 0) out vec3 normal;
|
||||
layout(location = 1) out vec3 color;
|
||||
layout(location = 2) out Material material;
|
||||
layout(location = 0) out vec2 uv;
|
||||
layout(location = 1) smooth out mat3 TBN;
|
||||
|
||||
void main()
|
||||
{
|
||||
material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ];
|
||||
|
||||
uint index = IndexBuffers[ PushConstants.indexBufferIndex ].indices[gl_VertexIndex];
|
||||
Vertex vertex = VertexBuffers[ PushConstants.vertexBufferIndex ].vertices[ index ];
|
||||
|
||||
color = texture(texSampler[material.albedoTexture], vertex.uv[0]).xyz;
|
||||
uv = vertex.uv[0];
|
||||
|
||||
if(material.normalTexture != 0) {
|
||||
normal = texture(texSampler[material.normalTexture], vertex.uv[0]).xyz;
|
||||
}
|
||||
else {
|
||||
normal = vertex.normal.xyz;
|
||||
}
|
||||
mat3 model = transpose(inverse(mat3(PushConstants.render_matrix)));
|
||||
|
||||
vec3 T = normalize(vec3(vertex.tangent));
|
||||
vec3 N = normalize(vec3(vertex.normal));
|
||||
vec3 B = normalize(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user