diff --git a/src/game/Global.cpp b/src/game/Global.cpp index 4db822e..1865573 100644 --- a/src/game/Global.cpp +++ b/src/game/Global.cpp @@ -109,14 +109,16 @@ namespace Game GameInst = &instance; } - void* AllocateScratch(size_t byteCount, size_t align = 16) + void* AllocateScratch(size_t byteCount, size_t align) { size_t offset = GetInstance().UsedScratchAmount; uint8_t* base = static_cast(GetShared().Game.TransientStorage); uint8_t* current = base + offset; - uintptr_t ptrAligned = ((reinterpret_cast(current) + align - 1) / align) * align; - uintptr_t newOffset = ptrAligned - reinterpret_cast(base) + byteCount; + size_t offsetAligned = ((offset + align - 1) / align) * align; + uint8_t* ptrAligned = base + offsetAligned; + size_t newOffset = offsetAligned + byteCount; if (newOffset > GetShared().Game.TransientStorageSize) return nullptr; + GetInstance().UsedScratchAmount = newOffset; return reinterpret_cast(ptrAligned); } } // namespace Game diff --git a/src/game/Global.h b/src/game/Global.h index 6dbb8d8..2983719 100644 --- a/src/game/Global.h +++ b/src/game/Global.h @@ -76,5 +76,5 @@ namespace Game void SetShared(SharedData& instance); GameInstance& GetInstance(); void SetInstance(GameInstance& instance); - void* AllocateScratch(size_t byteCount); + void* AllocateScratch(size_t byteCount, size_t align = 16); } // namespace Game diff --git a/src/game/Instance.h b/src/game/Instance.h index ffdd77e..9a90389 100644 --- a/src/game/Instance.h +++ b/src/game/Instance.h @@ -33,7 +33,7 @@ namespace Game { bool IsInitialized = false; uint64_t Size = sizeof(GameInstance); - uint8_t UsedScratchAmount = 0; + uint64_t UsedScratchAmount = 0; Time Time; PlayerData Player; Level GameLevel; diff --git a/src/game/Level.cpp b/src/game/Level.cpp index a719528..5e7ee8a 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -141,8 +141,8 @@ namespace Game void TestEntity::Update() { - EData.TestColor[0] = 0.6f; - EData.TestColor[1] = 0.9f; - EData.TestColor[2] = 0.5f; + EData.TestColor[0] = 0.0f; + // EData.TestColor[1] = 0.9f; + // EData.TestColor[2] = 0.5f; } } // namespace Game diff --git a/src/game/compiled-shaders/dx11/frag.bin b/src/game/compiled-shaders/dx11/frag.bin index b01d079..9f39df5 100644 Binary files a/src/game/compiled-shaders/dx11/frag.bin and b/src/game/compiled-shaders/dx11/frag.bin differ diff --git a/src/game/compiled-shaders/dx11/vert.bin b/src/game/compiled-shaders/dx11/vert.bin index f71e19f..c13d000 100644 Binary files a/src/game/compiled-shaders/dx11/vert.bin and b/src/game/compiled-shaders/dx11/vert.bin differ diff --git a/src/game/compiled-shaders/glsl/frag.bin b/src/game/compiled-shaders/glsl/frag.bin index 14e802b..8a66368 100644 Binary files a/src/game/compiled-shaders/glsl/frag.bin and b/src/game/compiled-shaders/glsl/frag.bin differ diff --git a/src/game/compiled-shaders/glsl/vert.bin b/src/game/compiled-shaders/glsl/vert.bin index 53d0194..64b1441 100644 Binary files a/src/game/compiled-shaders/glsl/vert.bin and b/src/game/compiled-shaders/glsl/vert.bin differ diff --git a/src/game/compiled-shaders/spirv/frag.bin b/src/game/compiled-shaders/spirv/frag.bin index ef58272..77f42cf 100644 Binary files a/src/game/compiled-shaders/spirv/frag.bin and b/src/game/compiled-shaders/spirv/frag.bin differ diff --git a/src/game/compiled-shaders/spirv/vert.bin b/src/game/compiled-shaders/spirv/vert.bin index 763d620..57b573e 100644 Binary files a/src/game/compiled-shaders/spirv/vert.bin and b/src/game/compiled-shaders/spirv/vert.bin differ diff --git a/src/game/rendering/Rendering.cpp b/src/game/rendering/Rendering.cpp index b7b7776..2e0ab6b 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -37,7 +37,8 @@ namespace Game long fileSize = ftell(file); fseek(file, 0, SEEK_SET); - const bgfx::Memory* mem = bgfx::alloc(fileSize + 1); + void* rawMem = AllocateScratch(fileSize + 1); + const bgfx::Memory* mem = bgfx::makeRef(rawMem, fileSize + 1); fread(mem->data, 1, fileSize, file); if (appendZero) { @@ -126,7 +127,9 @@ namespace Game *_orientation = imageContainer.m_orientation; } - const bgfx::Memory* mem = bgfx::makeRef(imageContainer.m_data, imageContainer.m_size); + const bgfx::Memory* mem = + bgfx::makeRef(data->data + imageContainer.m_offset, data->size - imageContainer.m_offset); + // const bgfx::Memory* mem = bgfx::makeRef(imageContainer.m_data, imageContainer.m_size); if (NULL != _info) { diff --git a/src/game/shaders/frag.sc b/src/game/shaders/frag.sc index 0526edf..341b596 100644 --- a/src/game/shaders/frag.sc +++ b/src/game/shaders/frag.sc @@ -24,6 +24,11 @@ float calcBrightness(vec3 lightPos, vec3 vertPos, vec3 normal) return diffuse * clamp(1.0 - distance(lightPos, vertPos) * 0.01, 0.0, 1.0); } +float calcBrightnessDirectional(vec3 sunDir, vec3 normal) +{ + return max(0.0, dot(sunDir, normal)); +} + float circles(vec2 uv, float level, float subLevel, float brightness) { vec2 offsetUv = uv + 0.5; @@ -57,7 +62,9 @@ void main() 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); - float brightness = calcBrightness(lightPos, v_wpos, v_normal); + // float brightness = calcBrightness(lightPos, v_wpos, v_normal); + float brightness = calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal); + // brightness = 1.0; // brightness = 0.1 + brightness * 0.9; float baseScale = 2.0; @@ -80,12 +87,15 @@ void main() vec2 uv = v_uv0 * exp2(patternScaleLevel); float dither = circles(uv, patternScaleLevel, patternFractional, brightness); - vec3 color = desaturate(u_testColor.xyz) * 0.01 + dither * u_testColor.xyz * 0.95; + vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz; + vec3 color = desaturate(texColor) * 0.01 + dither * texColor * 0.95; vec3 smoothColor = brightness * u_testColor.xyz; vec3 mixedColor = 0.1 * smoothColor + 0.9 * color; - gl_FragColor = vec4(mixedColor, 1.0); + // gl_FragColor = vec4(mixedColor, 1.0); + gl_FragColor = vec4(color, 1.0); // gl_FragColor = brightness; // gl_FragColor = dither; // gl_FragColor = u_testColor; - gl_FragColor = texture2D(s_texColor, v_uv0); + // gl_FragColor = texture2D(s_texColor, v_uv0); + // gl_FragColor = vec4(v_normal, 1.0); } diff --git a/src/game/shaders/vert.sc b/src/game/shaders/vert.sc index acb1f28..f831c3c 100644 --- a/src/game/shaders/vert.sc +++ b/src/game/shaders/vert.sc @@ -9,6 +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(mat3(u_model[0]), a_normal)); + v_normal = normalize(mul(u_model[0], a_normal)); } diff --git a/tools/remedy-session.rdbg b/tools/remedy-session.rdbg index a9aaa04..f3d051b 100644 Binary files a/tools/remedy-session.rdbg and b/tools/remedy-session.rdbg differ