Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaoyaoing #80

Merged
merged 3 commits into from
Oct 26, 2023
Merged
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
Binary file added scenes/curly-hair/models/wCurly.fiber
Binary file not shown.
80 changes: 80 additions & 0 deletions scenes/curly-hair/scene.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"mediums": [],
"materials": [
{
"name": "hair",
"albedo": 1,
"type": "hair",
"scale_angle": 2.5,
"melanin_ratio": 1,
"melanin_concentration": 1.3,
"roughness": 0.3
}
],
"entities": [
{
"transform":[0,0,0.1,0,0.13,0,0,0,0,0.1,0,0,0,9.4,0,1],
"type": "curves",
"file": "models/wCurly.fiber",
"curve_thickness": 0.05,
"curve_taper": false,
"subsample": 0,
"material": "hair",
"width_scale" : 0.111
},{
"cap_dir": [0.19,0.75,-0.62],
"power": 20,
"type": "infinite_sphere_cap",
"sample": true,
"cap_angle": 10
}

],
"camera": {
"tonemap": "filmic",
"resolution": 1024,
"reconstruction_filter": "tent",
"transform": {
"position": [
-0.234672,
16.5124,
-25.3482
],
"look_at": [
0.134185,
9.92412,
-0.828005
],
"up": [
0,
1,
0
]
},
"type": "pinhole",
"fov": 35
},
"integrator": {
"min_bounces": 1,
"max_bounces": 64,
"enable_consistency_checks": false,
"enable_two_sided_shading": true,
"type": "path_tracer",
"enable_light_sampling": true,
"enable_volume_light_sampling": true
},
"renderer": {
"output_file": "curly-hair",
"resume_render_prefix": "TungstenRenderState",
"overwrite_output_files": false,
"adaptive_sampling": true,
"enable_resume_render": false,
"stratified_sampler": true,
"scene_bvh": true,
"spp": 1,
"spp_step": 16,
"checkpoint_interval": "0",
"timeout": "0",
"hdr_output_file": "curly-hair.exr"
}
}
38 changes: 28 additions & 10 deletions src/CoreLayer/Geometry/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,41 @@ struct Frame {

/** \brief Assuming that the given direction is in the local coordinate
* system, return the cosine of the angle between the normal and v */
static float cosTheta(const Vec3d &v) {
static double cosTheta(const Vec3d &v) {
return v.z;
}

/** \brief Assuming that the given direction is in the local coordinate
* system, return the sine of the angle between the normal and v */
static float sinTheta(const Vec3d &v) {
float temp = sinTheta2(v);
static double sinTheta(const Vec3d &v) {
double temp = sinTheta2(v);
if (temp <= 0.0f)
return 0.0f;
return fm::sqrt(temp);
}

/** \brief Assuming that the given direction is in the local coordinate
* system, return the tangent of the angle between the normal and v */
static float tanTheta(const Vec3d &v) {
float temp = 1 - v.z*v.z;
static double tanTheta(const Vec3d &v) {
double temp = 1 - v.z*v.z;
if (temp <= 0.0f)
return 0.0f;
return fm::sqrt(temp) / v.z;
}

/** \brief Assuming that the given direction is in the local coordinate
* system, return the Squared sine of the angle between the normal and v */
static float sinTheta2(const Vec3d &v) {
static double sinTheta2(const Vec3d &v) {
return 1.0f - v.z * v.z;
}

/** \brief Assuming that the given direction is in the local coordinate
* system, return the sine of the phi parameter in spherical coordinates */
static float sinPhi(const Vec3d &v) {
float sinTheta = Frame::sinTheta(v);
static double sinPhi(const Vec3d &v) {
double sinTheta = Frame::sinTheta(v);
if (sinTheta == 0.0f)
return 1.0f;
return clamp(v.y / sinTheta, -1.0f, 1.0f);
return 1.0;
return clamp(v.y / sinTheta, -1.0, 1.0);
}


Expand All @@ -117,4 +117,22 @@ struct Frame {
static Vec3d reflect(const Vec3d &wo, const Vec3d & n) {
return -wo + 2 * dot(wo, n) * n;
}

static Frame FromZ(Normal3d z) {
Vec3d x, y;
coordinateSystem(z, x, y);
return Frame(x,y,z);
}

static Frame FromX(Normal3d x) {
Vec3d y, z;
coordinateSystem(x, y, z);
return Frame(x, y, z);
}

static Frame FromY(Normal3d y) {
Vec3d x, z;
coordinateSystem(y, z, x);
return Frame(x, y, z);
}
};
1 change: 1 addition & 0 deletions src/CoreLayer/Geometry/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using Vec2d = TVector2<double>;
using Vec2i = TVector2<int>;
using Vec3f = TVector3<float>;
using Vec3d = TVector3<double>;
using Vec4d = TVector4<double>;
using Vec3i = TVector3<int>;
// Point.h
template <typename T>
Expand Down
94 changes: 94 additions & 0 deletions src/CoreLayer/Geometry/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,100 @@ struct TVector3 {
}
};


template <typename T>
struct TVector4 {
T x, y, z,w;

TVector4 () { }

TVector4 (T _x, T _y, T _z,T _w) : x(_x), y(_y), z(_z),w(_w) { }

explicit TVector4 (T t) : x(t), y(t), z(t),w(t) { }

/*--- operator overloading ---*/
TVector4 operator+(T value) const {
return TVector4(x + value , y + value, z + value, w + value);
}

TVector4 operator+(const TVector4 &rhs) const {
return TVector4(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w);
}

TVector4& operator+=(const TVector4 &rhs) {
x += rhs.x, y += rhs.y, z += rhs.z, w+=rhs.w;
return *this;
}

TVector4 operator-(T value) const {
return TVector4(x - value , y - value, z -value, w -value);
}

TVector4 operator-(const TVector4 &rhs) const {
return TVector4(x-rhs.x, y-rhs.y, z-rhs.z, w-rhs.w);
}

TVector4& operator-=(const TVector4 &rhs) {
x -= rhs.x, y -= rhs.y, z -= rhs.z,w -= rhs.w;
return *this;
}

TVector4 operator*(const T t) const {
return TVector4(x*t, y*t, z*t, w*t);
}

TVector4 operator*(const TVector4 &rhs) const {
return TVector4(x * rhs.x, y * rhs.y, z * rhs.z,w * rhs.z);
}

TVector4& operator*=(const T t) {
x*=t, y*=t, z*=t, w*=t;
return *this;
}

TVector4 operator/(const T t) const {
assert(t != 0);
T recip = (T) 1/t;
return TVector4(x*recip, y*recip, z*recip, w*recip);
}

TVector4 operator/(const TVector4 &rhs) const {
return TVector4(x / rhs.x, y / rhs.y, z / rhs.z, w/rhs.w);
}

TVector4& operator/=(const T t) {
assert(t != 0);
T recip = (T) 1/t;
x*=recip, y*=recip, z*=recip, w*=recip;
return *this;
}

TVector4 operator-() const {
return TVector4(-x, -y, -z,-w);
}

T operator[](const int i) const {
return (&x)[i];
}

T& operator[](const int i) {
return (&x)[i];
}


bool operator==(const TVector4 &rhs) const {
return x==rhs.x && y==rhs.y && z==rhs.z && w==rhs.w;
}

bool operator!=(const TVector4 &rhs) const {
return x!=rhs.x || y!=rhs.y || z!=rhs.z || w!=rhs.w;
}

bool isZero() const {
return x==0 && y==0 && z==0 && w==0;
}
};

template <typename T>
std::ostream& operator<<(std::ostream &os, const TVector3<T> &v) {
os << v.x << " " << v.y << " " << v.z;
Expand Down
8 changes: 0 additions & 8 deletions src/CoreLayer/Math/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ constexpr double INV_TWOPI = 0.15915494309189533577f;
constexpr double ONEMINUSEPSILON = 1 - std::numeric_limits<double>::epsilon();
constexpr double EPSILON = std::numeric_limits<double>::epsilon();

/// Simple floating point clamping function
inline float clamp(float value, float min, float max) {
if (value < min)
return min;
else if (value > max)
return max;
else return value;
}

template<class T>
inline T clamp(T x, T minVal, T maxVal) {
Expand Down
Loading