8
#define WIN32_LEAN_AND_MEAN
10
#pragma warning(disable : 4996)
16
#include "RIB_parser.h"
18
// for points/curves test
25
//---------------------------------------------------------------------------
26
// global operators new & delete, to keep track of total memory allocated
28
// this code snippet from heaplayers library, not sure if flags are really all necessary (or correct..)
29
#if defined (_MSC_VER)
30
inline size_t getSize(void* ptr) { return _msize(ptr); }
31
#elif defined (__GNUC__) && !defined(__SVR4)
32
inline size_t getSize(void* ptr) { return malloc_usable_size(ptr); }
33
#elif defined (__APPLE__)
34
inline size_t getSize(void* ptr) { return malloc_size(ptr); }
37
static size_t curmem = 0; // current amount of memory allocated
38
static size_t maxmem = 0; // maximum amount of memory allocated
40
void* operator new(std::size_t sz) throw (std::bad_alloc)
42
#if defined (__GNUC__) && !defined(__SVR4)
43
void* ptr = memalign(8, sz);
45
void* ptr = malloc((sz & 7) ? ((sz & 0xfffffffffffffff8) + 8) : (sz & 0xfffffffffffffff8));
47
if (ptr == NULL) throw std::bad_alloc();
48
if ((curmem += getSize(ptr)) > maxmem) maxmem = curmem;
52
void* operator new[](std::size_t sz) throw (std::bad_alloc)
54
#if defined (__GNUC__) && !defined(__SVR4)
55
void* ptr = memalign(8, sz);
57
void* ptr = malloc((sz & 7) ? ((sz & 0xfffffffffffffff8) + 8) : (sz & 0xfffffffffffffff8));
59
if (ptr == NULL) throw std::bad_alloc();
60
if ((curmem += getSize(ptr)) > maxmem) maxmem = curmem;
64
void operator delete(void* ptr) throw()
67
curmem -= getSize(ptr);
72
void operator delete[](void* ptr) throw()
75
curmem -= getSize(ptr);
80
//-------------------------------------------------------------------------------------------------------------------------------------
81
// basic commandline render, no option overrides yet
84
void dbout(const std::string &msg)
86
std::cout << msg << std::endl;
89
int main(int argc, char* argv[])
92
std::cout << "Usage: " << argv[0] << " ribfile" << std::endl;
97
// disable float exceptions
98
_control87(MCW_EM, MCW_EM);
101
QDRender::RIBparse_t rp; //(dbout);
104
std::cout << "Total memory allocated: " << maxmem << "( " << (maxmem/(float)(1 << 20)) << " Mb )\n" << std::endl;
108
//-------------------------------------------------------------------------------------------------------------------------------------
115
// disable float exceptions
116
_control87(MCW_EM, MCW_EM);
121
//RiDisplay("curvehair.tga", RI_FILE, RI_RGB, RI_NULL);
122
RiDisplay("curvehair", RI_FRAMEBUFFER, RI_RGB, RI_NULL);
124
RiProjection("perspective", RI_FOV, &fov, RI_NULL);
126
//RiExposure(1.f, 0.666666f);
127
RiFormat(800, 800, 1);
128
RiPixelSamples(4, 4);
129
// cropwindow is useful to only render parts of image when rendering huge number of hairs.
130
//RiCropWindow(0, 0.5, 0, 0.5);
132
RiTranslate(0, 0.1, 5);
137
//RiLightSource("ambientlight", "intensity", &int1, RI_NULL);
139
RtPoint from = {6, 6, 6};
140
RtPoint to = {0, 0, 0};
142
RiLightSource("distantlight", "intensity", &int2, "from", &from, "to", &to, RI_NULL);
144
const float srad = 1.25f;
145
//RiAttributeBegin();
146
//RiSurface("matte", RI_NULL);
147
//RtColor sc = {0.25, 0.025, 0.0025};
149
//RiSphere(srad, -srad, srad, 360, RI_NULL);
152
//RtFloat rg = 0.15f, ks = 0.2, kd = 0.8;
153
RiSurface("hair", RI_NULL); //"roughness", &rg, "Ks", &ks, "Kd", &kd, RI_NULL);
154
//RtFloat sp1 = 0.1, sp2 = 0.03;
155
//RiSurface("SIG2k_srf_fur", "color rootcolor", &sc, "float SPEC1", &sp1, "float SPEC2", &sp2, RI_NULL);
157
// 1500000 hairs at 1000x1000 res with 8x8 samples and 4x4 sinc filter, 16 max gridsize:
158
// 10080772 prims, 5173370 grids, 39143712 mp's, +23285sec, 319.9Mb... horrible...
159
// (Cause of the bad rendertime is only having 512Mb, so it was basicaly all HD swapping,
160
// taskmanager indicated a mem usage of about 770Mb, cpu was barely active at all...)
163
// -16.4sec 28.6Mb with sqrt(maxgridsize) splitting
165
// +15.5sec 26.7Mb, immediate split into individual segments (with forced no split 14.2s 47Mb)
166
// +15.3sec 24.4Mb separate saving of P, excluded from primvar
168
//RiBasis(RiBezierBasis, RI_BEZIERSTEP, RiBSplineBasis, RI_BSPLINESTEP);
169
// make a sphere with hair
170
const int numhairs = 100000;
171
const int numcp = 4; // number of control points, 4 minimum
172
RtPoint* pts = new RtPoint[numhairs*numcp];
173
RtInt* verts = new RtInt[numhairs];
174
RtFloat* wd = new RtFloat[numhairs*2]; // 4 cp, 2 varyings
175
const QDRender::stdPerlin_t ngen;
176
for (int i=0; i<numhairs; ++i) {
177
QDRender::Point3 sp = srad*QDRender::RandomVectorSphere();
178
if (sp.z > 0.f) sp *= -1.f; // all hairs on the font of the sphere
179
QDRender::Vector op = toVector(sp).normalize();
180
for (int j=0; j<numcp; ++j) {
181
int icp = i*numcp + j;
182
pts[icp][0] = sp.x, pts[icp][1] = sp.y, pts[icp][2] = sp.z;
183
QDRender::Point3 tp = sp*4.38462f;
184
QDRender::Point3 ofs(QDRender::getSignedNoise(&ngen, tp),
185
QDRender::getSignedNoise(&ngen, tp + QDRender::Point3(10.1)),
186
QDRender::getSignedNoise(&ngen, tp - QDRender::Point3(10.1)));
187
ofs = 0.5f*(op + ofs);
188
sp += (0.3f*QDRender::frand() + 0.2f)*ofs;
190
// add some random 'gravity' to the hair endpoint to make it slope downwards
191
pts[i*numcp + numcp - 1][1] -= 0.25f*QDRender::frand();
196
RiCurves("cubic", numhairs, verts, "nonperiodic", "P", pts, "width", wd, RI_NULL);
197
//RtFloat cwd = 0.001f;
198
//RiCurves("cubic", numhairs, verts, "nonperiodic", "P", pts, "constantwidth", &cwd, RI_NULL);
199
// arrays can now be deleted here
208
std::cout << "Total memory allocated: " << maxmem << "( " << (maxmem/(float)(1 << 20)) << " Mb )\n" << std::endl;
215
// while it works, memory usage is rather inefficient, just one million particles already use up 150-200Mb
216
// It is possible to rasterize directly though, no micropolys needed TODO
220
// disable float exceptions
221
_control87(MCW_EM, MCW_EM);
226
RiDisplay("points test", RI_FRAMEBUFFER, RI_RGB, RI_NULL);
228
RiProjection("perspective", RI_FOV, &fov, RI_NULL);
230
RiFormat(512, 512, 1);
231
RiPixelSamples(4, 4);
232
RiExposure(1.5, 0.75);
234
RiTranslate(0, 0, 5);
238
// constant color with additive blending
239
RiSurface("constadd", RI_NULL);
243
const int nump = (int)pow(nh3*2, 3);
244
RtPoint* pts = new RtPoint[nump];
245
RtColor* cols = new RtColor[nump];
246
const QDRender::blenderNoise_t ngen;
247
const float sc = 0.025;
248
const float csc = 0.0025;
250
const float nh3d = 1.f/(2*nh3);
251
for (int z=-nh3; z<nh3; ++z) {
252
for (int y=-nh3; y<nh3; ++y) {
253
for (int x=-nh3; x<nh3; ++x) {
254
const QDRender::Point3 tp(x*sc, y*sc, z*sc);
255
cols[i][0] = ngen(tp);
256
cols[i][1] = ngen(tp + QDRender::Point3(1.984851f));
257
cols[i][2] = ngen(tp - QDRender::Point3(5.8456f));
258
//cols[i][0] = 0.5f + x*nh3d, cols[i][1] = 0.5f + y*nh3d, cols[i][2] = 0.5f + z*nh3d;
259
pts[i][0] = rad * (2.f*cols[i][0] - 1.f);
260
pts[i][1] = rad * (2.f*cols[i][1] - 1.f);
261
pts[i][2] = rad * (2.f*cols[i][2] - 1.f);
262
cols[i][0] *= csc, cols[i][1] *= csc, cols[i][2] *= csc;
267
std::cout << "TOTAL POINTS: " << nump << std::endl;
268
const float cw = 0.075;
270
RiRotate(45, 1, 0, 0);
271
RiPoints(nump, "P", pts, "constantwidth", &cw, "Cs", cols, RI_NULL);
280
std::cout << "Total memory allocated: " << maxmem << "( " << (maxmem/(float)(1 << 20)) << " Mb )\n" << std::endl;