Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Created August 23, 2013 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjameshuff/6314271 to your computer and use it in GitHub Desktop.
Save cjameshuff/6314271 to your computer and use it in GitHub Desktop.
class Fault: public TerrainFn {
protected:
const float4 center;
const float4 plane;
const float4 displacement;
const float amplitude;
public:
Fault(fn_handle _input, float4 c, float4 p, float amp):
TerrainFn{std::move(_input)},
center{c},
plane{vnormalized3(p)},
displacement{vnormalized3(vcross3(y_cross3(p), p))*amp},
amplitude(amp)
{}
virtual auto operator()(float4 pt) -> VolumeVal
{
auto dir = pt - center;
float t = vdot3(dir, plane);
float lowd = 2.0f/(1.0f + std::fabs(t/amplitude));
float highd = 1.0f/(1.0f + sqr(t/amplitude));
if(t < 0.0f) {
// Do lower half of fault + spillover
VolumeVal low = (*input)(pt - displacement*lowd);
if(low.type != kAirVolume)
return low;
else // spillover
return (*input)(pt + displacement*highd + float4{0.0f, sqr(t/amplitude)*4.0f, 0.0f});
}
else {
// do upper half of fault
return (*input)(pt + displacement*highd);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment