it works??

This commit is contained in:
Asuro
2025-02-11 20:58:50 +01:00
parent 851db78d66
commit bf2371eca0
12 changed files with 33 additions and 18 deletions

View File

@@ -3,7 +3,6 @@
#include "Global.h" #include "Global.h"
#include "Instance.h" #include "Instance.h"
#include <bx/math.h> #include <bx/math.h>
#include <bgfx/bgfx.h>
namespace namespace
{ {
@@ -65,7 +64,8 @@ namespace Game
double time = TestY <= 5 ? globalTime * 1.0f : 0.0f; double time = TestY <= 5 ? globalTime * 1.0f : 0.0f;
if (TestX == 4 && TestY == 4) 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 else
{ {

View File

@@ -126,6 +126,7 @@ namespace Game
| BGFX_STATE_DEPTH_TEST_LESS | BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_CULL_CCW | BGFX_STATE_CULL_CCW
| BGFX_STATE_MSAA; | BGFX_STATE_MSAA;
Materials[0].Uniforms[Material::UniformTimeIdx] = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
if (!GetInstance().IsInitialized) if (!GetInstance().IsInitialized)
{ {
@@ -179,9 +180,8 @@ namespace Game
bgfx::setViewRect(0, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight); 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 float TimeValues[4]{0.0f};
// if no other draw calls are submitted to view 0. TimeValues[0] = GetInstance().Now;
bgfx::touch(0);
for (int32_t i = 0; i < GetInstance().GameLevel.Cubes.Count; ++i) for (int32_t i = 0; i < GetInstance().GameLevel.Cubes.Count; ++i)
{ {
@@ -195,6 +195,7 @@ namespace Game
bgfx::setVertexBuffer(0, currentModel.VertexBuffer); bgfx::setVertexBuffer(0, currentModel.VertexBuffer);
bgfx::setIndexBuffer(currentModel.IndexBuffer); bgfx::setIndexBuffer(currentModel.IndexBuffer);
bgfx::setState(currentMaterial.State); bgfx::setState(currentMaterial.State);
bgfx::setUniform(Materials[0].Uniforms[Material::UniformTimeIdx], TimeValues);
// Submit primitive for rendering to view 0. // Submit primitive for rendering to view 0.
bgfx::submit(0, currentMaterial.Shader); bgfx::submit(0, currentMaterial.Shader);

View File

@@ -88,7 +88,9 @@ namespace Game
struct Material struct Material
{ {
static constexpr uint32_t UniformTimeIdx = 0;
bgfx::ProgramHandle Shader; bgfx::ProgramHandle Shader;
bgfx::UniformHandle Uniforms[8];
uint64_t State = 0; uint64_t State = 0;
}; };

View File

@@ -1,5 +1,8 @@
$input v_color0 $input v_color0
$input v_uv0 $input v_uv0
$input v_wpos
uniform vec4 u_time;
#include "common.sh" #include "common.sh"
@@ -13,7 +16,12 @@ float circle(vec2 uv, float radius)
return clamp(1.0 - result, 0.0, 1.0); 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 offsetUv = uv + 0.5;
vec2 baseUv = (offsetUv % 1.0) - 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 step3 = clamp(step - 2, 0.0, 1.0);
float sum = 0.0; float sum = 0.0;
// sum += circle(baseUv, lerp(0.5, 0.25, subLevel)); sum = circle(baseUv, lerp(0.5, 0.25, subLevel) * brightness);
// sum += circle(step1Uv, 0.25 * step1); sum = max(sum, circle(step1Uv, 0.25 * step1 * brightness));
// sum += circle(step2Uv, 0.25 * step2); sum = max(sum, circle(step2Uv, 0.25 * step2 * brightness));
// sum += circle(step3Uv, 0.25 * step3); sum = max(sum, circle(step3Uv, 0.25 * step3 * brightness));
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));
return min(sum, 1.0); return min(sum, 1.0);
} }
void main() 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; float baseScale = 10.0;
float2 dx = ddx(v_uv0 * baseScale); float2 dx = ddx(v_uv0 * baseScale);
float2 dy = ddy(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); float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0);
float spacing = freq.y * exp2(2.0); float spacing = freq.y * exp2(2.0);
spacing = 1.0 / spacing; spacing = 4.0 / spacing;
spacing *= 1.0; // TODO: check reference to see how to calculate this! spacing *= brightness; // TODO: check reference to see how to calculate this!
float spacingLog = max(log2(spacing), 1.0); float spacingLog = max(log2(spacing), 1.0);
int patternScaleLevel = floor(spacingLog); int patternScaleLevel = floor(spacingLog);
float patternFractional = spacingLog - patternScaleLevel; float patternFractional = spacingLog - patternScaleLevel;
vec2 uv = v_uv0 * exp2(patternScaleLevel); vec2 uv = v_uv0 * exp2(patternScaleLevel);
gl_FragColor = circles(uv, patternScaleLevel, patternFractional); gl_FragColor = circles(uv, patternScaleLevel, patternFractional, brightness);
} }

View File

@@ -1,5 +1,6 @@
vec4 v_color0 : COLOR0 = vec4(1.0, 1.0, 0.0, 1.0); vec4 v_color0 : COLOR0 = vec4(1.0, 1.0, 0.0, 1.0);
vec2 v_uv0 : TEXCOORD0 = vec2(0.0, 0.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; vec3 a_position : POSITION;
vec4 a_color0 : COLOR0; vec4 a_color0 : COLOR0;

View File

@@ -1,5 +1,5 @@
$input a_position, a_color0, a_texcoord0 $input a_position, a_color0, a_texcoord0
$output v_color0, v_uv0 $output v_color0, v_uv0, v_wpos
#include "common.sh" #include "common.sh"
@@ -8,4 +8,5 @@ void main()
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
v_color0 = a_color0; v_color0 = a_color0;
v_uv0 = a_texcoord0; v_uv0 = a_texcoord0;
v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz;
} }