videoplay

This commit is contained in:
Peter Li 2025-05-02 23:05:36 -07:00
parent b733d7a329
commit 35e6905ed8
18 changed files with 267 additions and 123 deletions

View File

@ -6,3 +6,5 @@ zig version: 0.14
Backlog Labs Game Engine. Backlog Labs Game Engine.
run tools/scripts/first-time-setup.py run tools/scripts/first-time-setup.py
ffmpeg -i INPUT.mp4 -c:v libtheora -q:v 7 -c:a libvorbis -q:a 4 OUTPUT.ogv

View File

@ -30,8 +30,8 @@ pub const SceneObjectPosRot = struct {
pub inline fn toTransform(self: @This()) core.Transform { pub inline fn toTransform(self: @This()) core.Transform {
var transform = core.zm.mul( var transform = core.zm.mul(
core.zm.scalingV(self.scale.toZm()),
core.zm.matFromQuat(self.rotation.quat), core.zm.matFromQuat(self.rotation.quat),
core.zm.scalingV(self.scale.toZm()),
); );
transform = core.zm.mul( transform = core.zm.mul(
@ -317,8 +317,8 @@ pub const SceneSystem = struct {
core.zm.mul( core.zm.mul(
core.zm.translationV(posRot.position.toZm()), core.zm.translationV(posRot.position.toZm()),
core.zm.mul( core.zm.mul(
core.zm.matFromQuat(posRot.rotation.quat),
core.zm.scalingV(posRot.scale.toZm()), core.zm.scalingV(posRot.scale.toZm()),
core.zm.matFromQuat(posRot.rotation.quat),
), ),
), ),
final, final,

View File

@ -26,9 +26,12 @@ struct Scene
uint textureMode; // 0 = regular triple, uint textureMode; // 0 = regular triple,
// 0x10 = video yuv, // 0x10 = video yuv,
uint pad0; // 0 = regular triple,
uint pad1; // 0 = regular triple,
uint pad2; // 0 = regular triple,
}; };
StructuredBuffer<Scene> scene: register(t0, space0); StructuredBuffer<Scene> scene: register(t4, space2);
// from learnopengl.com // from learnopengl.com
float3 BlinnPhong(float3 normal, float3 fragPos, float3 lightPos, float3 lightColor) float3 BlinnPhong(float3 normal, float3 fragPos, float3 lightPos, float3 lightColor)
@ -186,7 +189,6 @@ float4 main(
float4 s; float4 s;
float alpha = s.w;
int texMode = scene[Instance].textureMode; int texMode = scene[Instance].textureMode;
if (texMode == 0x10) // YUV if (texMode == 0x10) // YUV
@ -196,44 +198,27 @@ float4 main(
float3 Gcoeff = float3(1.164, -0.213, -0.533); float3 Gcoeff = float3(1.164, -0.213, -0.533);
float3 Bcoeff = float3(1.164, 2.112, 0.000); float3 Bcoeff = float3(1.164, 2.112, 0.000);
float3 yuv, rgb; float3 yuv;
float3 rgb;
yuv.x =Texture0.Sample(Sampler0, UV).r; float2 uv = UV;
yuv.y =Texture1.Sample(Sampler1, UV).r;
yuv.z =Texture2.Sample(Sampler2, UV).r;
yuv.x = Texture0.Sample(Sampler0, uv).r;
yuv.y = Texture1.Sample(Sampler1, uv).r;
yuv.z = Texture2.Sample(Sampler2, uv).r;
yuv += offset; yuv += offset;
rgb.r = dot(yuv, Rcoeff);
rgb.g = dot(yuv, Gcoeff);
rgb.b = dot(yuv, Bcoeff);
// " gl_FragColor = vec4(rgb, 1.0);\n" rgb.x = dot(yuv, Rcoeff);
// "uniform sampler2D samp0;\n" rgb.y = dot(yuv, Gcoeff);
// "uniform sampler2D samp1;\n" rgb.z = dot(yuv, Bcoeff);
// "uniform sampler2D samp2;\n"
// "const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n" s = float4(rgb, 1.0);
// "const vec3 Rcoeff = vec3(1.164, 0.000, 1.793);\n"
// "const vec3 Gcoeff = vec3(1.164, -0.213, -0.533);\n"
// "const vec3 Bcoeff = vec3(1.164, 2.112, 0.000);\n"
// "void main() {\n"
// " vec2 tcoord;\n"
// " vec3 yuv, rgb;\n"
// " tcoord = gl_TexCoord[0].xy;\n"
// " yuv.x = texture2D(samp0, tcoord).r;\n"
// " yuv.y = texture2D(samp1, tcoord).r;\n"
// " yuv.z = texture2D(samp2, tcoord).r;\n"
// " yuv += offset;\n"
// " rgb.r = dot(yuv, Rcoeff);\n"
// " rgb.g = dot(yuv, Gcoeff);\n"
// " rgb.b = dot(yuv, Bcoeff);\n"
// " gl_FragColor = vec4(rgb, 1.0);\n"
// "}\n";
} }
else if(texMode == 0) else if(texMode == 0)
{ {
s = Texture0.Sample(Sampler0, UV); s = Texture0.Sample(Sampler0, UV);
} }
float alpha = s.w;
if(alpha < 0.01) if(alpha < 0.01)
{ {
discard; discard;

View File

@ -6,7 +6,7 @@
} }
], ],
"types" : { "types" : {
"_15" : { "_19" : {
"name" : "type.Uniforms", "name" : "type.Uniforms",
"members" : [ "members" : [
{ {
@ -41,7 +41,7 @@
} }
] ]
}, },
"_18" : { "_22" : {
"name" : "Scene", "name" : "Scene",
"members" : [ "members" : [
{ {
@ -55,15 +55,30 @@
"name" : "textureMode", "name" : "textureMode",
"type" : "uint", "type" : "uint",
"offset" : 64 "offset" : 64
},
{
"name" : "pad0",
"type" : "uint",
"offset" : 68
},
{
"name" : "pad1",
"type" : "uint",
"offset" : 72
},
{
"name" : "pad2",
"type" : "uint",
"offset" : 76
} }
] ]
}, },
"_17" : { "_21" : {
"name" : "type.StructuredBuffer.Scene", "name" : "type.StructuredBuffer.Scene",
"members" : [ "members" : [
{ {
"name" : "_m0", "name" : "_m0",
"type" : "_18", "type" : "_22",
"array" : [ "array" : [
0 0
], ],
@ -117,6 +132,18 @@
"set" : 2, "set" : 2,
"binding" : 0 "binding" : 0
}, },
{
"type" : "texture2D",
"name" : "Texture1",
"set" : 2,
"binding" : 1
},
{
"type" : "texture2D",
"name" : "Texture2",
"set" : 2,
"binding" : 2
},
{ {
"type" : "texture2D", "type" : "texture2D",
"name" : "DirectionalShadowDepthMap", "name" : "DirectionalShadowDepthMap",
@ -131,6 +158,18 @@
"set" : 2, "set" : 2,
"binding" : 0 "binding" : 0
}, },
{
"type" : "sampler",
"name" : "Sampler1",
"set" : 2,
"binding" : 1
},
{
"type" : "sampler",
"name" : "Sampler2",
"set" : 2,
"binding" : 2
},
{ {
"type" : "sampler", "type" : "sampler",
"name" : "DirectionalShadowSampler", "name" : "DirectionalShadowSampler",
@ -140,17 +179,17 @@
], ],
"ssbos" : [ "ssbos" : [
{ {
"type" : "_17", "type" : "_21",
"name" : "scene", "name" : "scene",
"readonly" : true, "readonly" : true,
"block_size" : 0, "block_size" : 0,
"set" : 0, "set" : 2,
"binding" : 0 "binding" : 4
} }
], ],
"ubos" : [ "ubos" : [
{ {
"type" : "_15", "type" : "_19",
"name" : "type.Uniforms", "name" : "type.Uniforms",
"block_size" : 76, "block_size" : 76,
"set" : 3, "set" : 3,

View File

@ -29,6 +29,10 @@ struct Scene
uint textureMode; // 0 = regular triple, uint textureMode; // 0 = regular triple,
// 0x10 = video yuv, // 0x10 = video yuv,
uint pad0; // 0 = regular triple,
uint pad1; // 0 = regular triple,
uint pad2; // 0 = regular triple,
}; };
StructuredBuffer<Scene> scene: register(t0, space0); StructuredBuffer<Scene> scene: register(t0, space0);

View File

@ -20,6 +20,21 @@
"name" : "textureMode", "name" : "textureMode",
"type" : "uint", "type" : "uint",
"offset" : 64 "offset" : 64
},
{
"name" : "pad0",
"type" : "uint",
"offset" : 68
},
{
"name" : "pad1",
"type" : "uint",
"offset" : 72
},
{
"name" : "pad2",
"type" : "uint",
"offset" : 76
} }
] ]
}, },

View File

@ -11,7 +11,8 @@ entity: core.Entity = undefined,
textureMode: u32 = 0, textureMode: u32 = 0,
// DEBUG for-fun function, completely override what happens when the renderer tries to render this mesh. // DEBUG for-fun function, completely override what happens when the renderer tries to render this mesh.
cmrf: ?*rend.renderer.CustomMeshRenderFunc = null, cmrf: ?rend.renderer.CustomMeshRenderFunc = null,
cmrf_ctx: ?*anyopaque = null,
pub const textureMode_default = 0; pub const textureMode_default = 0;
pub const textureMode_videoYUV = 0x10; pub const textureMode_videoYUV = 0x10;
@ -41,13 +42,16 @@ pub fn updateMesh(self: *@This()) void {
pub fn updateTexture(self: *@This()) void { pub fn updateTexture(self: *@This()) void {
if (self.textureName.handle() != 0) { if (self.textureName.handle() != 0) {
self.setMeshByName(&self.textureName); self.setTextureByName(&self.textureName);
} }
} }
pub fn setMeshByName(self: *@This(), meshName: *core.Name) void { pub fn setMeshByName(self: *@This(), meshName: *core.Name) void {
self.mesh = rend.getMeshByName(meshName); self.mesh = rend.getMeshByName(meshName);
self.meshName = meshName.*; self.meshName = meshName.*;
core.engine_log("getMeshByName {d} {s}", .{ meshName.handle(), meshName.utf8() });
// core.engine_log("late bind of mesh {s}", .{meshName.utf8()});
} }
// script function // script function

View File

@ -0,0 +1,14 @@
# Blender 4.4.3
# www.blender.org
o Plane
v -1.000000 0.000000 1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 -1.000000
v 1.000000 0.000000 -1.000000
vn -0.0000 1.0000 -0.0000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
s 0
f 1/1/1 2/2/1 4/3/1 3/4/1

View File

@ -69,14 +69,14 @@ pub const MeshPool = struct {
switch (u) { switch (u) {
.new => |new| { .new => |new| {
var name = new.name; var name = new.name;
// core.engine_log("uploading mesh => {s}", .{name.utf8()}); core.engine_log("uploading mesh => {s}", .{name.utf8()});
const indexSpan = try self.addTransfer(copyPass, self.indexBuffer, u32, &self.indexSpans, new.indices); const indexSpan = try self.addTransfer(copyPass, self.indexBuffer, u32, &self.indexSpans, new.indices);
const vertexSpan = try self.addTransfer(copyPass, self.vertexBuffer, meshes.MeshVertex, &self.vertexSpans, new.vertices); const vertexSpan = try self.addTransfer(copyPass, self.vertexBuffer, meshes.MeshVertex, &self.vertexSpans, new.vertices);
// core.graphics_log("uploading {d} vertices and {d} indices", .{ vertexSpan.size, indexSpan.size }); core.graphics_log("uploading {d} vertices and {d} indices", .{ vertexSpan.size, indexSpan.size });
// core.engine_log("install mesh by name {d}", .{name.handle()}); core.engine_log("install mesh by name {d}", .{name.handle()});
try self.installedMeshes.put(self.allocator, name.handle(), .{ try self.installedMeshes.put(self.allocator, name.handle(), .{
.vertex = vertexSpan, .vertex = vertexSpan,
.index = indexSpan, .index = indexSpan,

View File

@ -360,7 +360,10 @@ pub const Renderer = struct {
// todo.. sparse uploads // todo.. sparse uploads
self.ssboScene = self.device.createGPUBuffer(&.{ self.ssboScene = self.device.createGPUBuffer(&.{
.usage = .{ .bufferusageGraphicsStorageRead = true, .bufferusageVertex = true }, .usage = .{
.bufferusageGraphicsStorageRead = true,
.bufferusageVertex = true,
},
.size = MaxObjectCount * @sizeOf(meshes_vert.Scene), .size = MaxObjectCount * @sizeOf(meshes_vert.Scene),
.props = 0, .props = 0,
}); });
@ -638,8 +641,11 @@ pub const Renderer = struct {
self.state.pass = cmd.beginGPURenderPass(&targetInfo, 1, &depthTarget); self.state.pass = cmd.beginGPURenderPass(&targetInfo, 1, &depthTarget);
const renderpass = self.state.pass.?; const renderpass = self.state.pass.?;
//renderpass.bindGPUGraphicsPipeline(self.testPipeline); //renderpass.bindGPUGraphicsPipeline(self.testPipeline);
renderpass.bindGPUFragmentSamplers(1, &.{ .sampler = self.blockySampler, .texture = self.defaultTexture.texture }, 1);
renderpass.bindGPUFragmentSamplers(2, &.{ .sampler = self.blockySampler, .texture = self.defaultTexture.texture }, 1);
renderpass.bindGPUVertexStorageBuffers(0, &self.ssboScene, 1); renderpass.bindGPUVertexStorageBuffers(0, &self.ssboScene, 1);
renderpass.bindGPUFragmentStorageBuffers(0, &self.ssboScene, 1);
renderpass.bindGPUVertexBuffers(0, &.{ .buffer = self.meshPool.vertexBuffer, .offset = 0 }, 1); renderpass.bindGPUVertexBuffers(0, &.{ .buffer = self.meshPool.vertexBuffer, .offset = 0 }, 1);
renderpass.bindGPUIndexBuffer(&.{ .buffer = self.meshPool.indexBuffer, .offset = 0 }, .indexelementsize32bit); renderpass.bindGPUIndexBuffer(&.{ .buffer = self.meshPool.indexBuffer, .offset = 0 }, .indexelementsize32bit);
@ -653,6 +659,8 @@ pub const Renderer = struct {
try self.uploadUniforms(cmd); try self.uploadUniforms(cmd);
//rendering each mesh //rendering each mesh
{ {
// placeholder textures
const container = rend.MeshComponent.BaseContainer; const container = rend.MeshComponent.BaseContainer;
const uploadCount: usize = @min(container.dense.items.len, MaxObjectCount); const uploadCount: usize = @min(container.dense.items.len, MaxObjectCount);
for (0..uploadCount) |i| { for (0..uploadCount) |i| {
@ -663,11 +671,15 @@ pub const Renderer = struct {
t = self.defaultTexture; t = self.defaultTexture;
} }
renderpass.bindGPUFragmentSamplers(0, &.{ .texture = t.?.texture, .sampler = self.blockySampler }, 1);
if (component.mesh) |mesh| { if (component.mesh) |mesh| {
renderpass.bindGPUFragmentSamplers(0, &.{ .texture = t.?.texture, .sampler = self.blockySampler }, 1);
if (component.cmrf) |cmrf| {
cmrf(component.cmrf_ctx);
}
renderpass.drawGPUIndexedPrimitives(mesh.index.size, 1, mesh.index.start, @intCast(mesh.vertex.start), @intCast(i)); renderpass.drawGPUIndexedPrimitives(mesh.index.size, 1, mesh.index.start, @intCast(mesh.vertex.start), @intCast(i));
} } else {}
} }
} }
@ -792,7 +804,7 @@ pub const RendererState = struct {
swapchainTexture: ?*gpu.GPUTexture = null, swapchainTexture: ?*gpu.GPUTexture = null,
}; };
pub const CustomMeshRenderFunc = *const fn (mesh: *rend.MeshComponent, renderState: *RendererState) void; pub const CustomMeshRenderFunc = *const fn (?*anyopaque) void;
pub const GPUTextureType = gpu.GPUTexture; pub const GPUTextureType = gpu.GPUTexture;
const skybox_mesh_obj align(8) = @embedFile("embedded/plane.obj").*; const plane_obj align(8) = @embedFile("embedded/plane.obj").*;

View File

@ -36,6 +36,10 @@ yTexture: *gpu.GPUTexture = undefined,
uTexture: *gpu.GPUTexture = undefined, uTexture: *gpu.GPUTexture = undefined,
vTexture: *gpu.GPUTexture = undefined, vTexture: *gpu.GPUTexture = undefined,
ySampler: *gpu.GPUSampler = undefined,
uSampler: *gpu.GPUSampler = undefined,
vSampler: *gpu.GPUSampler = undefined,
gpuTransferBuffer: *gpu.GPUTransferBuffer = undefined, gpuTransferBuffer: *gpu.GPUTransferBuffer = undefined,
fn log(comptime fmt: []const u8, args: anytype) void { fn log(comptime fmt: []const u8, args: anytype) void {
@ -134,7 +138,7 @@ fn releaseAndUploadFrameBuffer(self: *@This(), cmd: *gpu.GPUCommandBuffer) void
.rows_per_layer = @intCast(self.uvHeight), .rows_per_layer = @intCast(self.uvHeight),
}, },
&std.mem.zeroInit(gpu.GPUTextureRegion, .{ &std.mem.zeroInit(gpu.GPUTextureRegion, .{
.texture = self.yTexture, .texture = self.uTexture,
.w = @as(u32, @intCast(self.uvWidth)), .w = @as(u32, @intCast(self.uvWidth)),
.h = @as(u32, @intCast(self.uvHeight)), .h = @as(u32, @intCast(self.uvHeight)),
.d = 1, .d = 1,
@ -151,7 +155,7 @@ fn releaseAndUploadFrameBuffer(self: *@This(), cmd: *gpu.GPUCommandBuffer) void
.rows_per_layer = @intCast(self.uvHeight), .rows_per_layer = @intCast(self.uvHeight),
}, },
&std.mem.zeroInit(gpu.GPUTextureRegion, .{ &std.mem.zeroInit(gpu.GPUTextureRegion, .{
.texture = self.yTexture, .texture = self.vTexture,
.w = @as(u32, @intCast(self.uvWidth)), .w = @as(u32, @intCast(self.uvWidth)),
.h = @as(u32, @intCast(self.uvHeight)), .h = @as(u32, @intCast(self.uvHeight)),
.d = 1, .d = 1,
@ -189,6 +193,10 @@ pub fn createTextures(self: *@This()) !void {
.size = @as(u32, @intCast(self.width * self.height * 2)), .size = @as(u32, @intCast(self.width * self.height * 2)),
.props = 0, .props = 0,
}); });
self.ySampler = createVideoSampler();
self.uSampler = createVideoSampler();
self.vSampler = createVideoSampler();
} }
pub fn tick(self: *@This(), dt: f64) void { pub fn tick(self: *@This(), dt: f64) void {
@ -225,8 +233,45 @@ pub fn tick(self: *@This(), dt: f64) void {
} }
} }
fn bindVideoTextures(p: ?*anyopaque) void {
const self: *@This() = @ptrCast(@alignCast(p));
const ctx = rend.context();
const renderpass: *gpu.GPURenderPass = ctx.state.pass.?;
renderpass.bindGPUFragmentSamplers(0, &.{ .sampler = self.ySampler, .texture = self.yTexture }, 1);
renderpass.bindGPUFragmentSamplers(1, &.{ .sampler = self.uSampler, .texture = self.uTexture }, 1);
renderpass.bindGPUFragmentSamplers(2, &.{ .sampler = self.vSampler, .texture = self.vTexture }, 1);
}
fn createVideoSampler() *gpu.GPUSampler {
return rend.context().device.createGPUSampler(&std.mem.zeroInit(gpu.GPUSamplerCreateInfo, .{
.min_filter = .filterLinear,
.mag_filter = .filterLinear,
.mipmap_mode = .samplermipmapmodeNearest,
.address_mode_u = .sampleraddressmodeRepeat,
.address_mode_v = .sampleraddressmodeRepeat,
.address_mode_w = .sampleraddressmodeRepeat,
}));
}
// creates a video player entity // creates a video player entity
pub fn createVideoPlayerEntity() !core.Entity {} pub fn createVideoPlayerEntity(self: *@This()) !core.Entity {
const entity = try core.createEntity();
const scene = entity.addComponent(core.Scene).?;
const size = 5.0;
const h: f32 = @floatFromInt(self.height);
const w: f32 = @floatFromInt(self.width);
scene.setScale(size, size, size * (h / w));
scene.setRotation(core.Rotation.eulerX(core.radians(90.0)));
if (entity.addComponent(rend.MeshComponent)) |mesh| {
mesh.cmrf = bindVideoTextures;
mesh.cmrf_ctx = self;
mesh.textureMode = 0x10;
mesh.setMesh("m_plane");
}
return entity;
}
pub fn destroy(self: *@This()) void { pub fn destroy(self: *@This()) void {
core.engine_logs("[Videoplayer] destroying player"); core.engine_logs("[Videoplayer] destroying player");

View File

@ -17,7 +17,9 @@ struct Scene
{ {
float4x4 Model; float4x4 Model;
uint textureMode; uint textureMode;
char _m0_final_padding[12]; uint pad0;
uint pad1;
uint pad2;
}; };
struct type_StructuredBuffer_Scene struct type_StructuredBuffer_Scene
@ -25,8 +27,8 @@ struct type_StructuredBuffer_Scene
Scene _m0[1]; Scene _m0[1];
}; };
constant float4 _68 = {}; constant float4 _83 = {};
constant float3 _70 = {}; constant float3 _85 = {};
struct main0_out struct main0_out
{ {
@ -42,93 +44,94 @@ struct main0_in
uint in_var_TEXCOORD4 [[user(locn4)]]; uint in_var_TEXCOORD4 [[user(locn4)]];
}; };
fragment main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_Scene& scene [[buffer(4294967295)]], texture2d<float> Texture0 [[texture(0)]], texture2d<float> DirectionalShadowDepthMap [[texture(3)]], sampler Sampler0 [[sampler(0)]], sampler DirectionalShadowSampler [[sampler(3)]]) fragment main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_Scene& scene [[buffer(1)]], texture2d<float> Texture0 [[texture(0)]], texture2d<float> Texture1 [[texture(1)]], texture2d<float> Texture2 [[texture(2)]], texture2d<float> DirectionalShadowDepthMap [[texture(3)]], sampler Sampler0 [[sampler(0)]], sampler Sampler1 [[sampler(1)]], sampler Sampler2 [[sampler(2)]], sampler DirectionalShadowSampler [[sampler(3)]])
{ {
main0_out out = {}; main0_out out = {};
int _80 = int(scene._m0[in.in_var_TEXCOORD4].textureMode); int _94 = int(scene._m0[in.in_var_TEXCOORD4].textureMode);
float4 _93; float4 _128;
if (_80 == 16) if (_94 == 16)
{ {
_93 = _68; float3 _115 = float3(Texture0.sample(Sampler0, in.in_var_TEXCOORD0).x, Texture1.sample(Sampler1, in.in_var_TEXCOORD0).x, Texture2.sample(Sampler2, in.in_var_TEXCOORD0).x) + float3(-0.0625, -0.5, -0.5);
_128 = float4(dot(_115, float3(1.164000034332275390625, 0.0, 1.7929999828338623046875)), dot(_115, float3(1.164000034332275390625, -0.212999999523162841796875, -0.53299999237060546875)), dot(_115, float3(1.164000034332275390625, 2.111999988555908203125, 0.0)), 1.0);
} }
else else
{ {
float4 _92; float4 _127;
if (_80 == 0) if (_94 == 0)
{ {
_92 = Texture0.sample(Sampler0, in.in_var_TEXCOORD0); _127 = Texture0.sample(Sampler0, in.in_var_TEXCOORD0);
} }
else else
{ {
_92 = _68; _127 = _83;
} }
_93 = _92; _128 = _127;
} }
if (_68.w < 0.00999999977648258209228515625) if (_128.w < 0.00999999977648258209228515625)
{ {
discard_fragment(); discard_fragment();
} }
float3 _146; float3 _182;
do do
{ {
float3 _103 = Uniforms.lightPosition.xyz - in.in_var_TEXCOORD1; float3 _139 = Uniforms.lightPosition.xyz - in.in_var_TEXCOORD1;
float _104 = length(_103); float _140 = length(_139);
float _105 = _104 * _104; float _141 = _140 * _140;
float _111; float _147;
if (_104 > 2.0) if (_140 > 2.0)
{ {
_111 = 0.5 / _105; _147 = 0.5 / _141;
} }
else else
{ {
_111 = 1.0 / _105; _147 = 1.0 / _141;
} }
float _116; float _152;
if (_104 > 4.0) if (_140 > 4.0)
{ {
_116 = _111 * 0.5; _152 = _147 * 0.5;
} }
else else
{ {
_116 = _111; _152 = _147;
} }
float _118 = (_104 > 15.0) ? 0.0 : _116; float _154 = (_140 > 15.0) ? 0.0 : _152;
float _120 = (_118 > 1.0) ? 1.0 : _118; float _156 = (_154 > 1.0) ? 1.0 : _154;
if (length(in.in_var_TEXCOORD2) < 0.100000001490116119384765625) if (length(in.in_var_TEXCOORD2) < 0.100000001490116119384765625)
{ {
_146 = (in.in_var_TEXCOORD1 * float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5)) * _120; _182 = (in.in_var_TEXCOORD1 * float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5)) * _156;
break; break;
} }
float3 _127 = fast::normalize(_103); float3 _163 = fast::normalize(_139);
_146 = ((float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5) * precise::max(dot(_127, in.in_var_TEXCOORD2), 0.0)) * _120) + (((float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5) * powr(precise::max(dot(in.in_var_TEXCOORD2, fast::normalize(_127 + fast::normalize(in.in_var_TEXCOORD1 - Uniforms.viewPos.xyz))), 0.0), 30.0)) * 2.0) * _120); _182 = ((float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5) * precise::max(dot(_163, in.in_var_TEXCOORD2), 0.0)) * _156) + (((float3(0.800000011920928955078125, 0.800000011920928955078125, 0.5) * powr(precise::max(dot(in.in_var_TEXCOORD2, fast::normalize(_163 + fast::normalize(in.in_var_TEXCOORD1 - Uniforms.viewPos.xyz))), 0.0), 30.0)) * 2.0) * _156);
break; break;
} while(false); } while(false);
float3 _163 = ((in.in_var_TEXCOORD3.xyz / float3(in.in_var_TEXCOORD3.w)) * 0.5) + float3(0.5); float3 _199 = ((in.in_var_TEXCOORD3.xyz / float3(in.in_var_TEXCOORD3.w)) * 0.5) + float3(0.5);
float3 _165; float3 _201;
_165.x = _163.x; _201.x = _199.x;
float2 _166 = _165.xy; float2 _202 = _201.xy;
_166.y = -_163.y; _202.y = -_199.y;
float _173; float _209;
int _176; int _212;
int _178; int _214;
_173 = 0.0; _209 = 0.0;
_176 = 0; _212 = 0;
_178 = -4; _214 = -4;
float _174; float _210;
int _177; int _213;
for (; _178 <= 4; _173 = _174, _176 = _177, _178++) for (; _214 <= 4; _209 = _210, _212 = _213, _214++)
{ {
_177 = _176; _213 = _212;
_174 = _173; _210 = _209;
for (int _187 = -4; _187 <= 4; ) for (int _223 = -4; _223 <= 4; )
{ {
_177++; _213++;
_174 += float((in.in_var_TEXCOORD3.z - 0.004999999888241291046142578125) > DirectionalShadowDepthMap.sample(DirectionalShadowSampler, (_166 + float2(float(_187) * 0.000244140625, float(_178) * 0.000244140625))).x); _210 += float((in.in_var_TEXCOORD3.z - 0.004999999888241291046142578125) > DirectionalShadowDepthMap.sample(DirectionalShadowSampler, (_202 + float2(float(_223) * 0.000244140625, float(_214) * 0.000244140625))).x);
_187++; _223++;
continue; continue;
} }
} }
out.out_var_SV_Target0 = float4(powr(_93.xyz * ((float3(0.100000001490116119384765625) + _146) + ((Uniforms.directionalLightColor.xyz * precise::max(dot(Uniforms.directionalLight.xyz, in.in_var_TEXCOORD2), 0.0)) * (1.0 - (_173 / float(_176))))), float3(0.4545454680919647216796875)), _68.w); out.out_var_SV_Target0 = float4(powr(_128.xyz * ((float3(0.100000001490116119384765625) + _182) + ((Uniforms.directionalLightColor.xyz * precise::max(dot(Uniforms.directionalLight.xyz, in.in_var_TEXCOORD2), 0.0)) * (1.0 - (_209 / float(_212))))), float3(0.4545454680919647216796875)), _128.w);
return out; return out;
} }

View File

@ -7,7 +7,9 @@ struct Scene
{ {
float4x4 Model; float4x4 Model;
uint textureMode; uint textureMode;
char _m0_final_padding[12]; uint pad0;
uint pad1;
uint pad2;
}; };
struct type_StructuredBuffer_Scene struct type_StructuredBuffer_Scene

View File

@ -0,0 +1,14 @@
# Blender 4.4.3
# www.blender.org
o Plane
v -1.000000 0.000000 1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 -1.000000
v 1.000000 0.000000 -1.000000
vn -0.0000 1.0000 -0.0000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
s 0
f 1/1/1 2/2/1 4/3/1 3/4/1

View File

@ -16,6 +16,7 @@ showWindow: bool = true,
fpcamera: *FpCamera = undefined, fpcamera: *FpCamera = undefined,
videoplayer: *VideoPlayer = undefined, videoplayer: *VideoPlayer = undefined,
videoplayerObject: core.Entity = undefined,
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This()); pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This());
@ -48,11 +49,11 @@ const assetReferences = [_]assets.AssetImportReference{
// "t_fox", // "t_fox",
// .{ .path = "gltf-samples/Fox/glTF/Texture.png" }, // .{ .path = "gltf-samples/Fox/glTF/Texture.png" },
// ), // ),
// assets.MakeImportRefOptions( assets.MakeImportRefOptions(
// "Texture", "Texture",
// "t_empire", "t_empire",
// .{ .path = "textures/lost_empire-RGBA.png" }, .{ .path = "textures/lost_empire-RGBA.png" },
// ), ),
// assets.MakeImportRefOptions( // assets.MakeImportRefOptions(
// "Texture", // "Texture",
// "t_skybox", // "t_skybox",
@ -80,7 +81,9 @@ pub fn prepare(self: *@This()) !void {
try assets.loadList(assetReferences); try assets.loadList(assetReferences);
self.videoplayer = try VideoPlayer.create(self.allocator); self.videoplayer = try VideoPlayer.create(self.allocator);
try self.videoplayer.startPlayback("OUTPUT3.ogv"); try self.videoplayer.startPlayback("LAPWING2.ogv");
self.videoplayerObject = try self.videoplayer.createVideoPlayerEntity();
// rend.setSkyboxTexture("t_skybox"); // rend.setSkyboxTexture("t_skybox");
@ -98,16 +101,18 @@ pub fn prepare(self: *@This()) !void {
} }
self.fpcamera = try FpCamera.create(self.allocator); self.fpcamera = try FpCamera.create(self.allocator);
self.fpcamera.setPosition(.{ .z = -15, .y = 20 }); self.fpcamera.setPosition(.{ .z = 15 });
self.fpcamera.activateCamera(); self.fpcamera.activateCamera();
{ {
core.engine_log("creating empire", .{});
const lostEmpire = try core.createEntity(); const lostEmpire = try core.createEntity();
const scene = lostEmpire.addComponent(core.Scene).?; const scene = lostEmpire.addComponent(core.Scene).?;
scene.setPosition(.{ .y = -20 }); scene.setPosition(.{ .y = -20 });
const empireMesh = lostEmpire.addComponent(rend.MeshComponent).?; const empireMesh = lostEmpire.addComponent(rend.MeshComponent).?;
empireMesh.setMesh("m_empire"); empireMesh.setMesh("m_empire");
// empireMesh.setTexture("t_empire"); empireMesh.setTexture("t_empire");
} }
{ {
@ -121,13 +126,13 @@ pub fn prepare(self: *@This()) !void {
} }
{ {
const lightbox = try core.createEntity(); // const lightbox = try core.createEntity();
const scene = lightbox.addComponent(core.Scene).?; // const scene = lightbox.addComponent(core.Scene).?;
scene.setPosition(.{ .y = 2 }); // scene.setPosition(.{ .z = 20 });
scene.setScale(0.1, 0.1, 0.1); // scene.setScale(0.1, 0.1, 0.1);
const mesh = lightbox.addComponent(rend.MeshComponent).?; // const mesh = lightbox.addComponent(rend.MeshComponent).?;
mesh.setMesh("m_default_cube"); // mesh.setMesh("m_default_cube");
mesh.setTexture("t_default"); // mesh.setTexture("t_default");
} }
const moveInput = try core.Axis2dBinding.create(core.MakeName("movement")); const moveInput = try core.Axis2dBinding.create(core.MakeName("movement"));