From 08003e649025d895105b191f1a85be7f95f3f792 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Mon, 11 Nov 2024 21:50:12 -0800 Subject: [PATCH] fixes for A Short Hike v2019 --- rust/src/unity/types/binary.rs | 11 +++++++---- src/AShortHike/Scenes.ts | 5 ++--- src/Common/Unity/AssetManager.ts | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/rust/src/unity/types/binary.rs b/rust/src/unity/types/binary.rs index 35cb99e62..9ec32a4d4 100644 --- a/rust/src/unity/types/binary.rs +++ b/rust/src/unity/types/binary.rs @@ -40,6 +40,7 @@ pub struct Material { pub lightmap_flags: u32, pub enable_instancing_variants: u8, pub double_sided_gi: u8, + #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment: Vec, pub custom_render_queue: u32, pub string_tag_map: Map, pub disabled_shader_passes: UnityArray, @@ -70,13 +71,13 @@ pub struct MeshRenderer { pub cast_shadows: u8, pub receive_shadows: u8, pub dynamic_occludee: u8, - #[deku(cond = "version > UnityVersion::V2021_3_27f1")] + #[deku(cond = "version >= UnityVersion::V2021_3_27f1")] pub static_shadow_caster: Option, pub motion_vectors: u8, pub light_probe_usage: u8, pub reflection_probe_usage: u8, pub ray_tracing_mode: u8, - #[deku(cond = "version > UnityVersion::V2021_3_27f1")] + #[deku(cond = "version >= UnityVersion::V2020_3_16f1")] pub ray_trace_procedural: Option, #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment: Vec, pub rendering_layer_mask: u32, @@ -214,10 +215,10 @@ pub struct ChannelInfo { pub stream: u8, pub offset: u8, pub format: VertexFormat, + #[deku(bits = "1", pad_bits_before = "4")] + pub instance_data: u8, #[deku(bits = "3")] pub dimension: u8, - #[deku(bits = "1", pad_bits_after = "4")] - pub instance_data: u8, } #[derive(DekuRead, Clone, Debug)] @@ -282,6 +283,8 @@ pub struct Texture2D { pub name: CharArray, pub forced_fallback_format: i32, pub downscale_fallback: u8, + pub is_alpha_channel_optional: u8, + #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment: Vec, pub width: i32, pub height: i32, pub complete_image_size: i32, diff --git a/src/AShortHike/Scenes.ts b/src/AShortHike/Scenes.ts index a84b07152..44094fa2c 100644 --- a/src/AShortHike/Scenes.ts +++ b/src/AShortHike/Scenes.ts @@ -202,7 +202,6 @@ class TerrainMaterial extends UnityMaterialInstance { class AShortHikeMaterialFactory extends UnityMaterialFactory { public createMaterialInstance(runtime: UnityRuntime, materialData: UnityMaterialData): UnityMaterialInstance { - debugger; // TODO(jstpierre): Pull out serialized shader data if (materialData.name.includes('_Splat3')) return new TerrainMaterial(runtime, materialData); @@ -229,7 +228,7 @@ class UnityRenderer implements Viewer.SceneGfx { const template = this.renderHelper.pushTemplateRenderInst(); template.setBindingLayouts(bindingLayouts); - let offs = template.allocateUniformBuffer(0, 32); + let offs = template.allocateUniformBuffer(0, 16); const mapped = template.mapUniformBufferF32(0); offs += fillMatrix4x4(mapped, offs, viewerInput.camera.clipFromWorldMatrix); @@ -277,7 +276,7 @@ class AShortHikeSceneDesc implements Viewer.SceneDesc { } public async createScene(device: GfxDevice, context: SceneContext): Promise { - const runtime = await createUnityRuntime(context, `AShortHike`, UnityVersion.V2021_3_27f1); + const runtime = await createUnityRuntime(context, `AShortHike`, UnityVersion.V2019_4_39f1); runtime.materialFactory = new AShortHikeMaterialFactory(); await runtime.loadLevel(this.id); diff --git a/src/Common/Unity/AssetManager.ts b/src/Common/Unity/AssetManager.ts index 26c8d43f9..5a6303848 100644 --- a/src/Common/Unity/AssetManager.ts +++ b/src/Common/Unity/AssetManager.ts @@ -739,7 +739,7 @@ export class UnityMaterialData { public fillTexEnvScaleBias(d: Float32Array, offs: number, name: string): number { const texture = this.texturesByName.get(name); if (texture !== undefined) { - return fillVec4(d, texture.scale[0], texture.scale[1], texture.offset[0], texture.offset[1]); + return fillVec4(d, offs, texture.scale[0], texture.scale[1], texture.offset[0], texture.offset[1]); } else { return fillVec4(d, offs, 1, 1, 0, 0); }