|
1 | | -using System.Runtime.CompilerServices; |
2 | | -using System.Runtime.InteropServices; |
| 1 | +using System.Runtime.InteropServices; |
3 | 2 | using Coplt.Graphics; |
4 | 3 | using Coplt.Graphics.Core; |
5 | 4 | using Coplt.Graphics.States; |
6 | 5 | using Coplt.Mathematics; |
| 6 | +using static Coplt.Mathematics.math; |
| 7 | +using static Coplt.Mathematics.ctor; |
7 | 8 |
|
8 | 9 | namespace Examples; |
9 | 10 |
|
@@ -246,14 +247,16 @@ private struct Args |
246 | 247 | } |
247 | 248 |
|
248 | 249 | public void Render(GpuRecord cmd, Time time) |
249 | | - { |
250 | | - var pos = new float3(0, -0.25f, -2); |
251 | | - pos.z += (float)math.sin(time.Total.TotalSeconds); |
252 | | - var rot = quaternion.Euler(new((-45f + (float)math.cos(time.Total.TotalSeconds * 0.1f) * 15f).radians(), 0, 0)); |
253 | | - var view = float4x4.TR(-pos, rot.inverse()); |
254 | | - var proj = float4x4.PerspectiveFov(Fov.radians(), Example.AspectRatio, Near, Far); |
255 | | - var vp = math.mul(proj, view); |
256 | | - var args = cmd.UploadConstants(new Args { ViewProj = vp }); |
| 250 | + { |
| 251 | + var t = (float)time.Total.TotalSeconds; |
| 252 | + var (sin_t, cos_t) = sincos(float2(t, t * 0.1f)); |
| 253 | + var pos = mad(float3(0, -cos_t.y, sin_t.x), float3(1, 0.1f, 1), float3(0, -0.25f, -2)); |
| 254 | + var rot = quaternion.Euler(float3(radians(-45f + cos_t.y * 15f), 0, 0)); |
| 255 | + var view = float4x4.TR(-pos, inverse(rot)); |
| 256 | + var proj = float4x4.PerspectiveFov(radians(Fov), Example.AspectRatio, Far, Near); // invert depth (near <> far) |
| 257 | + var view_proj = mul(proj, view); |
| 258 | + var args = cmd.UploadConstants(new Args { ViewProj = view_proj }); |
| 259 | + |
257 | 260 | using var render = cmd.Render([new(Example.Output, new Color(0.83f, 0.8f, 0.97f))], Name: "Display"); |
258 | 261 | render.SetBindItem(BindGroup, [new(0, args), new(1, Example.Image)]); |
259 | 262 | render.Draw(Pipeline, 4, Binding: Binding); |
|
0 commit comments