SHADE_Y3/Assets/Shaders/TestCube_FS.glsl

53 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2022-09-19 00:00:07 +08:00
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
2022-09-27 19:18:45 +08:00
#extension GL_EXT_nonuniform_qualifier : require
2022-09-19 00:00:07 +08:00
2022-09-28 20:33:29 +08:00
struct MatPropData
{
vec4 color;
int textureIndex;
float alpha;
vec3 beta;
};
2022-09-19 00:00:07 +08:00
layout(location = 0) in struct
{
vec4 vertPos; // location 0
vec2 uv; // location = 1
vec4 normal; // location = 2
2023-01-11 08:25:38 +08:00
vec4 worldPos; // location = 3
2023-03-06 00:02:06 +08:00
vec3 worldNormal; // location = 4
2022-09-19 00:00:07 +08:00
} In;
// material stuff
2023-03-06 00:02:06 +08:00
layout(location = 5) flat in struct
2022-09-19 00:00:07 +08:00
{
int materialIndex;
uint eid;
uint lightLayerIndex;
} In2;
2022-09-19 00:00:07 +08:00
2022-09-28 20:33:29 +08:00
layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global)
2022-12-28 20:47:20 +08:00
layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials
{
MatPropData data[];
} MatProp;
layout(location = 0) out vec4 position;
layout(location = 1) out uint outEntityID;
2023-03-06 00:02:06 +08:00
layout(location = 2) out uvec4 lightLayerIndices;
layout(location = 3) out vec4 normals;
layout(location = 4) out vec4 albedo;
2023-01-11 08:25:38 +08:00
layout(location = 5) out vec4 worldSpacePosition;
2022-09-19 00:00:07 +08:00
void main()
{
position = In.vertPos;
normals = In.normal;
albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) * MatProp.data[In2.materialIndex].color;
2023-01-11 08:25:38 +08:00
worldSpacePosition = In.worldPos;
2022-09-19 00:00:07 +08:00
outEntityID = In2.eid;
2023-03-06 00:02:06 +08:00
lightLayerIndices = uvec4 (In2.lightLayerIndex, packHalf2x16 (In.worldNormal.xy), packHalf2x16 (vec2 (In.worldNormal.z, 1.0f)), 1);
2022-09-19 00:00:07 +08:00
}