2017-02-08 17:35:41 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include "ShaderCommon.h"
|
|
|
|
|
|
|
|
// Used by the "modern" backends that use uniform buffers. They can share this without issue.
|
|
|
|
|
|
|
|
enum : uint64_t {
|
|
|
|
DIRTY_BASE_UNIFORMS =
|
|
|
|
DIRTY_WORLDMATRIX | DIRTY_PROJTHROUGHMATRIX | DIRTY_VIEWMATRIX | DIRTY_TEXMATRIX | DIRTY_ALPHACOLORREF |
|
2023-01-05 17:05:42 +01:00
|
|
|
DIRTY_PROJMATRIX | DIRTY_FOGCOLOR | DIRTY_FOGCOEFENABLE | DIRTY_TEXENV | DIRTY_TEX_ALPHA_MUL | DIRTY_STENCILREPLACEVALUE |
|
2020-11-08 23:17:06 +01:00
|
|
|
DIRTY_ALPHACOLORMASK | DIRTY_SHADERBLEND | DIRTY_COLORWRITEMASK | DIRTY_UVSCALEOFFSET | DIRTY_TEXCLAMP | DIRTY_DEPTHRANGE | DIRTY_MATAMBIENTALPHA |
|
2018-04-13 12:25:57 +02:00
|
|
|
DIRTY_BEZIERSPLINE | DIRTY_DEPAL,
|
2017-02-08 17:35:41 +01:00
|
|
|
DIRTY_LIGHT_UNIFORMS =
|
2022-09-25 18:30:27 +02:00
|
|
|
DIRTY_LIGHT_CONTROL | DIRTY_LIGHT0 | DIRTY_LIGHT1 | DIRTY_LIGHT2 | DIRTY_LIGHT3 |
|
2017-02-08 17:35:41 +01:00
|
|
|
DIRTY_MATDIFFUSE | DIRTY_MATSPECULAR | DIRTY_MATEMISSIVE | DIRTY_AMBIENT,
|
|
|
|
};
|
|
|
|
|
2023-01-10 10:08:34 +01:00
|
|
|
// Currently 496 bytes.
|
2017-12-07 21:08:34 +01:00
|
|
|
// Every line here is a 4-float.
|
2022-09-25 10:43:17 +02:00
|
|
|
struct alignas(16) UB_VS_FS_Base {
|
2017-02-08 17:35:41 +01:00
|
|
|
float proj[16];
|
|
|
|
float proj_through[16];
|
2017-02-14 11:53:46 +01:00
|
|
|
float view[12];
|
|
|
|
float world[12];
|
|
|
|
float tex[12];
|
2017-02-08 17:35:41 +01:00
|
|
|
float uvScaleOffset[4];
|
|
|
|
float depthRange[4];
|
|
|
|
float matAmbient[4];
|
2018-09-16 23:57:20 -07:00
|
|
|
float cullRangeMin[4];
|
|
|
|
float cullRangeMax[4];
|
2020-11-08 23:17:06 +01:00
|
|
|
uint32_t spline_counts; uint32_t depal_mask_shift_off_fmt; // 4 params packed into one.
|
2022-07-25 18:51:08 +02:00
|
|
|
uint32_t colorWriteMask; float mipBias;
|
2017-02-08 17:35:41 +01:00
|
|
|
// Fragment data
|
2022-10-10 17:16:52 +02:00
|
|
|
float fogColor[3]; uint32_t alphaColorRef;
|
2022-09-25 17:53:56 +02:00
|
|
|
float texEnvColor[3]; uint32_t colorTestMask;
|
2023-01-09 11:19:50 +01:00
|
|
|
float blendFixA[3]; float stencilReplaceValue;
|
2022-12-16 13:03:44 +01:00
|
|
|
float blendFixB[3]; float rotation;
|
2017-02-08 17:35:41 +01:00
|
|
|
float texClamp[4];
|
2022-09-25 17:53:56 +02:00
|
|
|
float texClampOffset[2]; float fogCoef[2];
|
2023-01-05 17:05:42 +01:00
|
|
|
float texNoAlpha; float texMul; float padding[2];
|
2022-10-10 18:00:21 +02:00
|
|
|
// VR stuff is to go here, later. For normal drawing, we can then get away
|
|
|
|
// with just uploading the first 448 bytes of the struct (up to and including fogCoef).
|
2017-02-08 17:35:41 +01:00
|
|
|
};
|
|
|
|
|
2022-09-26 09:30:54 +02:00
|
|
|
static const char * const ub_baseStr =
|
2020-10-17 07:57:32 +02:00
|
|
|
R"( mat4 u_proj;
|
|
|
|
mat4 u_proj_through;
|
|
|
|
mat3x4 u_view;
|
|
|
|
mat3x4 u_world;
|
2020-10-23 09:01:56 +02:00
|
|
|
mat3x4 u_texmtx;
|
2020-10-17 07:57:32 +02:00
|
|
|
vec4 u_uvscaleoffset;
|
|
|
|
vec4 u_depthRange;
|
|
|
|
vec4 u_matambientalpha;
|
2020-11-08 23:17:06 +01:00
|
|
|
vec4 u_cullRangeMin;
|
|
|
|
vec4 u_cullRangeMax;
|
2020-10-17 07:57:32 +02:00
|
|
|
uint u_spline_counts;
|
|
|
|
uint u_depal_mask_shift_off_fmt;
|
2020-11-08 23:17:06 +01:00
|
|
|
uint u_colorWriteMask;
|
2022-07-25 18:51:08 +02:00
|
|
|
float u_mipBias;
|
2022-10-10 17:16:52 +02:00
|
|
|
vec3 u_fogcolor; uint u_alphacolorref;
|
|
|
|
vec3 u_texenv; uint u_alphacolormask;
|
2022-09-25 10:43:17 +02:00
|
|
|
vec3 u_blendFixA; float u_stencilReplaceValue;
|
2022-12-16 13:03:44 +01:00
|
|
|
vec3 u_blendFixB; float u_rotation;
|
2020-10-17 07:57:32 +02:00
|
|
|
vec4 u_texclamp;
|
|
|
|
vec2 u_texclampoff;
|
2022-09-25 10:43:17 +02:00
|
|
|
vec2 u_fogcoef;
|
2023-01-05 17:05:42 +01:00
|
|
|
float u_texNoAlpha; float u_texMul; float pad1; float pad2;
|
2017-02-08 17:35:41 +01:00
|
|
|
)";
|
|
|
|
|
2018-03-12 11:07:51 +01:00
|
|
|
// 512 bytes. Would like to shrink more. Some colors only have 8-bit precision and we expand
|
|
|
|
// them to float unnecessarily, could just as well expand in the shader.
|
2022-09-25 10:43:17 +02:00
|
|
|
struct alignas(16) UB_VS_Lights {
|
2017-02-08 17:35:41 +01:00
|
|
|
float ambientColor[4];
|
|
|
|
float materialDiffuse[4];
|
|
|
|
float materialSpecular[4];
|
2022-09-25 13:59:52 +02:00
|
|
|
float materialEmissive[3];
|
|
|
|
uint32_t lightControl;
|
2017-02-08 17:35:41 +01:00
|
|
|
float lpos[4][4];
|
|
|
|
float ldir[4][4];
|
|
|
|
float latt[4][4];
|
2018-03-12 11:07:51 +01:00
|
|
|
float lightAngle_SpotCoef[4][4]; // TODO: Merge with lightSpotCoef, use .xy
|
2017-02-08 17:35:41 +01:00
|
|
|
float lightAmbient[4][4];
|
|
|
|
float lightDiffuse[4][4];
|
|
|
|
float lightSpecular[4][4];
|
|
|
|
};
|
|
|
|
|
2022-09-26 09:30:54 +02:00
|
|
|
static const char * const ub_vs_lightsStr =
|
2023-01-11 14:18:14 +01:00
|
|
|
R"( vec4 u_ambient;
|
|
|
|
vec3 u_matdiffuse;
|
|
|
|
vec4 u_matspecular;
|
|
|
|
vec3 u_matemissive;
|
2023-01-11 14:49:27 +01:00
|
|
|
uint u_lightControl; // light ubershader control bits
|
|
|
|
vec3 u_lightpos[4];
|
|
|
|
vec3 u_lightdir[4];
|
|
|
|
vec3 u_lightatt[4];
|
|
|
|
vec4 u_lightangle_spotCoef[4];
|
|
|
|
vec3 u_lightambient[4];
|
|
|
|
vec3 u_lightdiffuse[4];
|
|
|
|
vec3 u_lightspecular[4];
|
2017-02-08 17:35:41 +01:00
|
|
|
)";
|
|
|
|
|
2018-04-10 12:22:02 +02:00
|
|
|
// With some cleverness, we could get away with uploading just half this when only the four or five first
|
2020-10-17 07:57:32 +02:00
|
|
|
// bones are being used. This is 384b.
|
2022-09-25 10:43:17 +02:00
|
|
|
struct alignas(16) UB_VS_Bones {
|
2018-04-10 12:22:02 +02:00
|
|
|
float bones[8][12];
|
|
|
|
};
|
|
|
|
|
2022-09-26 09:30:54 +02:00
|
|
|
static const char * const ub_vs_bonesStr =
|
2020-10-23 18:37:37 +02:00
|
|
|
R"( mat3x4 u_bone0; mat3x4 u_bone1; mat3x4 u_bone2; mat3x4 u_bone3; mat3x4 u_bone4; mat3x4 u_bone5; mat3x4 u_bone6; mat3x4 u_bone7; mat3x4 u_bone8;
|
2018-04-10 12:22:02 +02:00
|
|
|
)";
|
|
|
|
|
2018-09-17 22:27:25 -07:00
|
|
|
void CalcCullRange(float minValues[4], float maxValues[4], bool flipViewport, bool hasNegZ);
|
|
|
|
|
2020-04-04 11:03:07 -07:00
|
|
|
void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipViewport, bool useBufferedRendering);
|
2017-02-08 17:35:41 +01:00
|
|
|
void LightUpdateUniforms(UB_VS_Lights *ub, uint64_t dirtyUniforms);
|
2018-04-10 12:22:02 +02:00
|
|
|
void BoneUpdateUniforms(UB_VS_Bones *ub, uint64_t dirtyUniforms);
|
|
|
|
|
2022-09-25 18:30:27 +02:00
|
|
|
uint32_t PackLightControlBits();
|