[vulkan] Get the forward renderer passing validation

It looks horrible due to the lack of lighting etc, but it's good enough
for basic testing, especially of my render job design (that passed with
flying colors).
This commit is contained in:
Bill Currie 2023-07-02 19:58:56 +09:00
parent 260a10d75c
commit 4471a40494
7 changed files with 105 additions and 155 deletions

View file

@ -291,6 +291,8 @@ particleg_src = $(vkshaderpath)/particle.geom
particleg_c = $(vkshaderpath)/particle.geom.spvc
particlef_src = $(vkshaderpath)/particle.frag
particlef_c = $(vkshaderpath)/particle.frag.spvc
spritef_src = $(vkshaderpath)/sprite.frag
spritef_c = $(vkshaderpath)/sprite.frag.spvc
sprite_gbufv_src = $(vkshaderpath)/sprite_gbuf.vert
sprite_gbufv_c = $(vkshaderpath)/sprite_gbuf.vert.spvc
sprite_gbuff_src = $(vkshaderpath)/sprite_gbuf.frag
@ -356,6 +358,8 @@ iqmv_src = $(vkshaderpath)/iqm.vert
iqmv_c = $(vkshaderpath)/iqm.vert.spvc
iqmf_src = $(vkshaderpath)/iqm.frag
iqmf_c = $(vkshaderpath)/iqm.frag.spvc
iqm_fwd_src = $(vkshaderpath)/iqm_fwd.frag
iqm_fwd_c = $(vkshaderpath)/iqm_fwd.frag.spvc
output_src = $(vkshaderpath)/output.frag
output_c = $(vkshaderpath)/output.frag.spvc
passthrough_src = $(vkshaderpath)/passthrough.vert
@ -382,6 +386,8 @@ $(particlev_c): $(particlev_src) $(matrices_h)
$(particleg_c): $(particleg_src) $(matrices_h)
$(particlef_c): $(particlef_src) $(oit_store) $(oit_h)
$(spritef_c): $(spritef_src)
$(sprite_gbufv_c): $(sprite_gbufv_src) $(matrices_h)
$(sprite_gbuff_c): $(sprite_gbuff_src)
@ -440,6 +446,8 @@ $(iqmv_c): $(iqmv_src) $(matrices_h)
$(iqmf_c): $(iqmf_src)
$(iqm_fwd_c): $(iqm_fwd_src)
$(output_c): $(output_src) $(matrices_h)
$(passthrough_c): $(passthrough_src)
@ -463,6 +471,7 @@ vkshader_c = \
$(particlev_c) \
$(particleg_c) \
$(particlef_c) \
$(spritef_c) \
$(sprite_gbufv_c) \
$(sprite_gbuff_c) \
$(sprite_depthv_c) \
@ -492,6 +501,7 @@ vkshader_c = \
$(alias_shadow_c) \
$(iqmv_c) \
$(iqmf_c) \
$(iqm_fwd_c) \
$(output_c) \
$(passthrough_c) \
$(fstriangle_c) \
@ -549,6 +559,7 @@ EXTRA_DIST += \
$(particlev_src) \
$(particleg_src) \
$(particlef_src) \
$(spritef_src) \
$(sprite_gbufv_src) \
$(sprite_gbuff_src) \
$(sprite_depthv_src) \
@ -578,6 +589,7 @@ EXTRA_DIST += \
$(alias_shadow_src) \
$(iqmv_src) \
$(iqmf_src) \
$(iqm_fwd_src) \
$(output_src) \
$(passthrough_src) \
$(fstriangle_src) \

View file

@ -241,7 +241,7 @@ properties = {
gbuf_fragment = {
stage = fragment;
name = main;
module = $builtin/bsp_gbuf.frag;
module = $builtin/quakebsp.frag;
};
quake_vertex = {
stage = vertex;
@ -326,7 +326,7 @@ properties = {
gbuf_fragment = {
stage = fragment;
name = main;
module = $builtin/alias_gbuf.frag;
module = $builtin/alias.frag;
};
};
vertexInput = {
@ -387,7 +387,7 @@ properties = {
gbuf_fragment = {
stage = fragment;
name = main;
module = $builtin/iqm.frag;
module = $builtin/iqm_fwd.frag;
};
};
vertexInput = {
@ -448,7 +448,7 @@ properties = {
gbuf_fragment = {
stage = fragment;
name = main;
module = $builtin/sprite_gbuf.frag;
module = $builtin/sprite.frag;
};
};
vertexInput = {

View file

@ -55,6 +55,8 @@ static
static
#include "libs/video/renderer/vulkan/shader/partupdate.comp.spvc"
static
#include "libs/video/renderer/vulkan/shader/sprite.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/sprite_gbuf.vert.spvc"
static
#include "libs/video/renderer/vulkan/shader/sprite_gbuf.frag.spvc"
@ -113,6 +115,8 @@ static
static
#include "libs/video/renderer/vulkan/shader/iqm.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/iqm_fwd.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/output.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/passthrough.vert.spvc"
@ -142,6 +146,7 @@ static shaderdata_t builtin_shaders[] = {
{ "particle.frag", particle_frag, sizeof (particle_frag) },
{ "partphysics.comp", partphysics_comp, sizeof (partphysics_comp) },
{ "partupdate.comp", partupdate_comp, sizeof (partupdate_comp) },
{ "sprite.frag", sprite_frag, sizeof (sprite_frag) },
{ "sprite_gbuf.vert", sprite_gbuf_vert, sizeof (sprite_gbuf_vert) },
{ "sprite_gbuf.frag", sprite_gbuf_frag, sizeof (sprite_gbuf_frag) },
{ "sprite_depth.vert", sprite_depth_vert, sizeof (sprite_depth_vert) },
@ -171,6 +176,7 @@ static shaderdata_t builtin_shaders[] = {
{ "alias_shadow.vert", alias_shadow_vert, sizeof (alias_shadow_vert) },
{ "iqm.vert", iqm_vert, sizeof (iqm_vert) },
{ "iqm.frag", iqm_frag, sizeof (iqm_frag) },
{ "iqm_fwd.frag", iqm_fwd_frag, sizeof (iqm_fwd_frag) },
{ "output.frag", output_frag, sizeof (output_frag) },
{ "passthrough.vert", passthrough_vert, sizeof (passthrough_vert) },
{ "fstriangle.vert", fstriangle_vert, sizeof (fstriangle_vert) },

View file

@ -1,76 +1,30 @@
#version 450
layout (set = 0, binding = 2) uniform sampler2DArray Skin;
/*
layout (set = 2, binding = 0) uniform sampler2D Texture;
layout (set = 2, binding = 1) uniform sampler2D GlowMap;
layout (set = 2, binding = 2) uniform sampler2D ColorA;
layout (set = 2, binding = 3) uniform sampler2D ColorB;
*/
struct LightData {
vec3 color;
float dist;
vec3 position;
int type;
vec3 direction;
float cone;
};
layout (constant_id = 0) const int MaxLights = 8;
//layout (set = 1, binding = 0) uniform Lights {
layout (set = 0, binding = 1) uniform Lights {
int light_count;
LightData lights[MaxLights];
};
layout (set = 1, binding = 0) uniform sampler2D Palette;
layout (set = 2, binding = 0) uniform sampler2DArray Skin;
layout (push_constant) uniform PushConstants {
layout (offset = 68)
uint base_color;
uint colorA;
uint colorB;
uint colors;
vec4 base_color;
vec4 fog;
vec4 color;
};
layout (location = 0) in vec2 st;
layout (location = 1) in vec3 position;
layout (location = 1) in vec4 position;
layout (location = 2) in vec3 normal;
layout (location = 0) out vec4 frag_color;
vec3
calc_light (LightData light)
{
if (light.type == 0) {
vec3 dist = light.position - position;
float dd = dot (dist, dist);
float mag = max (0.0, dot (dist, normal));
return light.color * mag * light.dist / dd;
} else if (light.type == 1) {
} else if (light.type == 2) {
float mag = max (0.0, -dot (light.direction, normal));
// position is ambient light
return light.color * dot (light.direction, normal) + light.position;
}
}
void
main (void)
{
vec4 c;
int i;
vec3 light = vec3 (0);
c = texture (Skin, vec3 (st, 0)) * unpackUnorm4x8(base_color);
c += texture (Skin, vec3 (st, 1)) * unpackUnorm4x8(colorA);
c += texture (Skin, vec3 (st, 2)) * unpackUnorm4x8(colorB);
vec4 c = texture (Skin, vec3 (st, 0)) * base_color;
vec4 e = texture (Skin, vec3 (st, 1));
vec4 rows = unpackUnorm4x8(colors);
vec4 cmap = texture (Skin, vec3 (st, 2));
c += texture (Palette, vec2 (cmap.x, rows.x)) * cmap.y;
c += texture (Palette, vec2 (cmap.z, rows.y)) * cmap.w;
if (MaxLights > 0) {
for (i = 0; i < light_count; i++) {
light += calc_light (lights[i]);
}
}
c *= vec4 (light, 1);
c += texture (Skin, vec3 (st, 3));
//frag_color = vec4((normal + 1)/2, 1);
frag_color = c;//fogBlend (c);
frag_color = c + e;//fogBlend (c);
}

View file

@ -0,0 +1,30 @@
#version 450
layout (set = 1, binding = 0) uniform sampler2D Skin;
layout (push_constant) uniform PushConstants {
layout (offset = 68)
uint colorA;
uint colorB;
vec4 base_color;
vec4 fog;
};
layout (location = 0) in vec2 texcoord;
layout (location = 1) in vec4 position;
layout (location = 2) in vec3 fnormal;
layout (location = 3) in vec3 ftangent;
layout (location = 4) in vec3 fbitangent;
layout (location = 5) in vec4 color;
layout (location = 0) out vec4 frag_color;
void
main (void)
{
vec4 c;
c = texture (Skin, texcoord);// * color;
frag_color = c;
}

View file

@ -1,10 +1,6 @@
#version 450
layout (set = 0, binding = 1) uniform sampler2D Texture;
layout (set = 0, binding = 2) uniform sampler2D GlowMap;
layout (set = 0, binding = 3) uniform sampler2D LightMap;
layout (set = 0, binding = 4) uniform sampler2DArray SkySheet;
layout (set = 0, binding = 5) uniform samplerCube SkyCube;
layout (set = 3, binding = 0) uniform sampler2DArray Texture;
layout (push_constant) uniform PushConstants {
vec4 fog;
@ -14,29 +10,12 @@ layout (push_constant) uniform PushConstants {
layout (location = 0) in vec4 tl_st;
layout (location = 1) in vec3 direction;
layout (location = 2) in vec3 normal;
layout (location = 3) in vec4 position;
layout (location = 4) in vec4 color;
layout (location = 0) out vec4 frag_color;
layout (constant_id = 0) const bool doWarp = false;
layout (constant_id = 1) const bool doLight = true;
layout (constant_id = 2) const bool doSkyCube = false;
layout (constant_id = 3) const bool doSkySheet = false;
const float PI = 3.14159265;
const float SPEED = 20.0;
const float CYCLE = 128.0;
const float FACTOR = PI * 2.0 / CYCLE;
const vec2 BIAS = vec2 (1.0, 1.0);
const float SCALE = 8.0;
vec2
warp_st (vec2 st, float time)
{
vec2 angle = st.ts * CYCLE / 2.0;
vec2 phase = vec2 (time, time) * SPEED;
return st + (sin ((angle + phase) * FACTOR) + BIAS) / SCALE;
}
vec4
fogBlend (vec4 color)
{
@ -47,77 +26,15 @@ fogBlend (vec4 color)
return vec4 (mix (fog_color.rgb, color.rgb, fog_factor), color.a);
}
vec4
sky_sheet (vec3 dir, float time)
{
float len;
vec2 flow = vec2 (1.0, 1.0);
vec2 base;
vec3 st1, st2;
vec4 c1, c2, c;
dir.z *= 3.0;
len = dot (dir, dir);
len = SCALE * inversesqrt (len);
base = dir.yx * vec2(1.0, -1.0) * len;
st1 = vec3 (base + flow * time / 8.0, 0);
st2 = vec3 (base + flow * time / 16.0, 1);
c1 = texture (SkySheet, st1);
c2 = texture (SkySheet, st2);
c = vec4 (mix (c2.rgb, c1.rgb, c1.a), max (c1.a, c2.a));
return c;
}
vec4
sky_cube (vec3 dir, float time)
{
// NOTE: quake's world is right-handed with Z up and X forward, but
// Vulkan's cube maps are left-handed with Y up and Z forward. The
// rotation to X foward is done by the Sky matrix so all that's left
// to do here is swizzle the Y and Z coordinates
return texture (SkyCube, dir.xzy);
}
vec4
sky_color (vec3 dir, float time)
{
if (!doSkySheet) {
return vec4 (1, 0, 1, 1);
//return sky_cube (dir, time);
} if (!doSkyCube) {
return sky_sheet (dir, time);
} else {
// can see through the sheet (may look funny when looking down)
// maybe have 4 sheet layers instead of 2?
vec4 c1 = sky_sheet (dir, time);
vec4 c2 = sky_cube (dir, time);
return vec4 (mix (c2.rgb, c1.rgb, c1.a), max (c1.a, c2.a));
return vec4 (1, 0, 1, 1);
}
}
void
main (void)
{
vec4 c;
vec2 t_st = tl_st.xy;
vec2 l_st = tl_st.zw;
vec3 t_st = vec3 (tl_st.xy, 0);
vec3 e_st = vec3 (tl_st.xy, 1);
vec2 l_st = vec2 (tl_st.zw);
vec4 c = texture (Texture, t_st) * color;
vec4 e = texture (Texture, e_st);
if (doWarp) {
t_st = warp_st (t_st, time);
}
if (doSkyCube || doSkySheet) {
c = sky_color (direction, time);
} else {
c = texture (Texture, t_st);
if (doLight) {
c *= vec4 (texture (LightMap, l_st).xyz, 1);
}
c += texture (GlowMap, t_st);
}
frag_color = c;//fogBlend (c);
}

View file

@ -0,0 +1,31 @@
#version 450
layout (set = 1, binding = 1) uniform sampler2DArray Texture;
layout (push_constant) uniform PushConstants {
layout (offset = 64)
int frame;
int spriteind;
// two slots
vec4 fog;
};
layout (location = 0) in vec2 st;
layout (location = 1) in vec4 position;
layout (location = 2) in vec3 normal;
layout(early_fragment_tests) in;
layout (location = 0) out vec4 frag_color;
void
main (void)
{
vec4 pix;
pix = texture (Texture, vec3 (st, frame));
if (pix.a < 0.5) {
discard;
}
frag_color = pix;
}