void ShaderInfoHelper::buildStandardImageShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("diff_col", Col3f(0.6f, 0.6f, 0.6f)); helper.addStringParam("diff_col_texture"); helper.addFloatSliderParam("diff_roughness", 0.0f); helper.addStringParam("diff_roughness_texture"); helper.addFloatSliderParam("diff_backlit", 0.0f); helper.addStringParam("diff_backlit_texture"); helper.addColourParam("spec_col", Col3f(0.0f, 0.0f, 0.0f)); helper.addStringParam("spec_col_texture"); helper.addFloatSliderParam("spec_roughness", 0.15f); helper.addStringParam("spec_roughness_texture"); helper.addStringPopupParam("microfacet_type", "beckmann", microfacetTypeOptions, 3); helper.addFloatSliderParam("reflection", 0.0f); helper.addFloatSliderParam("reflection_roughness", 0.0f); helper.addBoolParam("fresnel", true); helper.addFloatSliderParam("fresnel_coef", 0.0f); helper.addFloatParam("refraction_index", 1.49f); helper.addFloatSliderParam("transparency", 0.0f); helper.addFloatSliderParam("transmission", 0.0f); helper.addBoolParam("double_sided", 0); }
void ShaderInfoHelper::buildGridTextureParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addFloatSliderParam("scaleU", 1.0f, 0.0001f, 100.0f); helper.addFloatSliderParam("scaleV", 1.0f, 0.0001f, 100.0f); helper.addColourParam("colour1", Col3f(0.0f, 0.0f, 0.0f)); helper.addColourParam("colour2", Col3f(1.0f, 1.0f, 1.0f)); }
void ShaderInfoHelper::buildVelvetShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("horiz_col", Col3f(0.7f, 0.7f, 0.7f)); helper.addStringParam("horiz_col_texture"); helper.addFloatSliderParam("horiz_scatter_falloff", 0.4f); helper.addColourParam("backscatter_col", Col3f(0.4f, 0.4f, 0.4f)); helper.addStringParam("backscatter_col_texture"); helper.addFloatSliderParam("backscatter", 0.7f); }
void ShaderInfoHelper::buildWireframeTextureParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("interior_colour", Col3f(0.6f, 0.6f, 0.6f)); helper.addFloatSliderParam("line_width", 0.005f, 0.0f, 10.0f); helper.addColourParam("line_colour", Col3f(0.01f, 0.01f, 0.01f)); helper.addFloatSliderParam("edge_softness", 0.3f); helper.addIntParam("edge_type", 1); }
void ShaderInfoHelper::buildMetallicPaintShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("colour", Col3f(0.29f, 0.016f, 0.019f)); helper.addStringParam("col_texture"); helper.addColourParam("flake_colour", Col3f(0.39, 0.016f, 0.19f)); helper.addFloatSliderParam("flake_spread", 0.32f); helper.addFloatSliderParam("flake_mix", 0.38f); helper.addFloatParam("refraction_index", 1.39f); helper.addFloatSliderParam("reflection", 1.0f); helper.addFloatSliderParam("fresnel_coef", 0.0f); }
void ShaderInfoHelper::buildCommonLightShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo, bool addColour, bool visibleOn) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addFloatSliderParam("intensity", 1.0f, 0.0f, 100.0f); helper.addFloatSliderParam("exposure", 0.0f, 0.0f, 25.0f); if (addColour) { helper.addColourParam("colour", Col3f(1.0f, 1.0f, 1.0f)); } helper.addStringPopupParam("shadow_type", "normal", shadowTypeOptions, 3); helper.addIntParam("num_samples", 1); helper.addBoolParam("visible", visibleOn); #ifdef KAT_V_2 setShaderParameterMapping(iri, rendererObjectInfo, "shader", "imagineLightShader"); if (addColour) { setShaderParameterMapping(iri, rendererObjectInfo, "color", "imagineLightParams.colour"); } setShaderParameterMapping(iri, rendererObjectInfo, "intensity", "imagineLightParams.intensity"); setShaderParameterMapping(iri, rendererObjectInfo, "exposure", "imagineLightParams.exposure"); #endif }
void ShaderInfoHelper::buildPlasticShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("colour", Col3f(0.5f, 0.5f, 1.0f)); helper.addFloatSliderParam("roughness", 0.1f); helper.addFloatSliderParam("fresnel_coef", 0.0f); helper.addFloatParam("refraction_index", 1.39f); }
void ShaderInfoHelper::buildSwatchTextureParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addFloatSliderParam("scaleU", 1.0f, 0.0001f, 100.0f); helper.addFloatSliderParam("scaleV", 1.0f, 0.0001f, 100.0f); helper.addStringPopupParam("grid_type", "hue", swatchGridTypeOptions, 3); helper.addColourParam("grid_colour", Col3f(0.64f, 0.64f, 0.64f)); helper.addBoolParam("checkerboard", false); }
void ShaderInfoHelper::buildBrushedMetalShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("colour", Col3f(0.9f, 0.9f, 0.9f)); helper.addFloatParam("refraction_index", 1.39f); helper.addFloatParam("k", 4.8f); helper.addFloatSliderParam("roughness_x", 0.1f); helper.addFloatSliderParam("roughness_y", 0.02f); helper.addBoolParam("double_sided", 0); }
void ShaderInfoHelper::buildTranslucentShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("surface_col", Col3f(0.4f, 0.4f, 1.0f)); helper.addStringParam("surface_col_texture"); helper.addColourParam("specular_col", Col3f(0.1f, 0.1f, 0.1f)); helper.addStringParam("specular_col_texture"); helper.addFloatParam("specular_roughness", 0.05f); helper.addColourParam("inner_col", Col3f(0.4f, 0.4f, 0.4f)); helper.addFloatSliderParam("subsurface_density", 3.1f, 0.0001f, 10.0f); helper.addFloatSliderParam("sampling_density", 0.35f, 0.001f, 2.0f); helper.addFloatSliderParam("transmittance", 0.41f); helper.addFloatSliderParam("transmittance_roughness", 0.7f); helper.addFloatSliderParam("absorption_ratio", 0.46f); helper.addFloatParam("refractionIndex", 1.42f); }
void ShaderInfoHelper::buildMetalShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("colour", Col3f(0.9f, 0.9f, 0.9f)); helper.addFloatParam("refraction_index", 1.39f); helper.addFloatParam("k", 4.8f); helper.addFloatSliderParam("roughness", 0.01f); helper.addIntEnumParam("microfacet_type", 1, microfacetTypeOptions, 3); helper.addBoolParam("double_sided", 0); }
void ShaderInfoHelper::buildLuminousShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("colour", Col3f(1.0f, 1.0f, 1.0f)); helper.addFloatSliderParam("intensity", 1.0f, 0.0f, 20.0f); helper.addBoolParam("register_as_light", 0); helper.addFloatSliderParam("light_intensity", 1.0f, 0.0f, 10.0f); helper.addFloatSliderParam("light_exposure", 3.0f, 0.0f, 20.0f); helper.addBoolParam("light_quadratic_falloff", 1); helper.addBoolParam("light_weight_by_surface_area", 1); }
void ShaderInfoHelper::buildTranslucentShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("surface_col", Col3f(0.0f, 0.0f, 0.0f)); helper.addStringParam("surface_col_texture"); helper.addColourParam("specular_col", Col3f(0.1f, 0.1f, 0.1f)); helper.addStringParam("specular_col_texture"); helper.addFloatSliderParam("specular_roughness", 0.05f); helper.addStringPopupParam("surface_type", "diffuse", translucentSurfaceTypeOptions, 3); helper.addStringPopupParam("scatter_mode", "mean free path", translucentScatterModeOptions, 2); helper.addColourParam("inner_col", Col3f(0.4f, 0.4f, 0.4f)); helper.addFloatSliderParam("subsurface_density", 3.1f, 0.0001f, 10.0f); helper.addColourParam("mfp", Col3f(0.22f, 0.081f, 0.06f)); helper.addFloatSliderParam("mfp_scale", 2.7f, 0.001f, 25.0f); helper.addColourParam("scatter_albedo", Col3f(0.3f, 0.3f, 0.3f)); helper.addFloatSliderParam("sampling_density", 0.65f, 0.0001f, 2.0f); helper.addIntParam("scatter_limit", 6); helper.addBoolParam("use_surf_col_as_trans", false); helper.addFloatSliderParam("transmittance", 1.0f); helper.addFloatSliderParam("transmittance_roughness", 0.8f); helper.addStringPopupParam("entry_exit_type", "refractive", translucentEntryExitTypeOptions, 3); helper.addFloatSliderParam("absorption_ratio", 0.46f); helper.addFloatParam("refractionIndex", 1.42f); }
void ShaderInfoHelper::buildGlassShaderParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("colour", Col3f(0.0f, 0.0f, 0.0f)); helper.addFloatSliderParam("reflection", 1.0f); helper.addFloatSliderParam("roughness", 0.0f); helper.addFloatSliderParam("transparency", 1.0f); helper.addFloatSliderParam("transmittance", 1.0f); helper.addFloatParam("refraction_index", 1.517f); helper.addBoolParam("fresnel", true); helper.addBoolParam("thin_volume", false); helper.addBoolParam("ignore_trans_refraction", false); }
__forceinline Col3f BRDF_sample(const Ref<BackendScene>& scene, Col3f c, DifferentialGeometry dg,const Sample3f wi, float epsilon) { if (wi.pdf <= 0.0f) return zero; Ray r( dg.P, wi.value, dg.error*epsilon, inf ); DifferentialGeometry diff; scene->accel->intersect( r, diff ); scene->postIntersect( r, diff ); Col3f radiance = Col3f( 0.0f,0.0f,0.0f ); float pdflight = 0.0f; if ( diff.light ) { radiance = diff.light->Le(diff, -wi.value ); pdflight = diff.light->pdf( dg, wi ); } float weight = mis(wi.pdf, pdflight); if ( dot( diff.Ng, -r.dir ) > 0 ) return radiance * c * weight / wi.pdf; }
void myApp02::init() { globalAmbient = Col3f(1, .1, .1); shadowsOn(); // wall plane = GroundPlane(Vec3(), Vec3(), Dim2f(8, 7), Col4f(1, 1, 0, 1), 1, 1, "orange.jpg"); //Plane.textureOn(); plane.setBumpMap("white_tile.jpg"); plane.setTextureScale(Vec2f(.5)); //Plane.setAmbientMaterial(Col4f(.02, .02, .02, 1.0)); plane.setSpecularMaterial(Col4f(.1, .1, .1, 1.0)); plane.setShininess(100); //tube = ProtoTube(); float radius = .107; Vec3f v(0, 0, 0); int segments = 10; // 60; v = Vec3f(0, 0, 0); Vec3f spd(0, 0, 0); //cps.push_back(v); float turbulence = .1f; Dim3f size(4.25, 4.25, 4.25); float startY = -.5; int ribCount = 3;// 17; float ribSpan = 4.5; float ribRadius = 0; float ribRadiusMax = 2.0; float ribTheta = 0; float ribGap = ribSpan / ribCount; for (int i = 0; i < ribCount; ++i){ float theta = 0, weaveTheta = 0; std::vector <Vec3> cps; Spline3 spline; ribRadius = fabs(sin(ribTheta) * ribRadiusMax); for (int j = 0; j < segments; ++j){ //spd = Vec3(random(-turbulence*.1, turbulence*.1), 0, random(-turbulence*.1, turbulence*.1)); //v = spd + Vec3f(sin(theta)*2+random(-turbulence, turbulence), startY+=.1, cos(theta)*2+random(-turbulence, turbulence)); //cps.push_back(Vec3(v.x, v.y, v.z)); cps.push_back(Vec3(sin(theta) * ribRadius, -ribSpan / 2 + ribGap*i + sin(weaveTheta) * .15, cos(theta) * ribRadius)); theta += TWO_PI / segments; //weaveTheta += j*j*j*.125 * PI / 180; weaveTheta += TWO_PI / segments * (ribRadius * 4); } //trace("ribradius = ", ribRadius*4); ribTheta += PI / ribCount; //spline = Spline3(cps, 4, false, .5); spline = Spline3(cps, 5, false, .5); TransformFunction t1 = TransformFunction(TransformFunction::SINUSOIDAL, Tup2f(.02, .95 + (ribRadius*random(.07, .31))), 1/*int(random(1, 3))*/); ribs.push_back(ProtoTube(Vec3f(), Vec3f(), Dim3f(1), Col4f(1), spline, .09, 12, t1, true, "pitted.jpg", Vec2f(1, random(.0825, .2)))); ribs.at(i).setIsClosed(0); ribs.at(i).setSpecularMaterial(Col4f(.4, .275, .1, 1)); ribs.at(i).setShininess(6); ribs.at(i).setBumpMap("pitted.jpg"); // rib tendrils std::vector <Vec3> ribCps; for (int j = 0; j < ribs.at(i).getFrenetFrameLength(); j += int(random(1, 3))){ for (int k = 0; k < ribs.at(i).getCrossSectionDetail(); k += int(random(1, 3))){ ribCps.push_back(ribs.at(i).getVertices().at(j*ribs.at(i).getCrossSectionDetail() + k).pos); } } Spline3 ribSpline = Spline3(ribCps, 2, false, .5); TransformFunction ribT = TransformFunction(TransformFunction::SINUSOIDAL, Tup2f(random(.05, .2), random(..3, .5)), int(random(5, 12))); ribBands.push_back(ProtoTube(Vec3f(), Vec3f(), Dim3f(1), Col4f(1), ribSpline, .09, 12, ribT, true, "vascular.jpg", Vec2f(1, random(.0825, 1)))); ribBands.at(i).setIsClosed(0); ribBands.at(i).setSpecularMaterial(Col4f(.8, .275, .1, 1)); ribBands.at(i).setShininess(5); ribBands.at(i).setBumpMap("vascular.jpg"); } //yRot = xRot = 0; //xRotLast = yRotLast = 0; //mouseXIn = mouseYIn = 0; }
static void parseCommandLine(Ref<ParseStream> cin, const FileName& path) { while (true) { std::string tag = cin->getString(); if (tag == "") return; /* parse command line parameters from a file */ if (tag == "-c") { FileName file = path + cin->getFileName(); parseCommandLine(new ParseStream(new LineCommentFilter(file,"#")),file.path()); } /* read model from file */ else if (tag == "-i") *g_scene += load(path+cin->getFileName()); /* triangulated sphere */ else if (tag == "-trisphere") { Ref<Device::RTShape> sphere = g_device->rtNewShape("sphere"); sphere->rtSetFloat3("P",cin->getVec3f()); sphere->rtSetFloat1("r",cin->getFloat()); sphere->rtSetInt1("numTheta",cin->getInt()); sphere->rtSetInt1("numPhi",cin->getInt()); sphere->rtCommit(); Ref<Device::RTMaterial> material = g_device->rtNewMaterial("matte"); material->rtSetFloat3("reflection",Col3f(1.0f,0.0f,0.0f)); material->rtCommit(); *g_scene += new ShapeNode(sphere,material); } /* ambient light source */ else if (tag == "-ambientlight") { Ref<Device::RTLight> light = g_device->rtNewLight("ambientlight"); light->rtSetFloat3("L",cin->getVec3f()); light->rtCommit(); *g_scene += new LightNode(light); } /* point light source */ else if (tag == "-pointlight") { Vec3f P = cin->getVec3f(); Vec3f I = cin->getVec3f(); std::cout << " P " << P.x << " : " << P.y << " : " << P.z << std::endl; std::cout << " I " << I.x << " : " << I.y << " : " << I.z << std::endl; Ref<Device::RTLight> light = g_device->rtNewLight("pointlight"); light->rtSetFloat3("P",P); light->rtSetFloat3("I",I); light->rtCommit(); *g_scene += new LightNode(light); } /* distant light source */ else if (tag == "-distantlight") { Ref<Device::RTLight> light = g_device->rtNewLight("distantlight"); light->rtSetFloat3("D",cin->getVec3f()); light->rtSetFloat3("L",cin->getVec3f()); light->rtSetFloat1("halfAngle",cin->getFloat()); light->rtCommit(); *g_scene += new LightNode(light); } /* triangular light source */ else if (tag == "-trianglelight") { Vec3f P = cin->getVec3f(); Vec3f U = cin->getVec3f(); Vec3f V = cin->getVec3f(); Vec3f L = cin->getVec3f(); Ref<Device::RTLight> light = g_device->rtNewLight("trianglelight"); light->rtSetFloat3("v0",P); light->rtSetFloat3("v1",P+U); light->rtSetFloat3("v2",P+V); light->rtSetFloat3("L" ,L); light->rtCommit(); *g_scene += new LightNode(light); } /* quad light source */ else if (tag == "-quadlight") { Vec3f P = cin->getVec3f(); Vec3f U = cin->getVec3f(); Vec3f V = cin->getVec3f(); Vec3f L = cin->getVec3f(); Ref<Device::RTLight> light0 = g_device->rtNewLight("trianglelight"); light0->rtSetFloat3("v0",P); light0->rtSetFloat3("v1",P+U); light0->rtSetFloat3("v2",P+U+V); light0->rtSetFloat3("L" ,L); light0->rtCommit(); *g_scene += new LightNode(light0); Ref<Device::RTLight> light1 = g_device->rtNewLight("trianglelight"); light1->rtSetFloat3("v0",P+U+V); light1->rtSetFloat3("v1",P+V); light1->rtSetFloat3("v2",P); light1->rtSetFloat3("L" ,L); light1->rtCommit(); *g_scene += new LightNode(light1); } /* HDRI light source */ else if (tag == "-hdrilight") { Ref<Device::RTLight> light = g_device->rtNewLight("hdrilight"); light->rtSetFloat3("L",cin->getVec3f()); light->rtSetImage("image",loadRTImage(path + cin->getFileName())); light->rtCommit(); *g_scene += new LightNode(light); } /* parse camera parameters */ else if (tag == "-vp") g_camPos = Vec3f(cin->getVec3f()); else if (tag == "-vi") g_camLookAt = Vec3f(cin->getVec3f()); else if (tag == "-vd") g_camLookAt = g_camPos+cin->getVec3f(); else if (tag == "-vu") g_camUp = cin->getVec3f(); else if (tag == "-angle") g_camAngle = cin->getFloat(); else if (tag == "-fov") g_camAngle = cin->getFloat(); else if (tag == "-radius") g_camRadius = cin->getFloat(); /* frame buffer size */ else if (tag == "-size") { g_width = cin->getInt(); g_height = cin->getInt(); g_frameBuffer = g_device->rtNewFrameBuffer("RGB_FLOAT32", g_width, g_height); } /* full screen mode */ else if (tag == "-fullscreen") { g_fullscreen = true; } /* refine rendering when not moving */ else if (tag == "-refine") g_refine = true; else if (tag == "-norefine") g_refine = false; /* acceleration structure to use */ else if (tag == "-accel") g_accel = cin->getString(); /* set renderer */ else if (tag == "-renderer") { std::string renderer = cin->getString(); if (renderer == "debug" ) g_renderer = parseDebugRenderer(cin,path); else if (renderer == "pt" ) g_renderer = parsePathTracer(cin,path); else if (renderer == "pathtracer") g_renderer = parsePathTracer(cin,path); else if (renderer == "material" ) g_renderer = parseMaterialRenderer(cin,path); else if (renderer == "opengl" ) g_renderer = parseOpenGLRenderer(cin); else throw std::runtime_error("unknown renderer: "+renderer); } /* set gamma */ else if (tag == "-gamma") { g_renderer->rtSetFloat1("gamma",g_gamma = cin->getFloat()); g_renderer->rtCommit(); } /* set recursion depth */ else if (tag == "-depth") { g_renderer->rtSetInt1("maxDepth",g_depth = cin->getInt()); g_renderer->rtCommit(); } /* set samples per pixel */ else if (tag == "-spp") { g_renderer->rtSetInt1("sampler.spp",g_spp = cin->getInt()); g_renderer->rtCommit(); } /* set the backplate */ else if (tag == "-backplate") { g_renderer->rtSetImage("backplate",g_backplate = loadRTImage(path + cin->getFileName())); g_renderer->rtCommit(); } /* render frame */ else if (tag == "-o") outputMode(path + cin->getFileName()); /* display image */ else if (tag == "-display") displayMode(); /* regression testing */ else if (tag == "-regression") { g_refine = false; g_regression = true; GLUTDisplay(OrthonormalSpace::lookAtPoint(g_camPos,g_camLookAt,g_camUp),0.01f); } else if (tag == "-version") { std::cout << "embree renderer version 1.0" << std::endl; exit(1); } else if (tag == "-h" || tag == "-?" || tag == "-help" || tag == "--help") { std::cout << std::endl; std::cout << "Embree Version 1.0" << std::endl; std::cout << std::endl; std::cout << " usage: embree -i model.obj -renderer debug -display" << std::endl; std::cout << " embree -i model.obj -renderer pathtracer -o out.tga" << std::endl; std::cout << " embree -c model.ecs -display" << std::endl; std::cout << std::endl; std::cout << "-renderer [debug,pathtracer]" << std::endl; std::cout << " Sets the renderer to use." << std::endl; std::cout << std::endl; std::cout << "-c file" << std::endl; std::cout << " Parses command line parameters from file." << std::endl; std::cout << std::endl; std::cout << "-i file" << std::endl; std::cout << " Loads a scene from file." << std::endl; std::cout << std::endl; std::cout << "-o file" << std::endl; std::cout << " Renders and outputs the image to the file." << std::endl; std::cout << std::endl; std::cout << "-display" << std::endl; std::cout << " Interactively displays the rendering into a window." << std::endl; std::cout << std::endl; std::cout << "-vp x y z" << std::endl; std::cout << " Sets camera position to the location (x,y,z)." << std::endl; std::cout << std::endl; std::cout << "-vi x y z" << std::endl; std::cout << " Sets camera lookat point to the location (x,y,z)." << std::endl; std::cout << std::endl; std::cout << "-vd x y z" << std::endl; std::cout << " Sets camera viewing direction to (x,y,z)." << std::endl; std::cout << std::endl; std::cout << "-vu x y z" << std::endl; std::cout << " Sets camera up direction to (x,y,z)." << std::endl; std::cout << std::endl; std::cout << "-fov angle" << std::endl; std::cout << " Sets camera field of view in y direction to angle." << std::endl; std::cout << std::endl; std::cout << "-size width height" << std::endl; std::cout << " Sets the width and height of image to render." << std::endl; std::cout << std::endl; std::cout << "-fullscreen" << std::endl; std::cout << " Enables full screen display mode." << std::endl; std::cout << std::endl; std::cout << "-accel [bvh2,bvh4,bvh4.spatial]" << std::endl; std::cout << " Sets the spatial index structure to use." << std::endl; std::cout << std::endl; std::cout << "-gamma v" << std::endl; std::cout << " Sets gamma correction to v (only pathtracer)." << std::endl; std::cout << std::endl; std::cout << "-depth i" << std::endl; std::cout << " Sets the recursion depth to i (default 16)" << std::endl; std::cout << std::endl; std::cout << "-spp i" << std::endl; std::cout << " Sets the number of samples per pixel to i (default 1) (only pathtracer)." << std::endl; std::cout << std::endl; std::cout << "-backplate" << std::endl; std::cout << " Sets a high resolution back ground image. (default none) (only pathtracer)." << std::endl; std::cout << std::endl; std::cout << "-ambientlight r g b" << std::endl; std::cout << " Creates an ambient light with intensity (r,g,b)." << std::endl; std::cout << std::endl; std::cout << "-pointlight px py pz r g b" << std::endl; std::cout << " Creates a point light with intensity (r,g,b) at position (px,py,pz)." << std::endl; std::cout << std::endl; std::cout << "-distantlight dx dy dz r g b halfAngle" << std::endl; std::cout << " Creates a distant sun light with intensity (r,g,b) shining into " << std::endl; std::cout << " direction (dx,dy,dz) from the cone spanned by halfAngle." << std::endl; std::cout << std::endl; std::cout << "-trianglelight px py pz ux uy uz vx vy vz r g b" << std::endl; std::cout << " Creates a triangle-light with intensity (r,g,b) spanned by the point " << std::endl; std::cout << " (px,py,pz) and the vectors (vx,vy,vz) and (ux,uy,uz)." << std::endl; std::cout << std::endl; std::cout << "-quadlight px py pz ux uy uz vx vy vz r g b" << std::endl; std::cout << " Creates a quad-light with intensity (r,g,b) spanned by the point " << std::endl; std::cout << " (px,py,pz) and the vectors (vx,vy,vz) and (ux,uy,uz)." << std::endl; std::cout << std::endl; std::cout << "-hdrilight r g b file" << std::endl; std::cout << " Creates a high dynamic range environment light from the image " << std::endl; std::cout << " file. The intensities are multiplies by (r,g,b)." << std::endl; std::cout << std::endl; std::cout << "-trisphere px py pz r theta phi" << std::endl; std::cout << " Creates a triangulated sphere with radius r at location (px,py,pz) " << std::endl; std::cout << " and triangulation rates theta and phi." << std::endl; std::cout << std::endl; std::cout << "-[no]refine" << std::endl; std::cout << " Enables (default) or disables the refinement display mode." << std::endl; std::cout << std::endl; std::cout << "-regression" << std::endl; std::cout << " Runs a stress test of the system." << std::endl; std::cout << std::endl; std::cout << "-version" << std::endl; std::cout << " Prints version number." << std::endl; std::cout << std::endl; std::cout << "-h, -?, -help, --help" << std::endl; std::cout << " Prints this help." << std::endl; exit(1); } /* skip unknown command line parameter */ else { std::cerr << "unknown command line parameter: " << tag << " "; while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " "; std::cerr << std::endl; } } }
void ProtoJuncusEffusus05::init() { globalAmbient = Col3f(.25f, .19f, .27f); // slight violet color // light0 light0.setPosition(Vec3f(0, 0, 1)); light0.setDiffuse(Col4f(1, 1, 1, 1.0f)); light0.setAmbient(Col4f(.5, .3, .3, 1.0)); light0.setSpecular(Col4f(1, 1, 1, 1.0)); light0.on(); light1.setPosition(Vec3f(-1, 0, 1)); light1.setDiffuse(Col4f(.2, .5, .65, 1.0f)); light1.setAmbient(Col4f(.3, .3, .3, 1.0)); light1.setSpecular(Col4f(1, 1, 1, 1.0)); light1.on(); juncsCount = 32;// 9;// 36; float ht = 2.25; int segs = 8; float step = ht / segs; float theta = 0; float radius = .107; float x, y, z; float chi = 0; // thanks to gamblin colors for (int i = 0; i < juncsCount; ++i){ theta = TWO_PI / juncsCount * i; y = -ht / 2; std::vector <Vec3> cps; radius = .14; chi = 0; for (int j = 0; j < segs; ++j){ z = (cos(theta + sin(chi)*random(j))*radius + random(-.08, .08)*j) * (random(1, 3.5) / (j + 1)); y += step; x = (sin(theta + sin(chi)*random(j))*radius + random(-.08, .08)*j) * (random(1, 3.5) / (j + 1)); cps.push_back(Vec3(x, y, z)); theta += TWO_PI / segs; radius += .085; chi += PI / 2; } std::string skin; int dice = int(random(12)); if (dice == 0) { skin = "aluminum_foil.jpg"; } else if (dice == 1){ skin = "gold_foil2.jpg"; } else if (dice == 2){ skin = "metal_grate.jpg"; } else if (dice == 3){ skin = "aluminum_foil.jpg"; } else if (dice == 4){ skin = "gold_foil.jpg"; } else if (dice == 5){ skin = "corroded_shipPlate.jpg"; } else if (dice == 6){ skin = "ship_plate2.jpg"; } else if (dice == 7){ skin = "bronze_fans.jpg"; } else if (dice == 8){ skin = "gold_foil2.jpg"; } else if (dice == 9){ skin = "metal_screwHeads.jpg"; } else if (dice == 10){ skin = "brushed_metal.jpg"; } else if (dice == 11){ skin = "metal_grate.jpg"; } else { skin = "brushed_metal.jpg"; } juncs.push_back(ProtoJuncusEffusus(Col4f(.7, .7, .6, 1), skin, skin, cps, ProtoJuncusEffusus::MEDIUM)); } // For exporting geometry to STL std::vector<Tup4v> vs; for (int i = 0; i < juncs.size(); ++i){ bool isTubule = false; if (i % 4 == 0)isTubule = false; else isTubule = true; std::vector<Tup4v> temp = juncs.at(i).getGeomData(isTubule, true); vs.insert(vs.end(), temp.begin(), temp.end()); } // export geometry data to STL //export(vs, STL); // Locations for page placement float arrayW = 9 * .37; float arrayH = 13 * .39; float gapX = arrayW / (COLUMNS - 1); float gapY = arrayH / (ROWS - 1); for (int i = 0; i < ROWS; ++i){ for (int j = 0; j < COLUMNS; ++j){ locs[i*COLUMNS + j] = Vec3(-arrayW / 2 + gapX*(j), arrayH / 2 - gapY*(i), 0); thetas[i*COLUMNS + j] = random(360.0); juncIDCounts[i*COLUMNS + j] = static_cast<int>(random(3, 24)); } } }
Col3f PathTraceIntegrator::Li(const LightPath& lightPathOrig, const Ref<BackendScene>& scene, Sampler* sampler, size_t& numRays) { bool done = false; Col3f coeff = Col3f(1,1,1); Col3f Lsum = zero; Col3f L = zero; LightPath lightPath = lightPathOrig; bool doneDiffuse = false; /*! while cycle instead of the recusrion call * throughput is accumulated and the resulting light addition is * multipliled by this throughput (coef) at each itteration */ while (!done) { BRDFType directLightingBRDFTypes = (BRDFType)(DIFFUSE); BRDFType giBRDFTypes = (BRDFType)(ALL); /*! Terminate path if too long or contribution too low. */ L = zero; /*! Terminate the path if maxDepth is reached */ if (lightPath.depth >= maxDepth) // || reduce_max(coeff) < minContribution) return Lsum; /*! Traverse ray. */ DifferentialGeometry dg; scene->accel->intersect(lightPath.lastRay,dg); scene->postIntersect(lightPath.lastRay,dg); const Vec3f wo = -lightPath.lastRay.dir; numRays++; /*! Environment shading when nothing hit. */ if (!dg) { if (backplate && lightPath.unbend) { Vec2f raster = sampler->getPrimary(); int width = sampler->getImageSize().x; int height = sampler->getImageSize().y; int x = (int)((raster.x / width) * backplate->width); x = clamp(x, 0, int(backplate->width)-1); int y = (int)((raster.y / height) * backplate->height); y = clamp(y, 0, int(backplate->height)-1); L = backplate->get(x, y); } else { if (!lightPath.ignoreVisibleLights) for (size_t i=0; i<scene->envLights.size(); i++) L += scene->envLights[i]->Le(wo); } return Lsum + L*coeff; } /*! Shade surface. */ CompositedBRDF brdfs; if (dg.material) dg.material->shade(lightPath.lastRay, lightPath.lastMedium, dg, brdfs); /*! face forward normals */ bool backfacing = false; #if defined(__EMBREE_CONSISTENT_NORMALS__) && __EMBREE_CONSISTENT_NORMALS__ > 1 return Col3f(abs(dg.Ns.x),abs(dg.Ns.y),abs(dg.Ns.z)); #else if (dot(dg.Ng, lightPath.lastRay.dir) > 0) { backfacing = true; dg.Ng = -dg.Ng; dg.Ns = -dg.Ns; } #endif /*! Sample BRDF - get the sample direction for * both the indirect illumination as well as for the MIS BRDF sampling */ Col3f c; Sample3f wi;BRDFType type; Vec2f s = sampler->getVec2f(firstScatterSampleID + lightPath.depth); float ss = sampler->getFloat(firstScatterTypeSampleID + lightPath.depth); c = brdfs.sample(wo, dg, wi, type, s, ss, giBRDFTypes); /*! Add light emitted by hit area light source. */ if (!lightPath.ignoreVisibleLights && dg.light && !backfacing) L += dg.light->Le(dg,wo); /*! Check if any BRDF component uses direct lighting. */ bool useDirectLighting = false; for (size_t i=0; i<brdfs.size(); i++) useDirectLighting |= (brdfs[i]->type & directLightingBRDFTypes) != NONE; /*! Direct lighting. */ if (useDirectLighting) { std::vector<float> illumFactor; // illumination factor for each ls float sum = 0; LightSample ls; if ( wi.pdf > 0.0f ) { Ray r( dg.P, wi.value, dg.error*epsilon, inf ); DifferentialGeometry diff; scene->accel->intersect( r, diff ); scene->postIntersect( r, diff ); // Col3f red = Col3f( 1.0f, 0.0f, 0.0f); Col3f radiance = Col3f( 0.0f,0.0f,0.0f ); if ( diff.light ) // if BRDF sampling hits the light { radiance = diff.light->Le(diff, -wi.value ); } if ( dot( diff.Ng, -r.dir ) > 0 && type != GLOSSY_REFLECTION) L += radiance * c / wi.pdf; } /*! Run through all the lightsources and sample or compute the distribution function for rnd gen */ for (size_t i=0; i<scene->allLights.size(); i++) { /*! Either use precomputed samples for the light or sample light now. */ if (scene->allLights[i]->precompute()) ls = sampler->getLightSample(precomputedLightSampleID[i]); else ls.L = scene->allLights[i]->sample(dg, ls.wi, ls.tMax, sampler->getVec2f(lightSampleID)); /*! Start using only one random lightsource after first Lambertian reflection * in case of the direct illumination MIS this heuristics is ommited */ if (true)//donedif { /*! run through all the lighsources and compute radiance accumulatively */ float boo = reduce_max(ls.L)/ls.tMax; // incomming illuminance heuristic sum += boo; illumFactor.push_back(boo); // illumination factor } else // if all the lights are sampled - take each sample and compute the addition { /*! Ignore zero radiance or illumination from the back. */ if (ls.L == Col3f(zero) || ls.wi.pdf == 0.0f || dot(dg.Ns,Vec3f(ls.wi)) <= 0.0f) continue; /*! Test for shadows. */ bool inShadow = scene->accel->occluded(Ray(dg.P, ls.wi, dg.error*epsilon, ls.tMax-dg.error*epsilon)); numRays++; if (inShadow) continue; /*! Evaluate BRDF. */ L += ls.L * brdfs.eval(wo, dg, ls.wi, directLightingBRDFTypes) * rcp(ls.wi.pdf); } } /*! After fisrt Lambertian reflection pick one random lightsource and compute contribution * in case of MIS active this heuristic is ommited */ if (true && scene->allLights.size() != 0)//donedif { /*! Generate the random value */ unsigned int RndVal; // random value // if (rand_s(&RndVal)) std::cout << "\nRND gen error!\n"; rand_r(&RndVal); float rnd((float)RndVal/(float)UINT_MAX); // compute the 0-1 rnd value /*! Pick the particular lightsource according the intensity-given distribution */ size_t i = 0; float accum = illumFactor[i]/sum; // accumulative sum while (i < scene->allLights.size() && rnd > accum) // get the lightsource index accirding the Pr { ++i; accum +=illumFactor[i]/sum; } /*! Sample the selected lightsource and compute contribution */ if ( i >= scene->allLights.size() ) i = scene->allLights.size() -1; // if (usedLight != NULL) // std::cout << "direct light " << scene->allLights[i].ptr << "\n"; float ql = illumFactor[i]/sum; // Pr of given lightsource // LightSample ls; if (scene->allLights[i]->precompute()) ls = sampler->getLightSample(precomputedLightSampleID[i]); else ls.L = scene->allLights[i]->sample(dg, ls.wi, ls.tMax, sampler->getVec2f(lightSampleID)); /*! Ignore zero radiance or illumination from the back. */ if (ls.L != Col3f(zero) && ls.wi.pdf != 0.0f && dot(dg.Ns,Vec3f(ls.wi)) > 0.0f) { /*! Test for shadows. */ bool inShadow = scene->accel->occluded(Ray(dg.P, ls.wi, dg.error*epsilon, ls.tMax-dg.error*epsilon)); numRays++; if (!inShadow) { /*! Evaluate BRDF. */ L += ls.L * brdfs.eval(wo, dg, ls.wi, directLightingBRDFTypes) * rcp(ls.wi.pdf*ql) * weight; } } } } /* Add the resulting light */ Lsum += coeff * L; /*! Global illumination. Pick one BRDF component and sample it. */ if (lightPath.depth < maxDepth) //always true { /*! Continue only if we hit something valid. */ if (c != Col3f(zero) && wi.pdf > 0.0f) { /*! detect the first diffuse */ if (wi.pdf < 0.33) doneDiffuse = true; /*! Compute simple volumetric effect. */ const Col3f& transmission = lightPath.lastMedium.transmission; if (transmission != Col3f(one)) c *= pow(transmission,dg.t); /*! Tracking medium if we hit a medium interface. */ Medium nextMedium = lightPath.lastMedium; if (type & TRANSMISSION) nextMedium = dg.material->nextMedium(lightPath.lastMedium); /*! Continue the path. */ float q = 1; if (doneDiffuse) { //std::cout << "\ndifusni\n"; q = min(abs(reduce_max(c) * rcp(wi.pdf)), (float)1); // std::cout << q << "\n"; unsigned int RndVal; // if (rand_s(&RndVal)) std::cout << "\nRND gen error!\n"; rand_r(&RndVal); if ((float)RndVal/(float)UINT_MAX > q) { // std::cout << "konec"; return Lsum;// + L*coeff; } } /*! Continue the path */ lightPath = lightPath.extended(Ray(dg.P, wi, dg.error*epsilon, inf), nextMedium, c, (type & directLightingBRDFTypes) != NONE); coeff = coeff * c * rcp(q * wi.pdf); }else done = true; // end the path } } return Lsum; }
Col3f PathTraceIntegrator::Li(const LightPath& lightPath, const Ref<BackendScene>& scene, const PrecomputedSample& sample, size_t& numRays) { /*! Terminate path if too long or contribution too low. */ if (lightPath.depth >= maxDepth || reduce_max(lightPath.throughput) < minContribution) return zero; /*! Traverse ray. */ DifferentialGeometry dg; scene->intersector->intersect(lightPath.lastRay,dg); scene->postIntersect(lightPath.lastRay,dg); numRays++; Col3f L = zero; const Vec3f wo = -lightPath.lastRay.dir; BRDFType directLightingBRDFTypes = (BRDFType)(DIFFUSE); BRDFType giBRDFTypes = (BRDFType)(ALL); /*! Environment shading when nothing hit. */ if (!dg) { if (backplate && lightPath.unbend) { Vec2f raster = sample.getPrimary(); int width = sample.imageSize.x; int height = sample.imageSize.y; int x = (int)((raster.x * rcp(float(width))) * backplate->width); x = clamp(x, 0, int(backplate->width)-1); int y = (int)((raster.y * rcp(float(height))) * backplate->height); y = clamp(y, 0, int(backplate->height)-1); L = backplate->get(x, y); } else { if (!lightPath.ignoreVisibleLights) for (size_t i=0; i<scene->envLights.size(); i++) L += scene->envLights[i]->Le(wo); } return L; } /*! face forward normals */ bool backfacing = false; if (dot(dg.Ng, lightPath.lastRay.dir) > 0) { backfacing = true; dg.Ng = -dg.Ng; dg.Ns = -dg.Ns; } /*! Shade surface. */ CompositedBRDF brdfs; if (dg.material) dg.material->shade(lightPath.lastRay, lightPath.lastMedium, dg, brdfs); /*! Add light emitted by hit area light source. */ if (!lightPath.ignoreVisibleLights && dg.light && !backfacing) L += dg.light->Le(dg,wo); /*! Global illumination. Pick one BRDF component and sample it. */ if (lightPath.depth < maxDepth) { /*! sample brdf */ Sample3f wi; BRDFType type; Vec2f s = sample.getVec2f(firstScatterSampleID + lightPath.depth); float ss = sample.getFloat(firstScatterTypeSampleID + lightPath.depth); Col3f c = brdfs.sample(wo, dg, wi, type, s, ss, giBRDFTypes); /*! Continue only if we hit something valid. */ if (c != Col3f(zero) && wi.pdf > 0.0f) { /*! Compute simple volumetric effect. */ const Col3f& transmission = lightPath.lastMedium.transmission; if (transmission != Col3f(one)) c *= pow(transmission,dg.t); /*! Tracking medium if we hit a medium interface. */ Medium nextMedium = lightPath.lastMedium; if (type & TRANSMISSION) nextMedium = dg.material->nextMedium(lightPath.lastMedium); /*! Continue the path. */ const LightPath scatteredPath = lightPath.extended(Ray(dg.P, wi, dg.error*epsilon, inf, lightPath.lastRay.time), nextMedium, c, (type & directLightingBRDFTypes) != NONE); L += c * Li(scatteredPath, scene, sample, numRays) * rcp(wi.pdf); } } /*! Check if any BRDF component uses direct lighting. */ bool useDirectLighting = false; for (size_t i=0; i<brdfs.size(); i++) useDirectLighting |= (brdfs[i]->type & directLightingBRDFTypes) != NONE; /*! Direct lighting. Shoot shadow rays to all light sources. */ if (useDirectLighting) { for (size_t i=0; i<scene->allLights.size(); i++) { /*! Either use precomputed samples for the light or sample light now. */ LightSample ls; if (scene->allLights[i]->precompute()) ls = sample.getLightSample(precomputedLightSampleID[i]); else ls.L = scene->allLights[i]->sample(dg, ls.wi, ls.tMax, sample.getVec2f(lightSampleID)); /*! Ignore zero radiance or illumination from the back. */ if (ls.L == Col3f(zero) || ls.wi.pdf == 0.0f || dot(dg.Ns,Vec3f(ls.wi)) <= 0.0f) continue; /*! Test for shadows. */ bool inShadow = scene->intersector->occluded(Ray(dg.P, ls.wi, dg.error*epsilon, ls.tMax-dg.error*epsilon, lightPath.lastRay.time)); numRays++; if (inShadow) continue; /*! Evaluate BRDF. */ L += ls.L * brdfs.eval(wo, dg, ls.wi, directLightingBRDFTypes) * rcp(ls.wi.pdf); } } return L; }
void ShaderInfoHelper::buildConstantTextureParams(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo) { ShaderInfoHelper helper(iri, rendererObjectInfo); helper.addColourParam("colour", Col3f(0.6f, 0.6f, 0.6f)); }