Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ engine/pill_engine/docs/uml_out/*
engine/target_*

*.log
*.wgsl
2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
"pill_native",
"pill_web",
"pill_runtime",
"/Users/mk/dev/demo/Pill-Engine-Upstream/examples/cube", ### Game project crate (This will be changed by Pill Launcher on build to allow proper compilation of game project)
"NO_PATH", ### Game project crate (This will be changed by Pill Launcher on build to allow proper compilation of game project)
]

# The per-game wasm cdylib (pill_web_app) lives as a template at
Expand Down
13 changes: 8 additions & 5 deletions engine/pill_assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ impl Pipeline {
.to_str()
.with_context(|| format!("non-UTF8 path in pipeline root: {pattern:?}"))?;

let matches = glob::glob(pattern_str)
.with_context(|| format!("invalid glob {pattern_str:?} for rule {}", rule.name()))?;
let matches = glob::glob(pattern_str).with_context(|| {
format!("invalid glob {pattern_str:?} for rule {}", rule.name())
})?;

for entry in matches {
let input = entry.with_context(|| format!("glob entry error for rule {}", rule.name()))?;
let input =
entry.with_context(|| format!("glob entry error for rule {}", rule.name()))?;
stats.discovered.push(input.clone());

let output = rule.output_for(&input);
Expand All @@ -79,8 +81,9 @@ impl Pipeline {
.with_context(|| format!("create output dir {parent:?}"))?;
}

rule.build(&input, &output)
.with_context(|| format!("rule {} failed: {input:?} -> {output:?}", rule.name()))?;
rule.build(&input, &output).with_context(|| {
format!("rule {} failed: {input:?} -> {output:?}", rule.name())
})?;
stats.rebuilt.push(output);
}
}
Expand Down
5 changes: 4 additions & 1 deletion engine/pill_engine/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ fn main() {
// Header-include directory: tracked recursively so changes to shared
// structs (common.hlsl) re-trigger the build. The glob doesn't pick these
// up (HlslToWgsl matches top-level shaders/*.hlsl only).
println!("cargo:rerun-if-changed={}", root.join("shaders/include").display());
println!(
"cargo:rerun-if-changed={}",
root.join("shaders/include").display()
);
for input in &stats.discovered {
println!("cargo:rerun-if-changed={}", input.display());
}
Expand Down
53 changes: 30 additions & 23 deletions engine/pill_engine/res/shaders/default_lit_fragment.hlsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Default lit fragment shader. Edit here — `pill_assets` regenerates the .wgsl.
// Diffuse + normal mapped, single point light, exp-squared depth fog.
// Diffuse + normal mapped, two lights, exp-squared depth fog.

#include "include/common.hlsl"

struct MaterialParams {
float3 tint;
float specularity;
float _pad; // Rust renderer writes Color as 16 bytes (xyz + 1 float pad); spec lands at offset 16
float spec;
};
[[vk::binding(0, 2)]] ConstantBuffer<MaterialParams> material;

Expand All @@ -23,35 +24,41 @@ float4 fs_main(
[[vk::location(4)]] float3 in_TBN_normal : TEXCOORD4,
[[vk::location(5)]] float3 in_world_position : TEXCOORD5
) : SV_TARGET {
// Settings (single point light, hard-coded).
const float ambient_light_strength = 0.02;
const float3 light_position = float3(-10.0, 10.0, -10.0);
const float3 light_color = float3(1.0, 1.0, 1.0);
// Key light: blue, diffuse-dominant, high above-front-left.
const float ambient_strength = 0.28;
const float3 key_dir = float3(-4.0, 12.0, -10.0);
const float3 key_color = float3(0.45, 0.55, 1.0);

// Spec light: white, tight highlight, from lower-right-front for a cross-axis streak.
const float3 spec_dir = float3(6.0, -3.0, -8.0);
const float3 spec_color = float3(1.0, 1.0, 1.0);
const float spec_exponent = 154.0;

float4 object_color = diffuse_texture.Sample(diffuse_sampler, in_vertex_texture_coords);
float4 object_normal = normal_texture.Sample(normal_sampler, in_vertex_texture_coords);

// Reconstruct TBN from per-vertex rows.
float3x3 TBN_matrix = float3x3(in_TBN_tangent, in_TBN_bitangent, in_TBN_normal);

float3 ambient_light_factor = light_color * ambient_light_strength;
// TBN is tangent-to-world (vertex shader stores the transpose).
float3x3 TBN_matrix = float3x3(in_TBN_tangent, in_TBN_bitangent, in_TBN_normal);
float3 normal_tangent = normalize(object_normal.rgb * 2.0 - 1.0);
float3 normal = normalize(mul(TBN_matrix, normal_tangent));

// Diffuse — normal map is in [0,1]; rescale to [-1,1].
float3 normal = normalize(object_normal.rgb * 2.0 - 1.0);
float3 light_direction = normalize(mul(TBN_matrix, light_position) - in_vertex_position);
float3 view_direction = normalize(camera.camera_position - in_world_position);

float diffuse_light_strength = max(dot(normal, light_direction), 0.0);
float3 diffuse_light_factor = light_color * diffuse_light_strength;
// Key light — diffuse + soft specular.
float3 key_light_dir = normalize(key_dir);
float key_diffuse = max(dot(normal, key_light_dir), 0.0);
float3 key_half = normalize(view_direction + key_light_dir);
float key_spec = pow(max(dot(normal, key_half), 0.0), 24.0) * material.spec * 0.4;
float3 key_contribution = key_color * (ambient_strength + key_diffuse * 1.2);

// Specular (Blinn-Phong, fixed exponent 32).
float3 view_direction = normalize(mul(TBN_matrix, camera.camera_position) - in_vertex_position);
float3 half_direction = normalize(view_direction + light_direction);
float specular_light_strength = pow(max(dot(normal, half_direction), 0.0), 32) * material.specularity;
float3 specular_light_factor = light_color * specular_light_strength;
// Spec light — specular only, crisp white streak.
float3 spec_light_dir = normalize(spec_dir);
float3 spec_half = normalize(view_direction + spec_light_dir);
float spec_strength = pow(max(dot(normal, spec_half), 0.0), spec_exponent) * material.spec * 3.0;
float3 spec_contribution = spec_color * spec_strength;

float3 final_color = (ambient_light_factor + diffuse_light_factor + specular_light_factor)
* object_color.xyz
* material.tint;
float3 final_color = key_contribution * object_color.xyz * material.tint
+ (key_color * key_spec + spec_contribution);

// Exponential-squared depth fog. density = 0 → no fog, bit-identical output.
float fog_dist = length(camera.camera_position - in_world_position);
Expand Down
73 changes: 0 additions & 73 deletions engine/pill_engine/res/shaders/default_lit_fragment.wgsl

This file was deleted.

56 changes: 0 additions & 56 deletions engine/pill_engine/res/shaders/default_unlit_fragment.wgsl

This file was deleted.

115 changes: 0 additions & 115 deletions engine/pill_engine/res/shaders/default_vertex.wgsl

This file was deleted.

1 change: 1 addition & 0 deletions engine/pill_engine/res/shaders/include/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
struct EngineParams {
float3 fog_color;
float fog_density;
float delta_time;
};
[[vk::binding(0, 0)]] ConstantBuffer<EngineParams> engine;

Expand Down
2 changes: 1 addition & 1 deletion engine/pill_engine/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub const DEFAULT_LIT_SHADER_COLOR_TEXTURE_SLOT_BINDINGS: (u32, u32) = (0, 1);
pub const DEFAULT_LIT_SHADER_NORMAL_TEXTURE_SLOT_NAME: &str = "normal";
pub const DEFAULT_LIT_SHADER_NORMAL_TEXTURE_SLOT_BINDINGS: (u32, u32) = (2, 3);
pub const DEFAULT_LIT_SHADER_TINT_PARAMETER_SLOT_NAME: &str = "tint";
pub const DEFAULT_LIT_SHADER_SPECULARITY_PARAMETER_SLOT_NAME: &str = "specularity";
pub const DEFAULT_LIT_SHADER_SPEC_PARAMETER_SLOT_NAME: &str = "spec";
pub const DEFAULT_LIT_MATERIAL_NAME: &str = "pill_engine_default_lit_material";

pub const DEFAULT_UNLIT_SHADER_NAME: &str = "pill_engine_default_unlit_shader";
Expand Down
Loading