void Scene::BuildCornellBoxScene(std::vector<Shape*> &objects) { camera = new Camera( Point(-260, 0, 90), Point(-199, 0, 90) ); float lightEnergy = 35e8; lights.push_back(new SphereLight(Point(0, 0, 160), 3, Color(lightEnergy,lightEnergy,lightEnergy),1)); Color walls(0.1f,0.1f,0.1f); Material* white = new Material(Ambient(0.3,0.3,0.3),Diffuse(0.9, 0.9, 0.9),walls); AddObject("files\\cornell_box\\cornell_box_floor.3ds", new Material(Color(0.3,0.3,0.3),Color(0.9,0.9,0.9),walls, Reflect(0.2, 0.2, 0.2)), objects); AddObject("files\\cornell_box\\cornell_box_ceil.3ds", white, objects); AddObject("files\\cornell_box\\cornell_box_right_wall.3ds", new Material(Color(0.,0.1,0.),Color(0.4,1,0.4),walls), objects); AddObject("files\\cornell_box\\cornell_box_back.3ds", white, objects); AddObject("files\\cornell_box\\cornell_box_left_wall.3ds", new Material(Color(0.1,0.,0.),Color(1,0.4,0.4),walls), objects); AddObject("files\\cornell_box\\cornell_box_box1.3ds", white, objects); AddObject("files\\cornell_box\\cornell_box_box2.3ds", white, objects); objects.push_back(new Sphere(Point(-35,-45,20),15,new Material(Ambient(0,0,0),Diffuse(0,0,0),Specular(0,0,0), Reflect(0,0,0), Refract(1,1,1), 1.51, 1), Shape::GetUniqueID())); objects.push_back(new Sphere(Point(-50,50,15),15,new Material(Ambient(0,0,0),Diffuse(0,0,0),Specular(0,0,0), Reflect(1,1,1)), Shape::GetUniqueID() )); }
void Sprite::setResAnim(const ResAnim *resanim) { if (resanim) { if (resanim->getTotalFrames()) setAnimFrame(resanim); else { AnimationFrame fr; fr.init(0, Diffuse(), RectF(0,0,0,0), RectF(0,0,0,0), getSize()); setAnimFrame(fr); } } else setAnimFrame(AnimationFrame()); }
bool initBuffer() { bool Validated(true); glGenBuffers(buffer::MAX, BufferName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, ElementSize, ElementData, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::VERTEX]); glBufferData(GL_ARRAY_BUFFER, PositionSize, PositionData, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); GLint UniformBlockSize(0); { glGetActiveUniformBlockiv( ProgramName, glf::semantic::uniform::TRANSFORM0, GL_UNIFORM_BLOCK_DATA_SIZE, &UniformBlockSize); UniformBlockSize = glm::max(UniformBufferOffset, UniformBlockSize) * Instances; glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glBufferData(GL_UNIFORM_BUFFER, UniformBlockSize * Instances, 0, GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } { glm::vec4 Diffuse(1.0f, 0.5f, 0.0f, 1.0f); glGetActiveUniformBlockiv( ProgramName, glf::semantic::uniform::MATERIAL, GL_UNIFORM_BLOCK_DATA_SIZE, &UniformBlockSize); glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::MATERIAL]); glBufferData(GL_UNIFORM_BUFFER, UniformBlockSize, &Diffuse[0], GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } return Validated; }
void Fluid::Evolve(float timeStep) { if (ApplyPulse(_pulse, &_velocities->View())) { _pulse.Reset(); } if (std::abs(timeStep) < 1e-6f) { return; } auto velocitiesTmp = Image2f::Create(_velocities->View(), kLeaveUninitialized); Advect(timeStep, _velocities->View(), _velocities->View(), &velocitiesTmp->View()); Diffuse(timeStep, kMaxDiffusionIterations, velocitiesTmp->View(), &_velocities->View()); Project(kMaxPressureIterations, _velocities->View(), &velocitiesTmp->View()); _velocities = std::move(velocitiesTmp); }
bool initBuffer() { // Generate buffer objects glGenBuffers(buffer::MAX, &BufferName[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, ElementSize, ElementData, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::VERTEX]); glBufferData(GL_ARRAY_BUFFER, PositionSize, PositionData, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); GLint UniformBlockSize = 0; { glGetActiveUniformBlockiv(ProgramName, UniformTransform, GL_UNIFORM_BLOCK_DATA_SIZE, &UniformBlockSize); glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glBufferData(GL_UNIFORM_BUFFER, UniformBlockSize, 0, GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } { glm::vec4 Diffuse(1.0f, 0.5f, 0.0f, 1.0f); glGetActiveUniformBlockiv( ProgramName, UniformMaterial, GL_UNIFORM_BLOCK_DATA_SIZE, &UniformBlockSize); glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::MATERIAL]); glBufferData(GL_UNIFORM_BUFFER, UniformBlockSize, &Diffuse[0], GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } return this->checkError("initBuffer"); }
// Buffer update using glMapBufferRange bool initBuffer() { // Generate a buffer object glGenBuffers(buffer::MAX, &BufferName[0]); // Bind the buffer for use glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::ARRAY]); // Reserve buffer memory but don't copy the values glBufferData( GL_ARRAY_BUFFER, PositionSize, 0, GL_STATIC_DRAW); // Copy the vertex data in the buffer, in this sample for the whole range of data. // It doesn't required to be the buffer size but pointers require no memory overlapping. GLvoid* Data = glMapBufferRange( GL_ARRAY_BUFFER, 0, // Offset PositionSize, // Size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); memcpy(Data, PositionData, PositionSize); // Explicitly send the data to the graphic card. glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, PositionSize); glUnmapBuffer(GL_ARRAY_BUFFER); // Unbind the buffer glBindBuffer(GL_ARRAY_BUFFER, 0); // Copy buffer glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::COPY]); glBufferData(GL_ARRAY_BUFFER, PositionSize, 0, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_COPY_READ_BUFFER, BufferName[buffer::ARRAY]); glBindBuffer(GL_COPY_WRITE_BUFFER, BufferName[buffer::COPY]); glCopyBufferSubData( GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, PositionSize); glBindBuffer(GL_COPY_READ_BUFFER, 0); glBindBuffer(GL_COPY_WRITE_BUFFER, 0); GLint UniformBlockSize = 0; { glGetActiveUniformBlockiv( ProgramName, UniformTransform, GL_UNIFORM_BLOCK_DATA_SIZE, &UniformBlockSize); glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glBufferData(GL_UNIFORM_BUFFER, UniformBlockSize, 0, GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } { glm::vec4 Diffuse(1.0f, 0.5f, 0.0f, 1.0f); glGetActiveUniformBlockiv( ProgramName, UniformMaterial, GL_UNIFORM_BLOCK_DATA_SIZE, &UniformBlockSize); glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::MATERIAL]); glBufferData(GL_UNIFORM_BUFFER, UniformBlockSize, &Diffuse[0], GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } return this->checkError("initBuffer"); }
void ON_Light::Dump( ON_TextLog& dump ) const { ON_BOOL32 bDumpDir = false; ON_BOOL32 bDumpLength = false; ON_BOOL32 bDumpWidth = false; const char* sStyle = "unknown"; switch(Style()) { //case ON::view_directional_light: // sStyle = "view_directional_light"; // bDumpDir = true; // break; //case ON::view_point_light: // sStyle = "view_point_light"; // break; //case ON::view_spot_light: // sStyle = "view_spot_light"; // bDumpDir = true; // break; case ON::camera_directional_light: sStyle = "camera_directional_light"; bDumpDir = true; break; case ON::camera_point_light: sStyle = "camera_point_light"; break; case ON::camera_spot_light: sStyle = "camera_spot_light"; bDumpDir = true; break; case ON::world_directional_light: sStyle = "world_directional_light"; bDumpDir = true; break; case ON::world_point_light: sStyle = "world_point_light"; break; case ON::world_spot_light: sStyle = "world_spot_light"; bDumpDir = true; break; case ON::world_linear_light: sStyle = "linear_light"; bDumpDir = true; bDumpLength = true; break; case ON::world_rectangular_light: sStyle = "rectangular_light"; bDumpDir = true; bDumpLength = true; bDumpWidth = true; break; case ON::ambient_light: sStyle = "ambient_light"; break; case ON::unknown_light_style: sStyle = "unknown"; break; default: sStyle = "unknown"; break; } dump.Print("index = %d style = %s\n",LightIndex(),sStyle); dump.Print("location = "); dump.Print(Location()); dump.Print("\n"); if ( bDumpDir ) dump.Print("direction = "); dump.Print(Direction()); dump.Print("\n"); if ( bDumpLength ) dump.Print("length = "); dump.Print(Length()); dump.Print("\n"); if ( bDumpWidth ) dump.Print("width = "); dump.Print(Width()); dump.Print("\n"); dump.Print("intensity = %g%%\n",Intensity()*100.0); dump.Print("ambient rgb = "); dump.PrintRGB(Ambient()); dump.Print("\n"); dump.Print("diffuse rgb = "); dump.PrintRGB(Diffuse()); dump.Print("\n"); dump.Print("specular rgb = "); dump.PrintRGB(Specular()); dump.Print("\n"); dump.Print("spot angle = %g degrees\n",SpotAngleDegrees()); }
optix::Group CornellSmall::getSceneRootGroup(optix::Context & context) { m_pgram_bounding_box = context->createProgramFromPTXFile( "parallelogram.cu.ptx", "bounds" ); m_pgram_intersection = context->createProgramFromPTXFile( "parallelogram.cu.ptx", "intersect" ); // create geometry instances QVector<optix::GeometryInstance> gis; Diffuse diffuseWhite = Diffuse(optix::make_float3( 0.8f )); Diffuse diffuseGreen = Diffuse(optix::make_float3( 0.05f, 0.8f, 0.05f )); Diffuse diffuseRed = Diffuse(optix::make_float3( 1.f, 0.05f, 0.05f )); // colors as in SmallVCM if ((m_config & CornellSmall::SmallVCMColors) != 0) { diffuseWhite = Diffuse(optix::make_float3( 0.803922f, 0.803922f, 0.803922f )); diffuseGreen = Diffuse(optix::make_float3( 0.156863f, 0.803922f, 0.172549f )); diffuseRed = Diffuse(optix::make_float3( 0.803922f, 0.152941f, 0.152941f )); } Diffuse diffuseBlue = Diffuse(optix::make_float3( 0.156863f, 0.172549f, 0.803922f )); Mirror mirror = Mirror(optix::make_float3(1.f,1.f,1.f)); Glossy glossyWhite = Glossy(optix::make_float3(.1f,.1f,.1f), optix::make_float3(.7f,.7f,.7f), 90.f); Glass glass = Glass(1.6, optix::make_float3(1.f,1.f,1.f), optix::make_float3(1.f,1.f,1.f) ); DiffuseEmitter emitter = DiffuseEmitter(m_sceneLights[0].power, Vector3(1)); // Set up materials // Floor Material *matFloor = &diffuseWhite; if ((m_config & Config::FloorMirror) != 0) { matFloor = &mirror; } else if ((m_config & Config::FloorGlossy) != 0) { matFloor = &glossyWhite; } // Ceiling Material *matCeiling = &diffuseWhite; // Back wall Material *matBackWall = &diffuseWhite; if ((m_config & Config::BackwallBlue) != 0) { matBackWall = &diffuseBlue; } // Right wall Material *matRightWall = &diffuseGreen; if ((m_config & CornellSmall::SmallVCMColors) != 0) matRightWall = &diffuseRed; // Left wall Material *matLeftWall = &diffuseRed; if ((m_config & CornellSmall::SmallVCMColors) != 0) matLeftWall = &diffuseGreen; // Short block Material *matShortBlock = &diffuseWhite; // Tall block Material *matTallBlock = &diffuseWhite; // Set geometry - Cornell box size in SmallVCM 2.56004, here rounded up slightly // Floor gis.push_back( createParallelogram(0, context, optix::make_float3( 0.0f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), optix::make_float3( 2.5f, 0.0f, 0.0f ), *matFloor ) ); // Ceiling if ((m_config & Config::LightPointDistant) == 0) { gis.push_back( createParallelogram(1, context, optix::make_float3( 0.0f, 2.5f, 0.0f ), optix::make_float3( 2.5f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), *matCeiling ) ); } // Back wall gis.push_back( createParallelogram(2, context,optix::make_float3( 0.0f, 0.0f, 2.5f), optix::make_float3( 0.0f, 2.5f, 0.0f), optix::make_float3( 2.5f, 0.0f, 0.0f), *matBackWall)); // Right wall gis.push_back( createParallelogram(3, context, optix::make_float3( 0.0f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 2.5f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), *matRightWall ) ); // Left wall gis.push_back( createParallelogram(4, context, optix::make_float3( 2.5f, 0.0f, 0.0f ), optix::make_float3( 0.0f, 0.0f, 2.5f ), optix::make_float3( 0.0f, 2.5f, 0.0f ), *matLeftWall ) ); if ((m_config & Config::Blocks) != 0) { // Short block gis.push_back( createParallelogram(5, context, optix::make_float3( 130.0f, 165.0f, 65.0f) / 220.f, optix::make_float3( -48.0f, 0.0f, 160.0f) / 220.f, optix::make_float3( 160.0f, 0.0f, 49.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(6, context, optix::make_float3( 290.0f, 0.0f, 114.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( -50.0f, 0.0f, 158.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(7, context, optix::make_float3( 130.0f, 0.0f, 65.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( 160.0f, 0.0f, 49.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(8, context, optix::make_float3( 82.0f, 0.0f, 225.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( 48.0f, 0.0f, -160.0f) / 220.f, *matShortBlock ) ); gis.push_back( createParallelogram(9, context, optix::make_float3( 240.0f, 0.0f, 272.0f) / 220.f, optix::make_float3( 0.0f, 165.0f, 0.0f) / 220.f, optix::make_float3( -158.0f, 0.0f, -47.0f) / 220.f, *matShortBlock)); // Tall block gis.push_back( createParallelogram(10, context, optix::make_float3( 423.0f, 340.0f, 247.0f) / 220.f, optix::make_float3( -158.0f, 0.0f, 49.0f) / 220.f, optix::make_float3( 49.0f, 0.0f, 159.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(11, context, optix::make_float3( 423.0f, 0.0f, 247.0f) / 220.f, optix::make_float3( 0.0f, 340.0f, 0.0f) / 220.f, optix::make_float3( 49.0f, 0.0f, 159.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(12, context, optix::make_float3( 472.0f, 0.0f, 406.0f) / 220.f, optix::make_float3( 0.0f, 340.0f, 0.0f) / 220.f, optix::make_float3( -158.0f, 0.0f, 50.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(13, context, optix::make_float3( 314.0f, 0.0f, 456.0f) / 220.f, optix::make_float3( 0.0f, 340.0f, 0.0f) / 220.f, optix::make_float3( -49.0f, 0.0f, -160.0f) / 220.f, *matTallBlock ) ); gis.push_back( createParallelogram(14, context, optix::make_float3( 265.0f, 0.0f, 296.0f) / 220.f, optix::make_float3( 0.0f, 340.1f, 0.0f) / 220.f, optix::make_float3( 158.0f, 0.0f, -49.0f) / 220.f, *matTallBlock ) ); } // Area light if ( ((m_config & Config::LightArea) != 0) || ((m_config & Config::LightAreaUpwards) != 0) ) { emitter.setInverseArea(m_sceneLights[0].inverseArea); for(int i = 0; i < m_sceneLights.size(); i++) { gis.push_back(createParallelogram(15 + i, context, m_sceneLights[i].position, m_sceneLights[i].v1, m_sceneLights[i].v2, emitter)); } } // Large sphere if ((m_config & Config::LargeMirrorSphere) != 0 || (m_config & Config::LargeGlassSphere) != 0) { Material *matLargeSphere = &mirror; if ((m_config & Config::LargeGlassSphere) != 0) matLargeSphere = &glass; float radius = 0.8; SphereInstance sphere = SphereInstance(*matLargeSphere, Sphere(Vector3(1.25f, radius, 1.25f), radius)); gis.push_back(sphere.getOptixGeometryInstance(context)); } // Small glass sphere right if ((m_config & Config::SmallGlassSphere)) { float radius = 0.5; SphereInstance sphere = SphereInstance(glass, Sphere(Vector3(1.25f - 0.535714269f, radius, 1.25f), radius)); gis.push_back(sphere.getOptixGeometryInstance(context)); } // Small mirror sphere left if ((m_config & Config::SmallMirrorSphere)) { float radius = 0.5; SphereInstance sphere = SphereInstance(mirror, Sphere(Vector3(1.25f + 0.535714269f, radius, 1.25f), radius)); gis.push_back(sphere.getOptixGeometryInstance(context)); } // Create geometry group optix::GeometryGroup geometry_group = context->createGeometryGroup(); geometry_group->setChildCount( static_cast<unsigned int>( gis.size() ) ); for (int i = 0; i < gis.size(); ++i ) geometry_group->setChild( i, gis[i] ); geometry_group->setAcceleration(context->createAcceleration("NoAccel", "NoAccel")); // Bvh Sbvh Trbvh NoAccel // Bvh BvhCompact NoAccel optix::Group gro = context->createGroup(); gro->setChildCount(1); gro->setChild(0, geometry_group); optix::Acceleration acceleration = context->createAcceleration("NoAccel", "NoAccel"); gro->setAcceleration(acceleration); return gro; }