diff --git a/src/game/Level.cpp b/src/game/Level.cpp index c89670b..1b3ace4 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -3,7 +3,6 @@ #include "Global.h" #include "Instance.h" #include -#include namespace { @@ -65,7 +64,8 @@ namespace Game double time = TestY <= 5 ? globalTime * 1.0f : 0.0f; if (TestX == 4 && TestY == 4) { - bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(-20.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); + // bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(-20.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); + // bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(0.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); } else { diff --git a/src/game/compiled-shaders/dx11/frag.bin b/src/game/compiled-shaders/dx11/frag.bin index f72be6a..07ddd9b 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 796e9ae..7898a40 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 2fcde08..9d01cab 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 c51b685..72079f3 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 3ebb57c..b3fbd8d 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 1d5348c..3811303 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 2987aec..e7aa717 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -126,6 +126,7 @@ namespace Game | BGFX_STATE_DEPTH_TEST_LESS | BGFX_STATE_CULL_CCW | BGFX_STATE_MSAA; + Materials[0].Uniforms[Material::UniformTimeIdx] = bgfx::createUniform("u_time", bgfx::UniformType::Vec4); if (!GetInstance().IsInitialized) { @@ -179,9 +180,8 @@ namespace Game bgfx::setViewRect(0, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight); } - // This dummy draw call is here to make sure that view 0 is cleared - // if no other draw calls are submitted to view 0. - bgfx::touch(0); + float TimeValues[4]{0.0f}; + TimeValues[0] = GetInstance().Now; for (int32_t i = 0; i < GetInstance().GameLevel.Cubes.Count; ++i) { @@ -195,6 +195,7 @@ namespace Game bgfx::setVertexBuffer(0, currentModel.VertexBuffer); bgfx::setIndexBuffer(currentModel.IndexBuffer); bgfx::setState(currentMaterial.State); + bgfx::setUniform(Materials[0].Uniforms[Material::UniformTimeIdx], TimeValues); // Submit primitive for rendering to view 0. bgfx::submit(0, currentMaterial.Shader); diff --git a/src/game/rendering/Rendering.h b/src/game/rendering/Rendering.h index 85c013c..c159b31 100644 --- a/src/game/rendering/Rendering.h +++ b/src/game/rendering/Rendering.h @@ -88,7 +88,9 @@ namespace Game struct Material { + static constexpr uint32_t UniformTimeIdx = 0; bgfx::ProgramHandle Shader; + bgfx::UniformHandle Uniforms[8]; uint64_t State = 0; }; diff --git a/src/game/shaders/frag.sc b/src/game/shaders/frag.sc index f33b6ff..23cd5fb 100644 --- a/src/game/shaders/frag.sc +++ b/src/game/shaders/frag.sc @@ -1,5 +1,8 @@ $input v_color0 $input v_uv0 +$input v_wpos + +uniform vec4 u_time; #include "common.sh" @@ -13,7 +16,12 @@ float circle(vec2 uv, float radius) return clamp(1.0 - result, 0.0, 1.0); } -float circles(vec2 uv, float level, float subLevel) +float calcBrightness(vec3 lightPos, vec3 vertPos) +{ + return clamp(1.0 - distance(lightPos, vertPos) * 0.01, 0.0, 1.0); +} + +float circles(vec2 uv, float level, float subLevel, float brightness) { vec2 offsetUv = uv + 0.5; vec2 baseUv = (offsetUv % 1.0) - 0.5; @@ -27,20 +35,22 @@ float circles(vec2 uv, float level, float subLevel) float step3 = clamp(step - 2, 0.0, 1.0); float sum = 0.0; - // sum += circle(baseUv, lerp(0.5, 0.25, subLevel)); - // sum += circle(step1Uv, 0.25 * step1); - // sum += circle(step2Uv, 0.25 * step2); - // sum += circle(step3Uv, 0.25 * step3); - sum = circle(baseUv, lerp(0.5, 0.25, subLevel)); - sum = max(sum, circle(step1Uv, 0.25 * step1)); - sum = max(sum, circle(step2Uv, 0.25 * step2)); - sum = max(sum, circle(step3Uv, 0.25 * step3)); + sum = circle(baseUv, lerp(0.5, 0.25, subLevel) * brightness); + sum = max(sum, circle(step1Uv, 0.25 * step1 * brightness)); + sum = max(sum, circle(step2Uv, 0.25 * step2 * brightness)); + sum = max(sum, circle(step3Uv, 0.25 * step3 * brightness)); return min(sum, 1.0); } void main() { + float testRadius = 50.0; + float testSpeed = 1.0; + vec3 testOffset = vec3(0.0, 0.0, 50.0); + float brightness = calcBrightness(testOffset + vec3(sin(u_time.x * testSpeed) * testRadius, 0.0, cos(u_time.x * testSpeed) * testRadius), v_wpos); + brightness = 0.2 + brightness * 0.8; + float baseScale = 10.0; float2 dx = ddx(v_uv0 * baseScale); float2 dy = ddy(v_uv0 * baseScale); @@ -53,12 +63,12 @@ void main() float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0); float spacing = freq.y * exp2(2.0); - spacing = 1.0 / spacing; - spacing *= 1.0; // TODO: check reference to see how to calculate this! + spacing = 4.0 / spacing; + spacing *= brightness; // TODO: check reference to see how to calculate this! float spacingLog = max(log2(spacing), 1.0); int patternScaleLevel = floor(spacingLog); float patternFractional = spacingLog - patternScaleLevel; vec2 uv = v_uv0 * exp2(patternScaleLevel); - gl_FragColor = circles(uv, patternScaleLevel, patternFractional); + gl_FragColor = circles(uv, patternScaleLevel, patternFractional, brightness); } diff --git a/src/game/shaders/varying.def.sc b/src/game/shaders/varying.def.sc index a925eb7..2cd00a9 100644 --- a/src/game/shaders/varying.def.sc +++ b/src/game/shaders/varying.def.sc @@ -1,5 +1,6 @@ vec4 v_color0 : COLOR0 = vec4(1.0, 1.0, 0.0, 1.0); vec2 v_uv0 : TEXCOORD0 = vec2(0.0, 0.0); +vec3 v_wpos : TEXCOORD1 = vec3(0.0, 0.0, 0.0); vec3 a_position : POSITION; vec4 a_color0 : COLOR0; diff --git a/src/game/shaders/vert.sc b/src/game/shaders/vert.sc index 2def252..0a95563 100644 --- a/src/game/shaders/vert.sc +++ b/src/game/shaders/vert.sc @@ -1,5 +1,5 @@ $input a_position, a_color0, a_texcoord0 -$output v_color0, v_uv0 +$output v_color0, v_uv0, v_wpos #include "common.sh" @@ -8,4 +8,5 @@ void main() gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); v_color0 = a_color0; v_uv0 = a_texcoord0; + v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz; }