Skip to content

Commit

Permalink
Merge pull request #71 from alphastrata/chore/misc-updates
Browse files Browse the repository at this point in the history
chore: misc updates to reset-3d script, add a few functions to common.wgsl and some new consts too
  • Loading branch information
alphastrata authored Nov 26, 2023
2 parents 3f5d59f + baf52ac commit c5e46ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion assets/shaders/myshader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//! The default 3d Shader.
//!
#import bevy_pbr::forward_io::VertexOutput
#import bevy_pbr::mesh_view_bindings::globals;
#import bevy_pbr::utils PI
#import bevy_sprite::mesh2d_view_bindings globals
#import shadplay::shader_utils::common NEG_HALF_PI, shader_toy_default, rotate2D

#import bevy_render::view View
Expand Down
10 changes: 4 additions & 6 deletions scripts/reset-3d.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
THREE3_SHADER_STARTER = """//!
//! The default 3d Shader.
//!
#import bevy_sprite::mesh2d_view_bindings::globals
#import shadplay::shader_utils::common::{NEG_HALF_PI, shader_toy_default, rotate2D, TWO_PI}
#import bevy_pbr::forward_io::VertexOutput;
#import bevy_render::view::View
#import bevy_pbr::forward_io::VertexOutput
#import bevy_pbr::mesh_view_bindings::globals;
#import bevy_pbr::utils PI
#import shadplay::shader_utils::common NEG_HALF_PI, shader_toy_default, rotate2D
@group(0) @binding(0) var<uniform> view: View;
Expand Down
17 changes: 16 additions & 1 deletion src/shader_utils/common.wgsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#define_import_path shadplay::shader_utils::common

// The circle family
const PI:f32 = 3.14159265359;
const HALF_PI = 1.57079632679;
const NEG_HALF_PI = -1.57079632679;
const NEG_QUARTER_PI = -0.78539816339;
const PI:f32 = 3.14159265359;
const QUARTER_PI = -0.78539816339;
const TAU:f32 = 6.28318530718;

// Euler's number / Napier's constant
const E: f32 = 2.71828182845;

// Pythagoras' constants
const SQRT_OF_2:f32 = 1.41421356237;
const SQRT_OF_3:f32 = 1.73205080756;

// The golden ratio
const PHI:f32 = 1.61803398874;

/// Turn your `uv` coords into polar coords
fn intoPolar(uv: vec2<f32>)-> vec2<f32>{
return vec2f(atan2(uv.x, uv.y), length(uv));
}

/// Clockwise by `theta`
fn rotate2D(theta: f32) -> mat2x2<f32> {
Expand Down

0 comments on commit c5e46ac

Please sign in to comment.