half assed bugfixing

This commit is contained in:
Till Wübbers
2025-05-29 17:33:14 +02:00
parent 87ce032833
commit 4b230be2a8
20 changed files with 64 additions and 41 deletions
+4
View File
@@ -3,8 +3,10 @@
#include "../gen/Generated.h"
#include "Log.h"
#include "Puzzle.h" // TODO: remove
#include "bgfx/bgfx.h"
#include "rendering/Rendering.h"
#include <cstdint>
#include <vcruntime_typeinfo.h>
#define ENTITY_HANDLE(X) \
struct X \
@@ -27,6 +29,7 @@ namespace Game
Gen::TextureHandle TextureHandle;
Gen::ModelHandle ModelH;
bool Visible = true;
bool DebugBreakOnRender = false;
void Render(const Model* models, const Material* materials, const Texture* textures);
void LoadFromSaved(const Gen::SavedEntityRenderData& saved);
@@ -140,6 +143,7 @@ namespace Game
void Render(const Model* models, const Material* materials, const Texture* textures)
{
if (!IsEnabled) return;
bgfx::setMarker(typeid(T).name());
for (uint16_t i = 0; i < Count; ++i)
{
Get({i}).EData.Render(models, materials, textures);
+2
View File
@@ -8,6 +8,7 @@
#include "Puzzle.h"
#include "UI.h"
#include "bx/bx.h"
#include "bx/debug.h"
#include "rendering/Rendering.h"
#include "SDL3/SDL_mouse.h"
@@ -28,6 +29,7 @@ namespace Game
{
void EntityRenderData::Render(const Model* models, const Material* materials, const Texture* textures)
{
if (DebugBreakOnRender) bx::debugBreak();
if (models == nullptr || materials == nullptr || textures == nullptr) return;
if (!Gen::IsValid(ModelH) || MaterialHandle >= EMaterial::EntryCount) return;
if (!Visible) return;
-1
View File
@@ -131,7 +131,6 @@ namespace Game
quad.EData.TextureHandle = Puzzle::IsValid(card.RefCard)
? staticCards[card.RefCard.Idx].BoardTextureHandle
: Gen::TextureHandle{0};
quad.EData.TextureHandle = {4};
quad.EData.Transform.Scale = {UICardScale, UICardScale, UICardScale};
quad.EData.DotColor = {1.0f, 1.0f, 1.0f, 1.0f};
quad.EData.BaseColor = {1.0f, 1.0f, 1.0f, 1.0f};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -325,7 +325,7 @@ namespace Game
SharedData& shared = GetShared();
bgfx::Init init;
init.type = bgfx::RendererType::Direct3D12;
init.type = bgfx::RendererType::Direct3D11;
#ifdef _DEBUG
init.debug = true;
// init.debug = false;
+11 -11
View File
@@ -42,19 +42,19 @@ float dither(float brightness, vec2 inputUv)
float zRes = dotsTotal;
float invZRes = 1 / zRes;
float2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5);
vec2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5);
float brightnessCurve = texture2D(s_rampSampler, rampLookupUv).r;
// Magic dot frequency calculation
float2 dx = ddx(inputUv);
float2 dy = ddy(inputUv);
float2x2 mat = float2x2(dx, dy);
float4 vectorized = float4(dx, dy);
vec2 dx = dFdx(inputUv);
vec2 dy = dFdy(inputUv);
mat2 mat = mat2(dx, dy);
vec4 vectorized = vec4(dx, dy);
float qq = dot(vectorized, vectorized);
float rr = determinant(mat);
float discriminantSqr = max(0.0, qq*qq - 4.0*rr*rr);
float discriminant = sqrt(discriminantSqr);
float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0);
vec2 freq = sqrt(vec2(qq + discriminant, qq - discriminant) / 2.0);
// Figuring out how many dots we want
float scaleExp = exp2(globalScale);
@@ -66,7 +66,7 @@ float dither(float brightness, vec2 inputUv)
spacing *= brightnessSpacingMultiplier;
float spacingLog = log2(spacing);
int patternScaleLevel = floor(spacingLog);
int patternScaleLevel = int(floor(spacingLog));
float patternFractional = spacingLog - patternScaleLevel;
vec2 uv = inputUv / exp2(patternScaleLevel);
@@ -91,7 +91,7 @@ void main()
float testRadius = 30.0;
float testSpeed = 1.0;
vec3 testOffset = vec3(0.0, 0.0, 50.0);
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
vec3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
vec3 texColor = u_dotColor.x > 0.1 ? u_dotColor.xyz : texture2D(s_texColor, v_uv0).xyz;
// lighting
@@ -103,9 +103,9 @@ void main()
float r = dither(brightness * texColor.r, v_uv0);
float g = dither(brightness * texColor.g, v_uv0);
float b = dither(brightness * texColor.b, v_uv0);
// float3 finalColor = vec3(r, g, b);
float3 ditheredColor = dither(brightness, v_uv0);
float3 finalColor = mix(u_baseColor, texColor, ditheredColor);
// vec3 finalColor = vec3(r, g, b);
vec3 ditheredColor = dither(brightness, v_uv0);
vec3 finalColor = mix(u_baseColor, texColor, ditheredColor);
gl_FragColor = vec4(finalColor, 1.0);
}
+1 -1
View File
@@ -9,5 +9,5 @@ void main()
v_color0 = a_color0;
v_uv0 = a_texcoord0;
v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz;
v_normal = normalize(mul(u_model[0], a_normal));
v_normal = normalize(mul(u_model[0], vec4(a_normal, 1.0)).xyz);
}
+7 -7
View File
@@ -42,19 +42,19 @@ float dither(float brightness, vec2 inputUv)
float zRes = dotsTotal;
float invZRes = 1 / zRes;
float2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5);
vec2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5);
float brightnessCurve = texture2D(s_rampSampler, rampLookupUv).r;
// Magic dot frequency calculation
float2 dx = ddx(inputUv);
float2 dy = ddy(inputUv);
float2x2 mat = float2x2(dx, dy);
float4 vectorized = float4(dx, dy);
vec2 dx = dFdx(inputUv);
vec2 dy = dFdy(inputUv);
mat2 mat = mat2(dx, dy);
vec4 vectorized = vec4(dx, dy);
float qq = dot(vectorized, vectorized);
float rr = determinant(mat);
float discriminantSqr = max(0.0, qq*qq - 4.0*rr*rr);
float discriminant = sqrt(discriminantSqr);
float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0);
vec2 freq = sqrt(vec2(qq + discriminant, qq - discriminant) / 2.0);
// Figuring out how many dots we want
float scaleExp = exp2(globalScale);
@@ -66,7 +66,7 @@ float dither(float brightness, vec2 inputUv)
spacing *= brightnessSpacingMultiplier;
float spacingLog = log2(spacing);
int patternScaleLevel = floor(spacingLog);
int patternScaleLevel = int(floor(spacingLog));
float patternFractional = spacingLog - patternScaleLevel;
vec2 uv = inputUv / exp2(patternScaleLevel);
+1 -1
View File
@@ -9,5 +9,5 @@ void main()
v_color0 = a_color0;
v_uv0 = a_texcoord0;
v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz;
v_normal = normalize(mul(u_model[0], a_normal));
v_normal = normalize(mul(u_model[0], vec4(a_normal, 0.0)).xyz);
}
+12 -6
View File
@@ -3,15 +3,21 @@ $shadersDir = ".\game\shaders"
$outputBaseDir = ".\game\compiled-shaders"
$includeDir = ".\dependency\bgfx.cmake\bgfx\src"
function CompileForAPI {
param ([string]$API, [string]$ShaderProfile)
$outDir = "$outputBaseDir\$API\$DirectoryName"
New-Item -ItemType Directory -Path $outDir -Force -ErrorAction Stop | Out-Null
Write-Host "Frag: $API $ShaderProfile"
& $shadercPath -f "$DirectoryFull\vert.sc" -o "$outDir\vert.bin" -i $includeDir --type v --platform windows --profile $ShaderProfile
Write-Host "Vert: $API $ShaderProfile"
& $shadercPath -f "$DirectoryFull\frag.sc" -o "$outDir\frag.bin" -i $includeDir --type f --platform windows --profile $ShaderProfile
}
function Process-Directory {
param ([string]$DirectoryFull, [string]$DirectoryName)
Write-Host "Dir: $DirectoryName"
$outDir = "$outputBaseDir\dx11\$DirectoryName"
New-Item -ItemType Directory -Path $outDir -Force -ErrorAction Stop | Out-Null
Write-Host "Frag"
& $shadercPath -f "$DirectoryFull\vert.sc" -o "$outDir\vert.bin" -i $includeDir --type v --platform windows --profile s_5_0
Write-Host "Vert"
& $shadercPath -f "$DirectoryFull\frag.sc" -o "$outDir\frag.bin" -i $includeDir --type f --platform windows --profile s_5_0
CompileForAPI -API "dx11" -ShaderProfile "s_5_0"
CompileForAPI -API "glsl" -ShaderProfile "430"
}
$subdirectories = Get-ChildItem -Path $shadersDir -Directory -Recurse -ErrorAction Stop