Created
August 23, 2013 00:17
-
-
Save cjameshuff/6314271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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