Refactor literally everything
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
in Varyings {
|
||||
layout(location = 0) vec3 positionVS;
|
||||
layout(location = 1) vec2 texCoord;
|
||||
layout(location = 2) vec3 normalVS;
|
||||
layout(location = 3) vec3 tangentVS;
|
||||
layout(location = 4) vec3 bitangentVS;
|
||||
layout(location = 0) flat uint instance;
|
||||
layout(location = 1) vec3 positionVS;
|
||||
layout(location = 2) vec2 texCoord;
|
||||
layout(location = 3) vec3 normalVS;
|
||||
layout(location = 4) vec3 tangentVS;
|
||||
layout(location = 5) vec3 bitangentVS;
|
||||
} var;
|
||||
|
||||
#include "main_common.glsl"
|
||||
@@ -78,13 +80,14 @@ vec4 texture2DAA(texture2D tex, vec2 texCoord) {
|
||||
return texture(sampler2D(tex, _Sampler), texCoord);
|
||||
}
|
||||
|
||||
#define MATERIAL _Materials[_Object.material]
|
||||
#define OBJECT _Object[var.instance]
|
||||
#define MATERIAL _Materials[uint(OBJECT.material)]
|
||||
|
||||
void main() {
|
||||
vec4 baseColorTexel = texture2DAA(_Textures[MATERIAL.baseColorTexture], var.texCoord);
|
||||
vec4 occlusionRoughnessMetallicTexel = texture2DAA(_Textures[MATERIAL.occlusionRoughnessMetallicTexture], var.texCoord);
|
||||
vec4 normalTexel = texture2DAA(_Textures[MATERIAL.normalTexture], var.texCoord);
|
||||
vec4 emissiveTexel = texture2DAA(_Textures[MATERIAL.emissiveTexture], var.texCoord);
|
||||
vec4 baseColorTexel = texture2DAA(_Textures[uint(MATERIAL.baseColorTexture)], var.texCoord);
|
||||
vec4 occlusionRoughnessMetallicTexel = texture2DAA(_Textures[uint(MATERIAL.occlusionRoughnessMetallicTexture)], var.texCoord);
|
||||
vec4 normalTexel = texture2DAA(_Textures[uint(MATERIAL.normalTexture)], var.texCoord);
|
||||
vec4 emissiveTexel = texture2DAA(_Textures[uint(MATERIAL.emissiveTexture)], var.texCoord);
|
||||
|
||||
vec3 baseColor = MATERIAL.baseColor * baseColorTexel.rgb;
|
||||
float occlusion = 1.0 + MATERIAL.occlusionTextureStrength * (occlusionRoughnessMetallicTexel.r - 1.0);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
layout(location = 0) in vec3 positionOS;
|
||||
layout(location = 1) in vec2 texCoord;
|
||||
@@ -8,29 +9,33 @@ layout(location = 2) in vec3 normalOS;
|
||||
layout(location = 3) in vec4 tangentOS;
|
||||
|
||||
out Varyings {
|
||||
layout(location = 0) vec3 positionVS;
|
||||
layout(location = 1) vec2 texCoord;
|
||||
layout(location = 2) vec3 normalVS;
|
||||
layout(location = 3) vec3 tangentVS;
|
||||
layout(location = 4) vec3 bitangentVS;
|
||||
layout(location = 0) flat uint instance;
|
||||
layout(location = 1) vec3 positionVS;
|
||||
layout(location = 2) vec2 texCoord;
|
||||
layout(location = 3) vec3 normalVS;
|
||||
layout(location = 4) vec3 tangentVS;
|
||||
layout(location = 5) vec3 bitangentVS;
|
||||
} var;
|
||||
|
||||
#include "main_common.glsl"
|
||||
|
||||
#define OBJECT _Object[gl_InstanceIndex]
|
||||
|
||||
void main() {
|
||||
vec3 positionWS = (_Object.matrixOStoWS * vec4(positionOS, 1.0)).xyz;
|
||||
vec3 positionWS = (OBJECT.matrixOStoWS * vec4(positionOS, 1.0)).xyz;
|
||||
vec3 positionVS = (_Global.matrixWStoVS * vec4(positionWS, 1.0)).xyz;
|
||||
vec4 positionCS = _Global.matrixVStoCS * vec4(positionVS, 1.0);
|
||||
|
||||
vec3 normalWS = normalize((_Object.matrixOStoWSNormal * vec4(normalOS, 0.0)).xyz);
|
||||
vec3 normalWS = normalize((OBJECT.matrixOStoWSNormal * vec4(normalOS, 0.0)).xyz);
|
||||
vec3 normalVS = normalize((_Global.matrixWStoVS * vec4(normalWS, 0.0)).xyz);
|
||||
|
||||
vec3 tangentWS = normalize((_Object.matrixOStoWSNormal * vec4(tangentOS.xyz, 0.0)).xyz);
|
||||
vec3 tangentWS = normalize((OBJECT.matrixOStoWSNormal * vec4(tangentOS.xyz, 0.0)).xyz);
|
||||
vec3 tangentVS = normalize((_Global.matrixWStoVS * vec4(tangentWS, 0.0)).xyz);
|
||||
|
||||
vec3 bitangentVS = tangentOS.w * normalize(cross(normalVS, tangentVS));
|
||||
|
||||
gl_Position = positionCS;
|
||||
var.instance = gl_InstanceIndex;
|
||||
var.positionVS = positionVS;
|
||||
var.texCoord = texCoord;
|
||||
var.normalVS = normalVS;
|
||||
|
||||
@@ -12,16 +12,24 @@ struct DirectionalLight {
|
||||
|
||||
struct Material {
|
||||
vec3 baseColor;
|
||||
uint baseColorTexture;
|
||||
vec3 emissive;
|
||||
uint emissiveTexture;
|
||||
float ior;
|
||||
float metallic;
|
||||
float normalScale;
|
||||
uint normalTexture;
|
||||
uint occlusionRoughnessMetallicTexture;
|
||||
float occlusionTextureStrength;
|
||||
float roughness;
|
||||
|
||||
uint16_t baseColorTexture;
|
||||
uint16_t emissiveTexture;
|
||||
uint16_t normalTexture;
|
||||
uint16_t occlusionRoughnessMetallicTexture;
|
||||
};
|
||||
|
||||
struct ObjectUniforms {
|
||||
mat4 matrixOStoWS;
|
||||
mat4 matrixOStoWSNormal;
|
||||
|
||||
uint16_t material;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0, scalar) uniform GlobalUniforms {
|
||||
@@ -47,11 +55,8 @@ layout(set = 0, binding = 3, scalar) readonly buffer Materials {
|
||||
layout(set = 0, binding = 4) uniform sampler _Sampler;
|
||||
layout(set = 0, binding = 5) uniform texture2D _Textures[];
|
||||
|
||||
// --- SET 1 --- PER OBJECT ----------------------------------------------------
|
||||
// --- SET 1 --- PER BATCH -----------------------------------------------------
|
||||
|
||||
layout(set = 1, binding = 0, scalar) uniform ObjectUniforms {
|
||||
mat4 matrixOStoWS;
|
||||
mat4 matrixOStoWSNormal;
|
||||
|
||||
uint material;
|
||||
} _Object;
|
||||
layout(set = 1, binding = 0, scalar) readonly buffer ObjectsUniforms {
|
||||
ObjectUniforms _Object[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user