voxel biomes and CPU pushed blocks
This commit is contained in:
parent
7fda2614d7
commit
a0b00b0f1c
24 changed files with 1007 additions and 91 deletions
|
|
@ -0,0 +1,149 @@
|
|||
#version 450
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
|
||||
const int MAX_TEXTURES = 128;
|
||||
|
||||
|
||||
layout(location = 0) in vec4 inPos;
|
||||
layout(location = 1) in vec3 inNormal;
|
||||
layout(location = 2) in vec3 inTangent;
|
||||
layout(location = 3) in vec3 inBitangent;
|
||||
layout(location = 4) in vec2 inTextCoords;
|
||||
layout(location = 5) in mat4 viewMatrix;
|
||||
layout(location = 9) in flat uint MaterialID;
|
||||
|
||||
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;
|
||||
layout(location = 7) out vec4 outViewPos;
|
||||
|
||||
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
|
||||
float reflectiveness; //100
|
||||
float refractiveness; //104
|
||||
float Padding1; //108
|
||||
float Padding2; //112
|
||||
};
|
||||
layout(set = 2, binding = 0) readonly buffer MaterialUniform {
|
||||
Material materials[];
|
||||
} matUniform;
|
||||
layout(set = 3, binding = 0) uniform sampler2D textSampler[MAX_TEXTURES];
|
||||
|
||||
vec3 calcNormal(Material material, vec3 normal, vec2 textCoords, mat3 TBN)
|
||||
{
|
||||
vec3 newNormal = normal;
|
||||
if (material.hasNormalMap > 0 && material.normalMapIdx < MAX_TEXTURES)
|
||||
{
|
||||
newNormal = texture(textSampler[nonuniformEXT(material.normalMapIdx)], textCoords).rgb;
|
||||
newNormal = normalize(newNormal * 2.0 - 1.0);
|
||||
newNormal = normalize(TBN * newNormal);
|
||||
}
|
||||
return newNormal;
|
||||
}
|
||||
|
||||
layout(push_constant) uniform pc {
|
||||
layout(offset = 64) uint materialIdx;
|
||||
} push_constants;
|
||||
|
||||
void main()
|
||||
{
|
||||
outPos = inPos;
|
||||
|
||||
vec4 viewPos = vec4(viewMatrix * vec4(inPos.xyz, 1.0));
|
||||
outViewPos = viewPos;
|
||||
|
||||
Material material = matUniform.materials[MaterialID];
|
||||
|
||||
uint albedoTextureIndex = material.textureIdx;
|
||||
if (albedoTextureIndex >= MAX_TEXTURES) {
|
||||
outAlbedo = vec4(0.0,0.0,1.0,1.0);
|
||||
outOpacity = vec4(0.0,0.0,1.0,1.0);
|
||||
outNormal = vec4(0.0,0.0,1.0,1.0);
|
||||
outEmissive = vec4(0.0,0.0,1.0,1.0);
|
||||
outTranslucency = vec4(0.0,0.0,1.0,1.0);
|
||||
outPBR = vec4(0.0,0.0,1.0,1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (material.hasTexture == 1) {
|
||||
outAlbedo = texture(textSampler[nonuniformEXT(albedoTextureIndex)], inTextCoords);
|
||||
} else {
|
||||
outAlbedo = material.diffuseColor;
|
||||
}
|
||||
|
||||
vec4 Opacity = vec4(outAlbedo.a, outAlbedo.a, outAlbedo.a, 1.0);
|
||||
|
||||
if (material.OpacityFactor > 0.0 && material.OpacityFactor < 1.0) {
|
||||
Opacity = vec4(material.OpacityFactor, material.OpacityFactor, material.OpacityFactor, 1.0);
|
||||
}
|
||||
|
||||
if (material.hasOpacityMap > 0 && material.OpacityMapIdx < MAX_TEXTURES) {
|
||||
outOpacity = texture(textSampler[nonuniformEXT(material.OpacityMapIdx)], inTextCoords);
|
||||
} else {
|
||||
outOpacity = Opacity;
|
||||
}
|
||||
|
||||
Opacity = outOpacity;
|
||||
|
||||
float opacityf = Opacity.x + Opacity.y + Opacity.z;
|
||||
opacityf = opacityf / 3;
|
||||
|
||||
outAlbedo = vec4(outAlbedo.rgb, opacityf);
|
||||
|
||||
if(outAlbedo.a < 0.5) discard;
|
||||
|
||||
mat3 TBN = mat3(inTangent, inBitangent, inNormal);
|
||||
vec3 newNormal = calcNormal(material, inNormal, inTextCoords, TBN);
|
||||
|
||||
float ao = 0.5f;
|
||||
float roughnessFactor = 0.0f;
|
||||
float metallicFactor = 0.0f;
|
||||
|
||||
if (material.hasRoughMap > 0 && material.roughMapIdx < MAX_TEXTURES) {
|
||||
vec4 metRoughValue = texture(textSampler[nonuniformEXT(material.roughMapIdx)], inTextCoords);
|
||||
roughnessFactor = metRoughValue.g;
|
||||
metallicFactor = metRoughValue.b;
|
||||
} else {
|
||||
roughnessFactor = material.roughnessFactor;
|
||||
metallicFactor = material.metallicFactor;
|
||||
}
|
||||
|
||||
vec4 emissive = material.emissiveColour;
|
||||
if (material.hasEmissiveMap > 0 && material.emissiveMapIdx < MAX_TEXTURES) {
|
||||
emissive = texture(textSampler[nonuniformEXT(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[nonuniformEXT(material.translucencyMapIdx)], inTextCoords);
|
||||
}
|
||||
outTranslucency = Translucency;
|
||||
|
||||
float Refractiveness = material.refractiveness;
|
||||
float Reflectiveness = material.reflectiveness;
|
||||
|
||||
outNormal = vec4(newNormal, Refractiveness);
|
||||
outPBR = vec4(ao, roughnessFactor, metallicFactor, Reflectiveness);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue