MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu-shadertoys / normal

Method normal

shaders/src/morphing.rs:177–192  ·  view source on GitHub ↗
(&self, p: Vec3, ray: Vec3, t: f32)

Source from the content-addressed store, hash-verified

175
176impl State {
177 fn normal(&self, p: Vec3, ray: Vec3, t: f32) -> Vec3 {
178 let pitch: f32 = 0.4 * t / self.inputs.resolution.x;
179 let d: Vec2 = vec2(-1.0, 1.0) * pitch;
180 // tetrahedral offsets
181 let p0: Vec3 = p + d.xxx();
182 let p1: Vec3 = p + d.xyy();
183 let p2: Vec3 = p + d.yxy();
184 let p3: Vec3 = p + d.yyx();
185 let f0: f32 = self.m(p0);
186 let f1: f32 = self.m(p1);
187 let f2: f32 = self.m(p2);
188 let f3: f32 = self.m(p3);
189 let grad: Vec3 = p0 * f0 + p1 * f1 + p2 * f2 + p3 * f3 - p * (f0 + f1 + f2 + f3);
190 // prevent normals pointing away from camera (caused by precision errors)
191 (grad - (grad.dot(ray).max(0.0)) * ray).normalize()
192 }
193
194 pub fn main_image(&mut self, frag_color: &mut Vec4, frag_coord: Vec2) {
195 let aa: f32 = 3.14159 / 4.0;

Callers 1

main_imageMethod · 0.45

Calls 1

mMethod · 0.80

Tested by

no test coverage detected