Constant CREATURE_WGSL
Source pub const CREATURE_WGSL: &str = r#"
struct Frame {
view_proj: mat4x4f, eye: vec4f, right: vec4f, up: vec4f, forward: vec4f,
lens: vec4f, sun: vec4f, sun_color: vec4f, extent: vec4f,
volume_lo: vec4f, volume_hi: vec4f, volume_color: vec4f, volume_control: vec4f,
}
struct Creature { position_scale: vec4f, right: vec4f, up: vec4f, forward: vec4f, motion: vec4f, }
@group(0) @binding(0) var<uniform> frame: Frame;
@group(0) @binding(1) var<storage, read> creatures: array<Creature>;
@group(0) @binding(2) var<storage, read> vertices: array<vec4f>;
@group(0) @binding(3) var scene_depth: texture_2d<f32>;
struct Out { @builtin(position) clip: vec4f, @location(0) color: vec3f, @location(1) distance: f32, }
@vertex fn vs_main(@builtin(vertex_index) vertex: u32, @builtin(instance_index) index: u32) -> Out {
let instance = creatures[index];
var local = vertices[vertex].xyz;
let phase = frame.extent.z * (4.0 + instance.motion.y * 1.3) + instance.motion.x;
if (instance.motion.z < 0.5) {
local.y += sin(phase) * abs(local.x) * 0.5;
} else {
local.x += sin(phase + local.z * 4.0) * max(-local.z, 0.0) * 0.2;
}
let world = instance.position_scale.xyz + instance.position_scale.w * (instance.right.xyz * local.x + instance.up.xyz * local.y + instance.forward.xyz * local.z);
var out: Out;
out.clip = frame.view_proj * vec4f(world, 1.0);
out.distance = length(world - frame.eye.xyz);
let light = 0.45 + 0.55 * max(0.0, dot(normalize(instance.up.xyz + vec3f(0.0, 0.3, 0.0)), normalize(frame.sun.xyz)));
out.color = select(vec3f(0.72, 0.58, 0.43), vec3f(0.28, 0.54, 0.63), instance.motion.z > 0.5) * light * frame.sun_color.rgb;
return out;
}
@fragment fn fs_main(in: Out) -> @location(0) vec4f {
if (in.distance > textureLoad(scene_depth, vec2i(in.clip.xy), 0).x) { discard; }
return vec4f(in.color, 1.0);
}
"#;