void updateFrustumPoints(frustum_t &f, camera_t *v) { vec3_t up, right, forward; vec3_t nc, fc, tmp1, tmp2; vec3_t gl_up_vec = {0,1,0}; vec3_t center; M_MultVec3(v->viewaxis[AXIS_FORWARD], 1, forward); right[0] = forward[1]; forward[1] = forward[2]; forward[2] = right[0]; M_MultVec3(v->origin, 1, center); right[0] = center[1]; center[1] = center[2]; center[2] = right[0]; //f.bmax[AXIS_Z] = v->farclip; //f.bmin[AXIS_Z] = v->nearclip; M_MultVec3(forward, f.bmax[AXIS_Z], fc); M_AddVec3(fc, center, fc); M_MultVec3(forward, f.bmin[AXIS_Z], nc); M_AddVec3(nc, center, nc); M_CrossProduct(forward, gl_up_vec, right); M_Normalize(right); M_CrossProduct(right, forward, up); M_Normalize(up); float near_height = tan(f.fov/2.0f) * f.bmin[AXIS_Z]; float near_width = near_height*f.ratio; float far_height = tan(f.fov/2.0f) * f.bmax[AXIS_Z]; float far_width = far_height*f.ratio; M_MultVec3(up, near_height, tmp1); M_MultVec3(right, near_width, tmp2); M_SubVec3(nc, tmp1, f.point[0]); M_SubVec3(f.point[0], tmp2, f.point[0]); M_AddVec3(nc, tmp1, f.point[1]); M_SubVec3(f.point[1], tmp2, f.point[1]); M_AddVec3(nc, tmp1, f.point[2]); M_AddVec3(f.point[2], tmp2, f.point[2]); M_SubVec3(nc, tmp1, f.point[3]); M_AddVec3(f.point[3], tmp2, f.point[3]); M_MultVec3(up, far_height, tmp1); M_MultVec3(right, far_width, tmp2); M_SubVec3(fc, tmp1, f.point[4]); M_SubVec3(f.point[4], tmp2, f.point[4]); M_AddVec3(fc, tmp1, f.point[5]); M_SubVec3(f.point[5], tmp2, f.point[5]); M_AddVec3(fc, tmp1, f.point[6]); M_AddVec3(f.point[6], tmp2, f.point[6]); M_SubVec3(fc, tmp1, f.point[7]); M_AddVec3(f.point[7], tmp2, f.point[7]); }
void GlassViewer::setCameraTarget(float x, float y, float z) { target[0] = x-camPos[0]; target[1] = y-camPos[1]; target[2] = z-camPos[2]; M_Normalize(target); }
void GL_RenderScene(camera_t *camera, vec3_t userpos, unsigned int sceneRenderFlags) { if (!world.cl_loaded || !gfx_render.integer) { //GL_2dMode(); return; } static float lasttime=0; camera_t sunCam; Pass basePass; worldLight_t rimLight; float lerp; float ambBoost = (vid_realbright.integer && gfx_GLSLQuality.integer<=1) ? vid_realbrightMult.value : 1.0f; basePass.setViewer(camera); scene_cam = camera; sunLight.origin[0] = -wr_sun_x.value; sunLight.origin[1] = -wr_sun_y.value; sunLight.origin[2] = -wr_sun_z.value; memset(&rimLight, 0, sizeof(worldLight_t)); M_MultVec3(sunLight.origin, -1, rimLight.origin); rimLight.type = LIGHT_DIRECTIONAL; //// SHADOW MAP RENDER //// //shadow pass, render to texture if(gfx_shadow.integer && gfx_shadowQuality.integer >= 1 && gfx_GLSLQuality.integer>1) { vec3_t wmin, wmax, sunLook; World_GetBounds(wmin, wmax); //SET_VEC3(sunLook, (wmax[0]-wmin[0])*.5f, (wmax[1]-wmin[1])*.5f, 0 * .5f); M_MultVec3(camera->viewaxis[AXIS_FORWARD], camera->farclip*0.05, sunLook); M_AddVec2(sunLook, camera->origin, sunLook); Cam_DefaultCamera(&sunCam, gfx_shadowSize.integer, gfx_shadowSize.integer, 2, 8192); if(wr_sun_z.value < 0) { SET_VEC3(sunCam.origin, -wr_sun_x.value, -wr_sun_y.value, -wr_sun_z.value); } else { SET_VEC3(sunCam.origin, wr_sun_x.value, wr_sun_y.value, wr_sun_z.value); } M_Normalize(sunCam.origin); M_MultVec3(sunCam.origin, wmax[0], sunCam.origin); sunCam.origin[0]+=sunLook[0]; sunCam.origin[1]+=sunLook[1]; M_SubVec3(sunLook, sunCam.origin, sunCam.viewaxis[AXIS_FORWARD]); M_GetAxisFromForwardVec(sunCam.viewaxis[AXIS_FORWARD], sunCam.viewaxis); sunCam.fovy = 50; sunCam.time = camera->time; sunCam.fog_far=100000; sunCam.fog_near=99999; sunCam.flags |= CAM_NO_SKY; //CSM setup if(gfx_shadowQuality.integer >= 2) { shadowSplit=0; for(int i=0;i<gfx_shadowQuality.integer;i++) { cascadedPass[i].setViewer(&sunCam); renderer.addPass(&cascadedPass[i]); } } else { shadowPass.setViewer(&sunCam); renderer.addPass(&shadowPass); } } else if( gfx_GLSLQuality.integer > 1 ) { renderer.addPass(&shadowPass); } if(gfx_postProcEnabled.integer && gfx_GLSLQuality.integer>1 && (gfx_depthNormalPass.integer || gfx_postSSAO.integer)) { zPass->setViewer(camera); renderer.addPass(zPass); } basePass.setDepthFunc(GL_LEQUAL); basePass.setDepthMask(true); basePass.clearDepth(true); if(gfx_GLSLQuality.integer>1 && gfx_postProcessing.integer) basePass.setTarget(screenPostTarget); else basePass.setTarget(glScreen); renderer.addPass(&basePass); //// BUILD RENDER LIST //// // sun/moon if(wr_sun_z.value < 0) { lerp = CLAMP(fabs(-1 - cos(wr_sun_phi.value)), 0, 1); //Console_Printf("phi %f lerp %f\n", wr_sun_phi.value, lerp); //setup sun light color and ambient sunLight.ambient[0] = obj_ambient_r.value*ambBoost; sunLight.ambient[1] = obj_ambient_g.value*ambBoost; sunLight.ambient[2] = obj_ambient_b.value*ambBoost; sunLight.color[0] = obj_light0_r.value*.9; sunLight.color[1] = obj_light0_g.value*.9; sunLight.color[2] = obj_light0_b.value*.98; rimLight.ambient[0] = 0; rimLight.ambient[1] = 0; rimLight.ambient[2] = 0; rimLight.color[0] = lerp*obj_light1_r.value*.9; rimLight.color[1] = lerp*obj_light1_g.value*.9; rimLight.color[2] = lerp*obj_light1_b.value*.98; } else { if(wr_sun_phi.value < 5.23f && wr_sun_phi.value > 1.0472f) lerp = CLAMP(fabs(1-cos(3*(M_PI-wr_sun_phi.value))), 0, 1); else lerp = 0; //Console_Printf("phi %f lerp %f cos %f\n", wr_sun_phi.value, lerp, cos(3*(M_PI-wr_sun_phi.value))); //the lights need to flip M_MultVec3(sunLight.origin, -1, sunLight.origin); M_MultVec3(rimLight.origin, -1, rimLight.origin); //setup moon light color and ambient sunLight.ambient[0] = obj_ambient_r.value*ambBoost; sunLight.ambient[1] = obj_ambient_g.value*ambBoost; sunLight.ambient[2] = obj_ambient_b.value*ambBoost; sunLight.color[0] = obj_light1_r.value*.9; sunLight.color[1] = obj_light1_g.value*.9; sunLight.color[2] = obj_light1_b.value*.98; rimLight.ambient[0] = 0; rimLight.ambient[1] = 0; rimLight.ambient[2] = 0; rimLight.color[0] = lerp*obj_light0_r.value*.9; rimLight.color[1] = lerp*obj_light0_g.value*.9; rimLight.color[2] = lerp*obj_light0_b.value*.98; } renderer.addLight(&sunLight, NULL, 0); renderer.addLight(&rimLight, NULL, 0); // The deal here is rather than changing the code in scene.cpp to support the // new renderer, we just "import" all the scene data //// SCENE DATA //// lightCount = 0; //objects scenelist_t *list; for (list = scenelist; list; list = list->next) { //if(list->cull) // continue; switch (list->obj.objtype) { case OBJTYPE_MODEL: GL_AddModelToLists(&list->obj); break; case OBJTYPE_LIGHT: GL_AddLight(0, &list->obj); break; default: break; } } //polys scenefacelist_t *flist; for (flist = scenefacelist; flist; flist = flist->next) { renderer.addPoly(flist, NULL, flist->shader); } //decals for (flist = scenefacelist_decals; flist; flist = flist->next) { renderer.addPoly(flist, NULL, flist->shader); } //lights scenelightlist_t *llist; for (llist = scenelightlist; llist; llist = llist->next) { worldLight_t *l = &worldlights[lightCount++]; M_CopyVec3(llist->light.color, l->color); M_CopyVec3(llist->light.pos, l->origin); renderer.addLight(l, NULL, 0); } //// END SCENE DATA //// //// ENVIRO //// if(!(camera->flags & CAM_NO_WORLD)) { //terrain if (!(scene_cam->flags & CAM_NO_TERRAIN)) renderer.addCustomListItem(&terrainItem, false); //sprites for (std::list<scenelist_t*>::iterator itr = spritelist.begin(); itr != spritelist.end(); itr++) { scenelist_t *sprite = *itr; renderer.addSprite(sprite, &sprite->obj, sprite->obj.shader); } //clouds (at the back) if(gfx_sky.integer) { renderer.addCustomListItem(&cloudsItem, false); } if(gfx_water.integer) { waterItem.set(NULL,NULL,0); renderer.addCustomListItem(&waterItem, false); } //sky if (gfx_sky.integer) { if(Cvar_GetInteger("tl_suntod") <= 1440) sky.setTimeofDay(Cvar_GetValue("tl_suntod")/1440.0f); else sky.setTimeofDay((Cvar_GetValue("tod_sunminute"))/1440.0f); //renderer.addListItem(&clouds, false); renderer.addCustomListItem(&sky, false); } //// FX LAYER //// //polys for (flist = scenefxfacelist; flist; flist = flist->next) { renderer.addPolyFX(flist, NULL, flist->shader); } //decals for (flist = scenefxfacelist_decals; flist; flist = flist->next) { renderer.addPolyFX(flist, NULL, flist->shader); } //sprites for (std::list<scenelist_t*>::iterator itr = spritefxlist.begin(); itr != spritefxlist.end(); itr++) { scenelist_t *sprite = *itr; renderer.addSpriteFX(sprite, &sprite->obj, sprite->obj.shader); } } //// RENDER //// renderer.render(camera->time-lasttime); lasttime = camera->time; }
void Scene_SetFrustum(camera_t *camera, vec4_t rect) { vec3_t eye, viewdir, viewup, viewright; float xfov, yfov; float wr, wl, wt, wb; float tanx, tany; vec3_t spts[4]; vec3_t offset; //vec3_t farpoint, nearpoint; //vec3_t bmin, bmax; //vec3_t raydir, bpoint; //vec3_t inv_viewdir; //vec3_t toward s; vec3_t p1,p2; int n; vec3_t invViewDir; if (gfx_lockfrustum.integer) return; M_CopyVec3(camera->viewaxis[AXIS_RIGHT], viewright); M_CopyVec3(camera->viewaxis[AXIS_FORWARD], viewdir); M_CopyVec3(camera->viewaxis[AXIS_UP], viewup); M_CopyVec3(camera->origin, eye); M_FlipVec3(viewdir, invViewDir); yfov = DEG2RAD(camera->fovy); xfov = DEG2RAD(camera->fovx); tanx=tan(xfov*0.5); tany=tan(yfov*0.5); // wl = wr * ((((selectionRect_x1) / (float)camera->width) - 0.5) * 2); // wb = wt * ((((camera->height - selectionRect_y2) / (float)camera->height) - 0.5) * 2); // wt *= ((((camera->height - selectionRect_y1) / (float)camera->height) - 0.5) * 2); // wr *= (((selectionRect_x2) / (float)camera->width) - 0.5) * 2; wl = tanx * (((rect[0] / (float)camera->width) - 0.5) * 2); wr = tanx * (((rect[2] / (float)camera->width) - 0.5) * 2); wb = tany * (((rect[1] / (float)camera->height) - 0.5) * 2); wt = tany * (((rect[3] / (float)camera->height) - 0.5) * 2); M_AddVec3(camera->origin, viewdir, offset); for (n=0; n<3; n++) { spts[0][n] = viewright[n]*wr + viewup[n]*wt + offset[n]; //top-right point spts[1][n] = viewright[n]*wl + viewup[n]*wt + offset[n]; //top-left point spts[2][n] = viewright[n]*wl + viewup[n]*wb + offset[n]; //bottom-left point spts[3][n] = viewright[n]*wr + viewup[n]*wb + offset[n]; //bottom-right point } M_CalcPlane(spts[1], spts[0], eye, &frustum[0]); //top plane M_CalcPlane(spts[2], spts[1], eye, &frustum[1]); //left plane M_CalcPlane(spts[3], spts[2], eye, &frustum[2]); //bottom plane M_CalcPlane(spts[0], spts[3], eye, &frustum[3]); //right plane //far plane M_PointOnLine(camera->origin, viewdir, camera->farclip, p1); M_CopyVec3(invViewDir, frustum[4].normal); frustum[4].dist = M_DotProduct(invViewDir, p1); //near plane M_PointOnLine(camera->origin, viewdir, camera->nearclip, p1); M_CopyVec3(viewdir, frustum[5].normal); frustum[5].dist = M_DotProduct(viewdir, p1); //compute frustum bounding box (for Scene_ClipBounds) //this is not a very efficient way to do this M_ClearBounds(camera->frustum_bmin, camera->frustum_bmax); M_AddPointToBounds(spts[0], camera->frustum_bmin, camera->frustum_bmax); M_AddPointToBounds(spts[1], camera->frustum_bmin, camera->frustum_bmax); M_AddPointToBounds(spts[2], camera->frustum_bmin, camera->frustum_bmax); M_AddPointToBounds(spts[3], camera->frustum_bmin, camera->frustum_bmax); M_SubVec3(spts[0], camera->origin, p1); M_Normalize(p1); M_PointOnLine(camera->origin, p1, camera->farclip, p2); M_AddPointToBounds(p2, camera->frustum_bmin, camera->frustum_bmax); M_SubVec3(spts[1], camera->origin, p1); M_Normalize(p1); M_PointOnLine(camera->origin, p1, camera->farclip, p2); M_AddPointToBounds(p2, camera->frustum_bmin, camera->frustum_bmax); M_SubVec3(spts[2], camera->origin, p1); M_Normalize(p1); M_PointOnLine(camera->origin, p1, camera->farclip, p2); M_AddPointToBounds(p2, camera->frustum_bmin, camera->frustum_bmax); M_SubVec3(spts[3], camera->origin, p1); M_Normalize(p1); M_PointOnLine(camera->origin, p1, camera->farclip, p2); M_AddPointToBounds(p2, camera->frustum_bmin, camera->frustum_bmax); /* M_ClearBounds(bmin, bmax); Cam_ConstructRay(camera, 0, 0, raydir); M_MultVec3(raydir, gfx_farclip.value, raydir); M_AddVec3(eye, raydir, bpoint); M_AddPointToBounds(bpoint, bmin, bmax); Cam_ConstructRay(camera, camera->width, 0, raydir); M_MultVec3(raydir, gfx_farclip.value, raydir); M_AddVec3(eye, raydir, bpoint); M_AddPointToBounds(bpoint, bmin, bmax); Cam_ConstructRay(camera, 0, camera->height, raydir); M_MultVec3(raydir, gfx_farclip.value, raydir); M_AddVec3(eye, raydir, bpoint); M_AddPointToBounds(bpoint, bmin, bmax); Cam_ConstructRay(camera, camera->width, camera->height, raydir); M_MultVec3(raydir, gfx_farclip.value, raydir); M_AddVec3(eye, raydir, bpoint); M_AddPointToBounds(bpoint, bmin, bmax); M_AddPointToBounds(nearpoint, bmin, bmax); M_CopyVec3(bmin, frustum_bmin); M_CopyVec3(bmax, frustum_bmax); */ }
/* * A light decoration is created in the specified coordinates. * Does largely the same thing as DL_AddLuminous(). */ void Rend_AddLightDecoration(float pos[3], ded_decorlight_t * def, float brightness, boolean isWall, DGLuint decorMap) { decorsource_t *source; lumobj_t *lum; float distance = Rend_PointDist3D(pos); float fadeMul = 1, flareMul = 1; float maxDist = (isWall ? decorWallMaxDist : decorPlaneMaxDist); int i; // Is the point in range? if(distance > maxDist) return; // Close enough to the maximum distance, the lights fade out. if(distance > .67f * maxDist) { fadeMul = (maxDist - distance) / (.33f * maxDist); } // Apply the brightness factor (was calculated using sector lightlevel). fadeMul *= brightness * (isWall ? decorWallFactor : decorPlaneFactor); // Brightness drops as the angle gets too big. if(def->elevation < 2 && decorFadeAngle > 0) // Close the surface? { float vector[3] = { pos[VX] - vx, pos[VZ] - vy, pos[VY] - vz }; float dot; M_Normalize(vector); dot = -(surfaceNormal[VX] * vector[VX] + surfaceNormal[VY] * vector[VY] + surfaceNormal[VZ] * vector[VZ]); if(dot < decorFadeAngle / 2) { flareMul = 0; } else if(dot < 3 * decorFadeAngle) { flareMul *= (dot - decorFadeAngle / 2) / (2.5f * decorFadeAngle); } } if(fadeMul <= 0) return; if(!(source = Rend_NewLightDecorationSource())) return; // Out of sources! // Initialize the essentials in the dummy mobj. source->thing.x = pos[VX] * FRACUNIT; source->thing.y = pos[VY] * FRACUNIT; source->thing.z = pos[VZ] * FRACUNIT; source->thing.frame = FF_FULLBRIGHT; source->thing.halofactor = 0xff; // Assumed visible. source->thing.subsector = R_PointInSubsector(source->thing.x, source->thing.y); // Fill in the data for a new luminous object. source->thing.light = DL_NewLuminous(); lum = DL_GetLuminous(source->thing.light); lum->thing = &source->thing; lum->center = 0; lum->flags = LUMF_CLIPPED; lum->tex = def->sides.tex; lum->ceilTex = def->up.tex; lum->floorTex = def->down.tex; // These are the same rules as in DL_ThingRadius(). lum->radius = def->radius * 40 * dlRadFactor; // Don't make a too small or too large light. if(lum->radius > dlMaxRad) lum->radius = dlMaxRad; if(def->halo_radius > 0) { lum->flareSize = def->halo_radius * 60 * (50 + haloSize) / 100.0f; if(lum->flareSize < 1) lum->flareSize = 1; } else { lum->flareSize = 0; } // This light source is associated with a decoration map, if one is // available. lum->decorMap = decorMap; // Zero = Texture chosen automatically. lum->flareTex = def->flare_texture; lum->flareMul = flareMul; for(i = 0; i < 3; i++) lum->rgb[i] = (byte) (255 * def->color[i] * fadeMul); // Approximate the distance. lum->distance = P_ApproxDistance3(source->thing.x - viewx, source->thing.y - viewy, source->thing.z - viewz); }