CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Common/ShaderUniforms.h
Views: 1401
#pragma once12#include <cstdint>34#include "ShaderCommon.h"56// Used by the "modern" backends that use uniform buffers. They can share this without issue.78enum : uint64_t {9DIRTY_BASE_UNIFORMS =10DIRTY_WORLDMATRIX | DIRTY_PROJTHROUGHMATRIX | DIRTY_VIEWMATRIX | DIRTY_TEXMATRIX | DIRTY_ALPHACOLORREF |11DIRTY_PROJMATRIX | DIRTY_FOGCOLOR | DIRTY_FOGCOEF | DIRTY_TEXENV | DIRTY_TEX_ALPHA_MUL | DIRTY_STENCILREPLACEVALUE |12DIRTY_ALPHACOLORMASK | DIRTY_SHADERBLEND | DIRTY_COLORWRITEMASK | DIRTY_UVSCALEOFFSET | DIRTY_TEXCLAMP | DIRTY_DEPTHRANGE | DIRTY_MATAMBIENTALPHA |13DIRTY_BEZIERSPLINE | DIRTY_DEPAL,14DIRTY_LIGHT_UNIFORMS =15DIRTY_LIGHT_CONTROL | DIRTY_LIGHT0 | DIRTY_LIGHT1 | DIRTY_LIGHT2 | DIRTY_LIGHT3 |16DIRTY_MATDIFFUSE | DIRTY_MATSPECULAR | DIRTY_MATEMISSIVE | DIRTY_AMBIENT,17};1819// Currently 496 bytes.20// Every line here is a 4-float.21struct alignas(16) UB_VS_FS_Base {22float proj[16];23float proj_through[16];24float view[12];25float world[12];26float tex[12];27float uvScaleOffset[4];28float depthRange[4];29float matAmbient[4];30float cullRangeMin[4];31float cullRangeMax[4];32uint32_t spline_counts; uint32_t depal_mask_shift_off_fmt; // 4 params packed into one.33uint32_t colorWriteMask; float mipBias;34// Fragment data35float texNoAlpha; float texMul; float padding[2]; // this vec4 will hold ubershader stuff. We won't use integer flags in the fragment shader.36float fogColor[3]; uint32_t alphaColorRef;37float texEnvColor[3]; uint32_t colorTestMask;38float texClamp[4];39float texClampOffset[2]; float fogCoef[2];40float blendFixA[3]; float stencilReplaceValue;41float blendFixB[3]; float rotation;42// VR stuff is to go here, later. For normal drawing, we can then get away43// with just uploading the first 448 bytes of the struct (up to and including fogCoef).44};4546static const char * const ub_baseStr =47R"( mat4 u_proj;48mat4 u_proj_through;49mat3x4 u_view;50mat3x4 u_world;51mat3x4 u_texmtx;52vec4 u_uvscaleoffset;53vec4 u_depthRange;54vec4 u_matambientalpha;55vec4 u_cullRangeMin;56vec4 u_cullRangeMax;57uint u_spline_counts;58uint u_depal_mask_shift_off_fmt;59uint u_colorWriteMask;60float u_mipBias;61vec2 u_texNoAlphaMul; float pad1; float pad2;62vec3 u_fogcolor; uint u_alphacolorref;63vec3 u_texenv; uint u_alphacolormask;64vec4 u_texclamp;65vec2 u_texclampoff; vec2 u_fogcoef;66vec3 u_blendFixA; float u_stencilReplaceValue;67vec3 u_blendFixB; float u_rotation;68)";6970// 512 bytes. Would like to shrink more. Some colors only have 8-bit precision and we expand71// them to float unnecessarily, could just as well expand in the shader.72struct alignas(16) UB_VS_Lights {73float ambientColor[4];74float materialDiffuse[4];75float materialSpecular[4];76float materialEmissive[3];77uint32_t lightControl;78float lpos[4][4];79float ldir[4][4];80float latt[4][4];81float lightAngle_SpotCoef[4][4]; // TODO: Merge with lightSpotCoef, use .xy82float lightAmbient[4][4];83float lightDiffuse[4][4];84float lightSpecular[4][4];85};8687static const char * const ub_vs_lightsStr =88R"( vec4 u_ambient;89vec3 u_matdiffuse;90vec4 u_matspecular;91vec3 u_matemissive;92uint u_lightControl; // light ubershader control bits93vec3 u_lightpos[4];94vec3 u_lightdir[4];95vec3 u_lightatt[4];96vec4 u_lightangle_spotCoef[4];97vec3 u_lightambient[4];98vec3 u_lightdiffuse[4];99vec3 u_lightspecular[4];100)";101102// With some cleverness, we could get away with uploading just half this when only the four or five first103// bones are being used. This is 384b.104struct alignas(16) UB_VS_Bones {105float bones[8][12];106};107108static const char * const ub_vs_bonesStr =109R"( 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;110)";111112void CalcCullRange(float minValues[4], float maxValues[4], bool flipViewport, bool hasNegZ);113114void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipViewport, bool useBufferedRendering);115void LightUpdateUniforms(UB_VS_Lights *ub, uint64_t dirtyUniforms);116void BoneUpdateUniforms(UB_VS_Bones *ub, uint64_t dirtyUniforms);117118uint32_t PackLightControlBits();119120121