Skip to content

Commit cd7aed8

Browse files
committed
readme
1 parent 44c5f1e commit cd7aed8

File tree

3 files changed

+512
-10
lines changed

3 files changed

+512
-10
lines changed

Examples/Mipmap/Example.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using System.Runtime.CompilerServices;
2-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
32
using Coplt.Graphics;
43
using Coplt.Graphics.Core;
54
using Coplt.Graphics.States;
65
using Coplt.Mathematics;
6+
using static Coplt.Mathematics.math;
7+
using static Coplt.Mathematics.ctor;
78

89
namespace Examples;
910

@@ -246,14 +247,16 @@ private struct Args
246247
}
247248

248249
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+
257260
using var render = cmd.Render([new(Example.Output, new Color(0.83f, 0.8f, 0.97f))], Name: "Display");
258261
render.SetBindItem(BindGroup, [new(0, args), new(1, Example.Image)]);
259262
render.Draw(Pipeline, 4, Binding: Binding);

0 commit comments

Comments
 (0)