Mii rendering and parsing library
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add model scaling

j0.lol ebb977d7 65f7fd5e

+47 -91
+9
lightweight_viewer/src/char_draw.rs
··· 198 198 _ => Vec3::ZERO, 199 199 }; 200 200 201 + let scale = match shape_kind { 202 + Shape::Glasses => Vec3::splat(0.15 * f32::from(st.char_info.glass_scale) + 0.4), // RFL_Model.c :784 203 + Shape::Nose => Vec3::splat(0.175 * f32::from(st.char_info.nose_scale) + 0.4), // RFL_Model.c :705 204 + _ => Vec3::ONE, 205 + }; 206 + 201 207 // Closure to reduce boilerplate for writing out textures. 202 208 let mut draw_tex = |func: fn(&mut State, &TextureView, &mut CommandEncoder), size: UVec2| { 203 209 let texture = texture::Texture::create_texture( ··· 227 233 shape_kind, 228 234 usize::from(shape_color), 229 235 position, 236 + scale, 230 237 projected_texture, 231 238 )) 232 239 } ··· 237 244 shape: Shape, 238 245 color: usize, 239 246 position: Vec3, 247 + scale: Vec3, 240 248 projected_texture: Option<texture::Texture>, 241 249 ) -> Rendered3dShape { 242 250 let mut vertices: Vec<Vertex> = vec![]; ··· 266 274 }, 267 275 texture: projected_texture, 268 276 position, 277 + scale, 269 278 } 270 279 }
+4 -4
lightweight_viewer/src/main.rs
··· 23 23 ) 24 24 } 25 25 26 - const FACES: [&str; 1] = [ 26 + const FACES: [&str; 4] = [ 27 27 // "testguy.charinfo", 28 - // "j0.charinfo", 29 - // "charline.charinfo", 28 + "j0.charinfo", 29 + "charline.charinfo", 30 30 "Jasmine.charinfo", 31 - // "soyun.charinfo", 31 + "soyun.charinfo", 32 32 ]; 33 33 34 34 fn main() {
+13 -8
vfl/src/draw/render_3d.rs
··· 13 13 diffuse_color: [f32; 4], 14 14 position: [f32; 3], 15 15 _pad: f32, 16 + scale: [f32; 3], 17 + _pad2: f32, 16 18 } 17 19 18 20 pub trait ProgramState { ··· 31 33 pub color: Vec4, 32 34 pub texture: Option<crate::draw::wgpu_render::texture::Texture>, 33 35 pub position: Vec3, 36 + pub scale: Vec3, 34 37 } 35 38 36 39 impl Rendered3dShape { ··· 61 64 diffuse_color: self.color.into(), 62 65 position: self.position.into(), 63 66 _pad: 0.0, 67 + scale: self.scale.into(), 68 + _pad2: 0.0, 64 69 }; 65 70 let char_shape_buffer = st 66 71 .device() ··· 123 128 bind_group_layouts.push(&projected_texture_bind_group_layout); 124 129 } 125 130 126 - let shader_module = if self.texture.is_some() { 127 - st.device() 128 - .create_shader_module(include_wgsl!("shader-3d-texture.wgsl")) 129 - } else { 130 - st.device() 131 - .create_shader_module(include_wgsl!("shader-3d.wgsl")) 132 - }; 131 + let shader_module = st 132 + .device() 133 + .create_shader_module(include_wgsl!("shader_3d.wgsl")); 133 134 134 135 // Optional projected texture 135 136 let projected_texture_bind_group = self.texture.as_ref().map(|texture| { ··· 169 170 }, 170 171 fragment: Some(wgpu::FragmentState { 171 172 module: &shader_module, 172 - entry_point: Some("fs_main"), 173 + entry_point: if self.texture.is_some() { 174 + Some("fs_main") 175 + } else { 176 + Some("fs_color_only") 177 + }, 173 178 targets: &[Some(wgpu::ColorTargetState { 174 179 format: st.surface_fmt().add_srgb_suffix(), 175 180 blend: Some(BlendState::ALPHA_BLENDING),
+21 -8
vfl/src/draw/shader-3d-texture.wgsl vfl/src/draw/shader_3d.wgsl
··· 6 6 7 7 struct CharShapeUniform { 8 8 color: vec4<f32>, 9 - position: vec3<f32> 9 + position: vec3<f32>, 10 + scale: vec3<f32> 11 + } 10 12 11 - } 12 13 @group(1) @binding(0) 13 14 var<uniform> char_shape: CharShapeUniform; 14 15 ··· 38 39 var out: VertexOutput; 39 40 out.tex_coords = model.tex_coords; 40 41 out.world_normal = model.normal; 41 - var world_position: vec4<f32> = vec4<f32>(model.position + char_shape.position, 1.0); 42 + var world_position: vec4<f32> = vec4<f32>((char_shape.scale * model.position) + char_shape.position, 1.0); 42 43 out.world_position = world_position.xyz; 43 44 out.clip_position = camera.view_proj * world_position; 44 45 return out; ··· 51 52 let sample_position = in.tex_coords; 52 53 let tex_color = textureSample(t_diffuse, s_diffuse, sample_position); 53 54 54 - // if tex_color.a == 0.0 { 55 - // discard; 56 - // } 55 + let color = mix(char_shape.color, tex_color, tex_color.a); 56 + 57 + if color.a == 0.0 { 58 + discard; 59 + } 60 + 61 + return color; 62 + 63 + } 57 64 58 - // return tex_color; 59 65 60 - return mix(char_shape.color, tex_color, tex_color.a); 66 + @fragment 67 + fn fs_color_only(in: VertexOutput) -> @location(0) vec4<f32> { 68 + let color = char_shape.color; 61 69 70 + if color.a == 0.0 { 71 + discard; 72 + } 73 + 74 + return color; 62 75 }
-71
vfl/src/draw/shader-3d.wgsl
··· 1 - struct CameraUniform { 2 - view_proj: mat4x4<f32>, 3 - }; 4 - @group(0) @binding(0) 5 - var<uniform> camera: CameraUniform; 6 - 7 - struct CharShapeUniform { 8 - color: vec4<f32>, 9 - position: vec3<f32> 10 - } 11 - @group(1) @binding(0) 12 - var<uniform> char_shape: CharShapeUniform; 13 - 14 - struct VertexInput { 15 - @location(0) position: vec3<f32>, 16 - @location(1) tex_coords: vec2<f32>, 17 - @location(2) normal: vec3<f32>, 18 - } 19 - 20 - struct VertexOutput { 21 - @builtin(position) clip_position: vec4<f32>, 22 - @location(0) tex_coords: vec2<f32>, 23 - @location(1) world_normal: vec3<f32>, 24 - @location(2) world_position: vec3<f32>, 25 - } 26 - 27 - @vertex 28 - fn vs_main( 29 - model: VertexInput, 30 - // instance: InstanceInput, 31 - ) -> VertexOutput { 32 - var out: VertexOutput; 33 - out.tex_coords = model.tex_coords; 34 - out.world_normal = model.normal; 35 - var world_position: vec4<f32> = vec4<f32>(model.position + char_shape.position, 1.0); 36 - out.world_position = world_position.xyz; 37 - out.clip_position = camera.view_proj * world_position; 38 - return out; 39 - } 40 - 41 - // Fragment shader 42 - 43 - @fragment 44 - fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { 45 - 46 - let color = char_shape.color; 47 - 48 - if color.a == 0.0 { 49 - discard; 50 - } 51 - return color; 52 - // let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords); 53 - 54 - // // We don't need (or want) much ambient light, so 0.1 is fine 55 - // let ambient_strength = 0.1; 56 - // let ambient_color = light.color * ambient_strength; 57 - 58 - // let light_dir = normalize(light.position - in.world_position); 59 - // let view_dir = normalize(camera.view_pos.xyz - in.world_position); 60 - // let half_dir = normalize(view_dir + light_dir); 61 - 62 - // let diffuse_strength = max(dot(in.world_normal, light_dir), 0.0); 63 - // let diffuse_color = light.color * diffuse_strength; 64 - 65 - // let specular_strength = pow(max(dot(in.world_normal, half_dir), 0.0), 32.0); 66 - // let specular_color = specular_strength * light.color; 67 - 68 - // let result = (ambient_color + diffuse_color + specular_color) * object_color.xyz; 69 - 70 - // return vec4<f32>(result, object_color.a); 71 - }