Skip to content

Commit 4960dee

Browse files
committed
Integrated new bgfx-python changes
1 parent a43d652 commit 4960dee

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

demo/shaders/demo.FieldFragmentShader.frag

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,40 @@ vec3 inferno(float t) {
6060

6161
}
6262

63+
vec3 posterize(vec3 _rgb, float _numColors)
64+
{
65+
return floor(_rgb*_numColors) / _numColors;
66+
}
67+
68+
vec4 posterize(vec4 _rgba, float _numColors)
69+
{
70+
return vec4(posterize(_rgba.xyz, _numColors), _rgba.w);
71+
}
72+
73+
#define NUM_OCTAVES 5
74+
75+
float rand(float n){return fract(sin(n) * 43758.5453123);}
76+
77+
float noise(float p){
78+
float fl = floor(p);
79+
float fc = fract(p);
80+
return mix(rand(fl), rand(fl + 1.0), fc);
81+
}
82+
83+
float fbm(float x) {
84+
float v = 0.0;
85+
float a = 0.5;
86+
float shift = float(100);
87+
for (int i = 0; i < NUM_OCTAVES; ++i) {
88+
v += a * noise(x);
89+
x = x * 2.0 + shift;
90+
a *= 0.5;
91+
}
92+
return v;
93+
}
94+
6395
void main()
6496
{
6597
vec4 col = texture2D(s_texColor, v_texcoord0.xy*0.5 + 0.5);
66-
gl_FragColor = vec4(plasma(col.x), col.x);
98+
gl_FragColor = vec4(plasma(fbm(col.x)), col.x);
6799
}

demo/simulation_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def init(self, platform_data):
8989
)
9090

9191
bgfx.setDebug(BGFX_DEBUG_TEXT)
92+
# bgfx.setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0xFFFFFFFF, 1.0, 0)
9293
bgfx.setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x1a0427FF, 1.0, 0)
9394

9495
self.vertex_layout = bgfx.VertexLayout()

demo/utils/imgui_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ def show_properties_dialog(fb_width, fb_height, hidpi: bool):
114114
stats = bgfx.getStats()
115115
to_ms_cpu = 1000.0 / stats.cpuTimerFreq
116116
to_ms_gpu = 1000.0 / stats.gpuTimerFreq
117-
frame_ms = max(float(stats.cpuTimeEnd - stats.cpuTimeBegin), 1.0e-9)
117+
frame_ms = float(stats.cpuTimeFrame) * to_ms_cpu
118118

119-
s_frame_time.push_sample(frame_ms * to_ms_cpu)
119+
s_frame_time.push_sample(frame_ms)
120+
fps = 1000.0 / s_frame_time.m_avg
120121

121-
frame_text_overlay = f"\uf063{s_frame_time.m_min:7.3f}ms, \uf062{s_frame_time.m_max:7.3f}ms\nAvg: {s_frame_time.m_avg:7.3f}ms, {(stats.cpuTimerFreq / frame_ms):6.2f} FPS"
122+
frame_text_overlay = f"\uf063{s_frame_time.m_min:7.3f}ms, \uf062{s_frame_time.m_max:7.3f}ms\nAvg: {s_frame_time.m_avg:7.3f}ms, {fps:6.2f} FPS"
122123
ImGui.PushStyleColor(
123124
ImGui.ImGuiCol_PlotHistogram, ImGui.ImVec4(0.0, 0.5, 0.15, 1.0)
124125
)

0 commit comments

Comments
 (0)