Example #1
0
std::shared_ptr<Material> MakeMaterial(const std::string &name,
                                       const TextureParams &mp) {
    Material *material = nullptr;
    if (name == "" || name == "none")
        return nullptr;
    else if (name == "matte")
        material = CreateMatteMaterial(mp);
    else if (name == "plastic")
        material = CreatePlasticMaterial(mp);
    else if (name == "translucent")
        material = CreateTranslucentMaterial(mp);
    else if (name == "glass")
        material = CreateGlassMaterial(mp);
    else if (name == "hair")
        material = CreateHairMaterial(mp);
    else if (name == "mirror")
        material = CreateMirrorMaterial(mp);
    else if (name == "mix") {
        std::string m1 = mp.FindString("namedmaterial1", "");
        std::string m2 = mp.FindString("namedmaterial2", "");
        std::shared_ptr<Material> mat1 = graphicsState.namedMaterials[m1];
        std::shared_ptr<Material> mat2 = graphicsState.namedMaterials[m2];
        if (!mat1) {
            Error("Named material \"%s\" undefined.  Using \"matte\"",
                  m1.c_str());
            mat1 = MakeMaterial("matte", mp);
        }
        if (!mat2) {
            Error("Named material \"%s\" undefined.  Using \"matte\"",
                  m2.c_str());
            mat2 = MakeMaterial("matte", mp);
        }

        material = CreateMixMaterial(mp, mat1, mat2);
    } else if (name == "metal")
        material = CreateMetalMaterial(mp);
    else if (name == "substrate")
        material = CreateSubstrateMaterial(mp);
    else if (name == "uber")
        material = CreateUberMaterial(mp);
    else if (name == "subsurface")
        material = CreateSubsurfaceMaterial(mp);
    else if (name == "kdsubsurface")
        material = CreateKdSubsurfaceMaterial(mp);
    else if (name == "fourier")
        material = CreateFourierMaterial(mp);
    else
        Warning("Material \"%s\" unknown.", name.c_str());

    if ((name == "subsurface" || name == "kdsubsurface") &&
        (renderOptions->IntegratorName != "path" &&
         (renderOptions->IntegratorName != "volpath")))
        Warning(
            "Subsurface scattering material \"%s\" used, but \"%s\" "
            "integrator doesn't support subsurface scattering. "
            "Use \"path\" or \"volpath\".",
            name.c_str(), renderOptions->IntegratorName.c_str());

    mp.ReportUnused();
    if (!material) Error("Unable to create material \"%s\"", name.c_str());
    return std::shared_ptr<Material>(material);
}
Example #2
0
void draw_s2fishdome(CAMERA cam) {
  
  // draw a fisheye / warped projection of the geometry
  double r, near, far;
  XYZ vp, vd, vr, vl;
  XYZ vright, vleft, vup;

  // Calculate various view vectors 
  vp = cam.vp;
  vd = cam.vd;
  vr = CrossProduct(vd,cam.vu);
  vl = CrossProduct(cam.vu,vd);
  vd = ArbitraryRotate(vd,cam.fishrotate,vr);
  vup = CrossProduct(vr,vd);
  vright = VectorAdd(vr,vd);
  vleft = VectorAdd(vl,vd);
  near = VectorLength(_s2priv_pmin(),_s2priv_pmax()) / 100;
  far  = MAX(cam.focallength,VectorLength(_s2priv_pmin(),
					     _s2priv_pmax())) * 20;
  
  // Left
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x+vleft.x,vp.y+vleft.y,vp.z+vleft.z,vup.x,vup.y,vup.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[2]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
    
  // Right
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x+vright.x,vp.y+vright.y,vp.z+vright.z,vup.x,vup.y,vup.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[3]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
  
  // Top 
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x+vup.x,vp.y+vup.y,vp.z+vup.z,-vright.x,-vright.y,-vright.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[0]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
  
  // Bottom 
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x-vup.x,vp.y-vup.y,vp.z-vup.z,-vleft.x,-vleft.y,-vleft.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[1]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
  
  // Remember the graphics state and return it at the end
  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glDisable(GL_LIGHTING);
  glDisable(GL_ALPHA_TEST);
  glDisable(GL_COLOR_MATERIAL);
  glDisable(GL_DITHER);
  //glDisable(GL_FOG);
  glDisable(GL_LINE_SMOOTH);
  glDisable(GL_LINE_STIPPLE);
  glDisable(GL_SCISSOR_TEST);
  glDisable(GL_STENCIL_TEST);
  
  // Setup projections for the dome
  glDrawBuffer(GL_BACK);
  if (_s2fd_options->dometype == WARPMAP)
    glClearColor(0.0,0.0,0.0,0.0);
  else
    glClearColor(0.05,0.05,0.05,0.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glViewport(0,0,_s2fd_options->screenwidth,_s2fd_options->screenheight);
  r = _s2fd_options->screenwidth / (double)_s2fd_options->screenheight;
  switch (_s2fd_options->dometype) {
  case TRUNCTOP:
  case TRUNCBOTTOM:
    glOrtho(-r*0.75,r*0.75,-0.75,0.75,0.1,10.0);
    break;
  case HSPHERICAL:
    glOrtho(-r*0.75,r*0.75,-0.75,0.75,0.1,10.0);
    break;
  case VSPHERICAL:
  case WARPMAP:
  default:
    glOrtho(-r,r,-1.0,1.0,0.1,10.0);
    break;
  }
    
  // Create camera projection for dome
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  switch (_s2fd_options->dometype) {
  case TRUNCBOTTOM:
    s2LookAt(0.0,-1.0,0.25,0.0,0.0,0.25,0.0,0.0,1.0);
    break;
  case TRUNCTOP:
    s2LookAt(0.0,-1.0,-0.25,0.0,0.0,-0.25,0.0,0.0,1.0);
    break;
  case HSPHERICAL:
  case VSPHERICAL:
  case WARPMAP:
  default:
    s2LookAt(0.0,-1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0);
    break;
  }
    
  // Finally draw the dome geometry
  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  glColor3f(1.0,1.0,1.0);
  DrawDome(TRUE,FALSE);

  _s2_fadeinout();
  
  DrawExtras();
  glPopAttrib();
  
}