We be kinda rendering
This commit is contained in:
35
destrum/assets_src/shaders/bindless.glsl
Normal file
35
destrum/assets_src/shaders/bindless.glsl
Normal file
@@ -0,0 +1,35 @@
|
||||
#extension GL_EXT_nonuniform_qualifier : enable
|
||||
|
||||
layout (set = 0, binding = 0) uniform texture2D textures[];
|
||||
layout (set = 0, binding = 0) uniform texture2DMS texturesMS[];
|
||||
layout (set = 0, binding = 0) uniform textureCube textureCubes[];
|
||||
layout (set = 0, binding = 0) uniform texture2DArray textureArrays[];
|
||||
layout (set = 0, binding = 1) uniform sampler samplers[];
|
||||
|
||||
#define NEAREST_SAMPLER_ID 0
|
||||
#define LINEAR_SAMPLER_ID 1
|
||||
#define SHADOW_SAMPLER_ID 2
|
||||
|
||||
vec4 sampleTexture2DNearest(uint texID, vec2 uv) {
|
||||
return texture(nonuniformEXT(sampler2D(textures[texID], samplers[NEAREST_SAMPLER_ID])), uv);
|
||||
}
|
||||
|
||||
vec4 sampleTexture2DMSNearest(uint texID, ivec2 p, int s) {
|
||||
return texelFetch(nonuniformEXT(sampler2DMS(texturesMS[texID], samplers[NEAREST_SAMPLER_ID])), p, s);
|
||||
}
|
||||
|
||||
vec4 sampleTexture2DLinear(uint texID, vec2 uv) {
|
||||
return texture(nonuniformEXT(sampler2D(textures[texID], samplers[LINEAR_SAMPLER_ID])), uv);
|
||||
}
|
||||
|
||||
vec4 sampleTextureCubeNearest(uint texID, vec3 p) {
|
||||
return texture(nonuniformEXT(samplerCube(textureCubes[texID], samplers[NEAREST_SAMPLER_ID])), p);
|
||||
}
|
||||
|
||||
vec4 sampleTextureCubeLinear(uint texID, vec3 p) {
|
||||
return texture(nonuniformEXT(samplerCube(textureCubes[texID], samplers[LINEAR_SAMPLER_ID])), p);
|
||||
}
|
||||
|
||||
float sampleTextureArrayShadow(uint texID, vec4 p) {
|
||||
return texture(nonuniformEXT(sampler2DArrayShadow(textureArrays[texID], samplers[SHADOW_SAMPLER_ID])), p);
|
||||
}
|
||||
19
destrum/assets_src/shaders/materials.glsl
Normal file
19
destrum/assets_src/shaders/materials.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef MATERIALS_GLSL
|
||||
#define MATERIALS_GLSL
|
||||
|
||||
#extension GL_EXT_buffer_reference : require
|
||||
|
||||
struct MaterialData {
|
||||
vec4 baseColor;
|
||||
vec4 metallicRoughnessEmissive;
|
||||
uint diffuseTex;
|
||||
uint normalTex;
|
||||
uint metallicRoughnessTex;
|
||||
uint emissiveTex;
|
||||
};
|
||||
|
||||
layout (buffer_reference, std430) readonly buffer MaterialsBuffer {
|
||||
MaterialData data[];
|
||||
} materialsBuffer;
|
||||
|
||||
#endif // MATERIALS_GLSL
|
||||
125
destrum/assets_src/shaders/mesh.frag
Normal file
125
destrum/assets_src/shaders/mesh.frag
Normal file
@@ -0,0 +1,125 @@
|
||||
#version 460
|
||||
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#include "bindless.glsl"
|
||||
#include "scene_data.glsl"
|
||||
#include "mesh_pcs.glsl"
|
||||
|
||||
layout (location = 0) in vec3 inPos;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inNormal;
|
||||
layout (location = 3) in vec4 inTangent;
|
||||
layout (location = 4) in mat3 inTBN;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialData material = pcs.sceneData.materials.data[pcs.materialID];
|
||||
|
||||
// vec4 diffuse = sampleTexture2DLinear(material.diffuseTex, inUV);
|
||||
// if (diffuse.a < 0.1) {
|
||||
// discard;
|
||||
// }
|
||||
//
|
||||
// vec3 baseColor = material.baseColor.rgb * diffuse.rgb;
|
||||
//
|
||||
// vec3 normal = normalize(inNormal).rgb;
|
||||
// if (inTangent != vec4(0.0)) {
|
||||
// // FIXME: sometimes Blender doesn't export tangents for some objects
|
||||
// // for some reason. When we will start computing tangents manually,
|
||||
// // this check can be removed
|
||||
// normal = sampleTexture2DLinear(material.normalTex, inUV).rgb;
|
||||
// // normal.y = 1 - normal.y; // flip to make OpenGL normal maps work
|
||||
// normal = inTBN * normalize(normal * 2.0 - 1.0);
|
||||
// normal = normalize(normal);
|
||||
// }
|
||||
//
|
||||
// #ifdef PBR
|
||||
// float metallicF = material.metallicRoughnessEmissive.r;
|
||||
// float roughnessF = material.metallicRoughnessEmissive.g;
|
||||
//
|
||||
// vec4 metallicRoughness = sampleTexture2DLinear(material.metallicRoughnessTex, inUV);
|
||||
//
|
||||
// float roughness = roughnessF * metallicRoughness.g;
|
||||
// // roughness *= roughness; // from perceptual to linear
|
||||
// roughness = max(roughness, 1e-2); // 0.0 roughness leads to NaNs
|
||||
//
|
||||
// float metallic = metallicF * metallicRoughness.b;
|
||||
//
|
||||
// vec3 dielectricSpecular = vec3(0.04);
|
||||
// vec3 black = vec3(0.0);
|
||||
// vec3 diffuseColor = mix(baseColor * (1.0 - dielectricSpecular.r), black, metallic);
|
||||
// vec3 f0 = mix(dielectricSpecular, baseColor, metallic);
|
||||
// #else
|
||||
// vec3 diffuseColor = baseColor;
|
||||
// float metallic = 0.f;
|
||||
// float roughness = 1.f;
|
||||
// vec3 f0 = vec3(0.0);
|
||||
// #endif
|
||||
//
|
||||
// vec3 cameraPos = pcs.sceneData.cameraPos.xyz;
|
||||
// vec3 fragPos = inPos.xyz;
|
||||
// vec3 n = normal;
|
||||
// vec3 v = normalize(cameraPos - fragPos);
|
||||
//
|
||||
// // diffuseColor = vec3(1.0);
|
||||
// // baseColor = vec3(1.0);
|
||||
//
|
||||
// vec3 fragColor = vec3(0.0);
|
||||
// for (int i = 0; i < pcs.sceneData.numLights; i++) {
|
||||
// Light light = pcs.sceneData.lights.data[i];
|
||||
//
|
||||
// vec3 l = light.direction;
|
||||
// if (light.type != TYPE_DIRECTIONAL_LIGHT) {
|
||||
// l = normalize(light.position - fragPos);
|
||||
// }
|
||||
// float NoL = clamp(dot(n, l), 0.0, 1.0);
|
||||
//
|
||||
// float occlusion = 1.0;
|
||||
// if (light.type == TYPE_DIRECTIONAL_LIGHT) {
|
||||
// occlusion = calculateCSMOcclusion(
|
||||
// fragPos, cameraPos, NoL,
|
||||
// pcs.sceneData.csmShadowMapId,
|
||||
// pcs.sceneData.cascadeFarPlaneZs,
|
||||
// pcs.sceneData.csmLightSpaceTMs);
|
||||
// } else if (light.type == TYPE_POINT_LIGHT && light.shadowMapID != 0) {
|
||||
// occlusion = calculatePointShadow(
|
||||
// fragPos, light.position, NoL,
|
||||
// light.shadowMapID,
|
||||
// pcs.sceneData.pointLightFarPlane);
|
||||
// }
|
||||
//
|
||||
// fragColor += calculateLight(light, fragPos, n, v, l,
|
||||
// diffuseColor, roughness, metallic, f0, occlusion);
|
||||
// }
|
||||
//
|
||||
// // emissive
|
||||
// float emissiveF = material.metallicRoughnessEmissive.b;
|
||||
// vec3 emissiveColor = emissiveF * sampleTexture2DLinear(material.emissiveTex, inUV).rgb;
|
||||
// fragColor += emissiveColor;
|
||||
//
|
||||
// // ambient
|
||||
// fragColor += baseColor * pcs.sceneData.ambientColor * pcs.sceneData.ambientIntensity;
|
||||
//
|
||||
// #if 0
|
||||
// // CSM DEBUG
|
||||
// uint cascadeIndex = chooseCascade(inPos, cameraPos, pcs.sceneData.cascadeFarPlaneZs);
|
||||
// fragColor *= debugShadowsFactor(cascadeIndex);
|
||||
// #endif
|
||||
//
|
||||
// #if 0
|
||||
// // TANGENT DEBUG
|
||||
// if (inTangent == vec4(0.0)) {
|
||||
// fragColor = vec3(1.0f, 0.0f, 0.0f);
|
||||
// }
|
||||
// #endif
|
||||
//
|
||||
// #if 1
|
||||
// // NORMAL DEBUG
|
||||
// // fragColor = normal;
|
||||
// #endif
|
||||
|
||||
outFragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
34
destrum/assets_src/shaders/mesh.vert
Normal file
34
destrum/assets_src/shaders/mesh.vert
Normal file
@@ -0,0 +1,34 @@
|
||||
#version 460
|
||||
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#include "mesh_pcs.glsl"
|
||||
|
||||
layout (location = 0) out vec3 outPos;
|
||||
layout (location = 1) out vec2 outUV;
|
||||
layout (location = 2) out vec3 outNormal;
|
||||
layout (location = 3) out vec4 outTangent;
|
||||
layout (location = 4) out mat3 outTBN;
|
||||
|
||||
void main()
|
||||
{
|
||||
Vertex v = pcs.vertexBuffer.vertices[gl_VertexIndex];
|
||||
|
||||
vec4 worldPos = pcs.transform * vec4(v.position, 1.0f);
|
||||
|
||||
gl_Position = pcs.sceneData.viewProj * worldPos;
|
||||
outPos = worldPos.xyz;
|
||||
outUV = vec2(v.uv_x, v.uv_y);
|
||||
// A bit inefficient, but okay - this is needed for non-uniform scale
|
||||
// models. See: http://www.lighthouse3d.com/tutorials/glsl-12-tutorial/the-normal-matrix/
|
||||
// Simpler case, when everything is uniform
|
||||
// outNormal = (pcs.transform * vec4(v.normal, 0.0)).xyz;
|
||||
outNormal = mat3(transpose(inverse(pcs.transform))) * v.normal;
|
||||
|
||||
outTangent = v.tangent;
|
||||
|
||||
vec3 T = normalize(vec3(pcs.transform * v.tangent));
|
||||
vec3 N = normalize(outNormal);
|
||||
vec3 B = cross(N, T) * v.tangent.w;
|
||||
outTBN = mat3(T, B, N);
|
||||
}
|
||||
15
destrum/assets_src/shaders/mesh_pcs.glsl
Normal file
15
destrum/assets_src/shaders/mesh_pcs.glsl
Normal file
@@ -0,0 +1,15 @@
|
||||
#extension GL_EXT_buffer_reference : require
|
||||
#extension GL_EXT_scalar_block_layout: require
|
||||
|
||||
#include "scene_data.glsl"
|
||||
#include "vertex.glsl"
|
||||
|
||||
layout (push_constant, scalar) uniform constants
|
||||
{
|
||||
mat4 transform;
|
||||
SceneDataBuffer sceneData;
|
||||
VertexBuffer vertexBuffer;
|
||||
uint materialID;
|
||||
uint padding;
|
||||
} pcs;
|
||||
|
||||
28
destrum/assets_src/shaders/scene_data.glsl
Normal file
28
destrum/assets_src/shaders/scene_data.glsl
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef SCENE_DATA_GLSL
|
||||
#define SCENE_DATA_GLSL
|
||||
|
||||
|
||||
#extension GL_EXT_scalar_block_layout: require
|
||||
#extension GL_EXT_buffer_reference : require
|
||||
|
||||
#include "materials.glsl"
|
||||
|
||||
layout (buffer_reference, scalar) readonly buffer SceneDataBuffer {
|
||||
// camera
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
mat4 viewProj;
|
||||
vec4 cameraPos;
|
||||
|
||||
// ambient
|
||||
vec3 ambientColor;
|
||||
float ambientIntensity;
|
||||
|
||||
// fog
|
||||
vec3 fogColor;
|
||||
float fogDensity;
|
||||
|
||||
MaterialsBuffer materials;
|
||||
} sceneDataBuffer;
|
||||
|
||||
#endif // SCENE_DATA_GLSL
|
||||
19
destrum/assets_src/shaders/vertex.glsl
Normal file
19
destrum/assets_src/shaders/vertex.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef VERTEX_GLSL
|
||||
#define VERTEX_GLSL
|
||||
|
||||
|
||||
#extension GL_EXT_buffer_reference : require
|
||||
|
||||
struct Vertex {
|
||||
vec3 position;
|
||||
float uv_x;
|
||||
vec3 normal;
|
||||
float uv_y;
|
||||
vec4 tangent;
|
||||
};
|
||||
|
||||
layout (buffer_reference, std430) readonly buffer VertexBuffer {
|
||||
Vertex vertices[];
|
||||
};
|
||||
|
||||
#endif // VERTEX_GLSL
|
||||
Reference in New Issue
Block a user