/* ============= RB_PostProcess ============= */ const void *RB_PostProcess(const void *data) { const postProcessCommand_t *cmd = data; FBO_t *srcFbo; ivec4_t srcBox, dstBox; qboolean autoExposure; // finish any 2D drawing if needed if(tess.numIndexes) RB_EndSurface(); if (!glRefConfig.framebufferObject || !r_postProcess->integer) { // do nothing return (const void *)(cmd + 1); } if (cmd) { backEnd.refdef = cmd->refdef; backEnd.viewParms = cmd->viewParms; } srcFbo = tr.renderFbo; if (tr.msaaResolveFbo) { // Resolve the MSAA before anything else // Can't resolve just part of the MSAA FBO, so multiple views will suffer a performance hit here FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); srcFbo = tr.msaaResolveFbo; } dstBox[0] = backEnd.viewParms.viewportX; dstBox[1] = backEnd.viewParms.viewportY; dstBox[2] = backEnd.viewParms.viewportWidth; dstBox[3] = backEnd.viewParms.viewportHeight; if (r_ssao->integer) { srcBox[0] = backEnd.viewParms.viewportX * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[1] = backEnd.viewParms.viewportY * tr.screenSsaoImage->height / (float)glConfig.vidHeight; srcBox[2] = backEnd.viewParms.viewportWidth * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[3] = backEnd.viewParms.viewportHeight * tr.screenSsaoImage->height / (float)glConfig.vidHeight; //FBO_BlitFromTexture(tr.screenSsaoImage, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); srcBox[1] = tr.screenSsaoImage->height - srcBox[1]; srcBox[3] = -srcBox[3]; FBO_Blit(tr.screenSsaoFbo, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); } srcBox[0] = backEnd.viewParms.viewportX; srcBox[1] = backEnd.viewParms.viewportY; srcBox[2] = backEnd.viewParms.viewportWidth; srcBox[3] = backEnd.viewParms.viewportHeight; if (srcFbo) { if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer) && qglActiveTextureARB) { autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer; RB_ToneMap(srcFbo, srcBox, NULL, dstBox, autoExposure); } else if (r_cameraExposure->value == 0.0f) { FBO_FastBlit(srcFbo, srcBox, NULL, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { vec4_t color; color[0] = color[1] = color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value); color[3] = 1.0f; FBO_Blit(srcFbo, srcBox, NULL, NULL, dstBox, NULL, color, 0); } } if (r_drawSunRays->integer) RB_SunRays(NULL, srcBox, NULL, dstBox); if (1) RB_BokehBlur(NULL, srcBox, NULL, dstBox, backEnd.refdef.blurFactor); else RB_GaussianBlur(backEnd.refdef.blurFactor); if (0 && r_sunlightMode->integer) { ivec4_t dstBox; VectorSet4(dstBox, 0, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 128, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 256, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 384, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } #if 0 if (r_cubeMapping->integer && tr.numCubemaps) { ivec4_t dstBox; int cubemapIndex = R_CubemapForPoint( backEnd.viewParms.or.origin ); if (cubemapIndex) { VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256); //FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1], NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); } } #endif backEnd.framePostProcessed = qtrue; return (const void *)(cmd + 1); }
/* ================= R_AddIQMSurfaces Add all surfaces of this model ================= */ void R_AddIQMSurfaces( trRefEntity_t *ent ) { iqmData_t *data; iqmData_t *skeleton; iqmData_t *oldSkeleton; srfIQModel_t *surface; int i, j; qboolean personalModel; int cull; int fogNum; int cubemapIndex; shader_t *shader; skin_t *skin; skinSurface_t *skinSurf; data = tr.currentModel->modelData; surface = data->surfaces; if ( !data->num_surfaces || !data->num_triangles || !data->num_vertexes ) { ri.Printf( PRINT_WARNING, "WARNING: Tried to render IQM '%s' with no surfaces\n", tr.currentModel->name ); return; } skeleton = R_GetIQMModelDataByHandle( ent->e.frameModel, data ); oldSkeleton = R_GetIQMModelDataByHandle( ent->e.oldframeModel, data ); // don't add mirror only objects if not in a mirror/portal personalModel = (ent->e.renderfx & RF_ONLY_MIRROR) && !tr.viewParms.isPortal; if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= skeleton->num_frames; ent->e.oldframe %= oldSkeleton->num_frames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ( (ent->e.frame >= skeleton->num_frames) || (ent->e.frame < 0) || (ent->e.oldframe >= oldSkeleton->num_frames) || (ent->e.oldframe < 0) ) { ri.Printf( PRINT_DEVELOPER, "R_AddIQMSurfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullIQM ( skeleton, oldSkeleton, ent ); if ( cull == CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // // see if we are in a fog volume // fogNum = R_ComputeIQMFogNum( skeleton, ent ); cubemapIndex = R_CubemapForPoint(ent->e.origin); for ( i = 0 ; i < data->num_surfaces ; i++ ) { if(ent->e.customShader) shader = R_GetShaderByHandle( ent->e.customShader ); else if(ent->e.customSkin > 0 && ent->e.customSkin <= tr.refdef.numSkins) { skin = &tr.refdef.skins[ent->e.customSkin - 1]; shader = tr.defaultShader; for(j = 0 ; j < skin->numSurfaces ; j++) { skinSurf = &tr.skinSurfaces[ skin->surfaces[ j ] ]; if (!strcmp(skinSurf->name, surface->name)) { shader = skinSurf->shader; break; } } if (shader == tr.nodrawShader) { surface++; continue; } } else { shader = surface->shader; } // we will add shadows even if the main object isn't visible in the view // stencil shadows can't do personal models unless I polyhedron clip if ( !personalModel && r_shadows->integer == 2 && fogNum == 0 && !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, 0, 0, 0 ); } // projection shadows work fine with personal models if ( r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, 0, 0, 0 ); } if( !personalModel ) { R_AddEntDrawSurf( ent, (void *)surface, shader, fogNum, 0, 0, cubemapIndex ); } surface++; } }
void R_MDRAddAnimSurfaces( trRefEntity_t *ent ) { mdrHeader_t *header; mdrSurface_t *surface; mdrLOD_t *lod; shader_t *shader; skin_t *skin; int i, j; int lodnum = 0; int fogNum = 0; int cull; int cubemapIndex; bool personalModel; header = (mdrHeader_t *) tr.currentModel->modelData; personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))); if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= header->numFrames; ent->e.oldframe %= header->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ((ent->e.frame >= header->numFrames) || (ent->e.frame < 0) || (ent->e.oldframe >= header->numFrames) || (ent->e.oldframe < 0) ) { ri.Printf( PRINT_DEVELOPER, "R_MDRAddAnimSurfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_MDRCullModel (header, ent); if ( cull == CULL_OUT ) { return; } // figure out the current LOD of the model we're rendering, and set the lod pointer respectively. lodnum = R_ComputeLOD(ent); // check whether this model has as that many LODs at all. If not, try the closest thing we got. if(header->numLODs <= 0) return; if(header->numLODs <= lodnum) lodnum = header->numLODs - 1; lod = (mdrLOD_t *)( (byte *)header + header->ofsLODs); for(i = 0; i < lodnum; i++) { lod = (mdrLOD_t *) ((byte *) lod + lod->ofsEnd); } // set up lighting if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // fogNum? fogNum = R_MDRComputeFogNum( header, ent ); cubemapIndex = R_CubemapForPoint(ent->e.origin); surface = (mdrSurface_t *)( (byte *)lod + lod->ofsSurfaces ); for ( i = 0 ; i < lod->numSurfaces ; i++ ) { if(ent->e.customShader) shader = R_GetShaderByHandle(ent->e.customShader); else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin = R_GetSkinByHandle(ent->e.customSkin); shader = tr.defaultShader; for(j = 0; j < skin->numSurfaces; j++) { if (!strcmp(skin->surfaces[j].name, surface->name)) { shader = skin->surfaces[j].shader; break; } } } else if(surface->shaderIndex > 0) shader = R_GetShaderByHandle( surface->shaderIndex ); else shader = tr.defaultShader; // we will add shadows even if the main object isn't visible in the view // stencil shadows can't do personal models unless I polyhedron clip if ( !personalModel && r_shadows->integer == 2 && fogNum == 0 && !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (surfaceType_t*)surface, tr.shadowShader, 0, false, false, 0 ); } // projection shadows work fine with personal models if ( r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (surfaceType_t*)surface, tr.projectionShadowShader, 0, false, false, 0 ); } if (!personalModel) R_AddDrawSurf( (surfaceType_t*)surface, shader, fogNum, false, false, cubemapIndex ); surface = (mdrSurface_t *)( (byte *)surface + surface->ofsEnd ); } }
/* ============= RB_PostProcess ============= */ const void *RB_PostProcess(const void *data) { const postProcessCommand_t *cmd = data; FBO_t *srcFbo; ivec4_t srcBox, dstBox; qboolean autoExposure; // finish any 2D drawing if needed if(tess.numIndexes) RB_EndSurface(); if (!glRefConfig.framebufferObject || !r_postProcess->integer) { // do nothing return (const void *)(cmd + 1); } if (cmd) { backEnd.refdef = cmd->refdef; backEnd.viewParms = cmd->viewParms; } srcFbo = tr.renderFbo; if (tr.msaaResolveFbo) { // Resolve the MSAA before anything else // Can't resolve just part of the MSAA FBO, so multiple views will suffer a performance hit here FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); srcFbo = tr.msaaResolveFbo; } dstBox[0] = backEnd.viewParms.viewportX; dstBox[1] = backEnd.viewParms.viewportY; dstBox[2] = backEnd.viewParms.viewportWidth; dstBox[3] = backEnd.viewParms.viewportHeight; if (r_ssao->integer) { srcBox[0] = backEnd.viewParms.viewportX * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[1] = backEnd.viewParms.viewportY * tr.screenSsaoImage->height / (float)glConfig.vidHeight; srcBox[2] = backEnd.viewParms.viewportWidth * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[3] = backEnd.viewParms.viewportHeight * tr.screenSsaoImage->height / (float)glConfig.vidHeight; FBO_Blit(tr.screenSsaoFbo, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); } srcBox[0] = backEnd.viewParms.viewportX; srcBox[1] = backEnd.viewParms.viewportY; srcBox[2] = backEnd.viewParms.viewportWidth; srcBox[3] = backEnd.viewParms.viewportHeight; if (srcFbo) { if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer)) { autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer; RB_ToneMap(srcFbo, srcBox, NULL, dstBox, autoExposure); } else if (r_cameraExposure->value == 0.0f) { FBO_FastBlit(srcFbo, srcBox, NULL, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { vec4_t color; color[0] = color[1] = color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value); color[3] = 1.0f; FBO_Blit(srcFbo, srcBox, NULL, NULL, dstBox, NULL, color, 0); } } if (r_drawSunRays->integer) RB_SunRays(NULL, srcBox, NULL, dstBox); if (1) RB_BokehBlur(NULL, srcBox, NULL, dstBox, backEnd.refdef.blurFactor); else RB_GaussianBlur(backEnd.refdef.blurFactor); #if 0 if (0) { vec4_t quadVerts[4]; vec2_t texCoords[4]; ivec4_t iQtrBox; vec4_t box; vec4_t viewInfo; static float scale = 5.0f; scale -= 0.005f; if (scale < 0.01f) scale = 5.0f; FBO_FastBlit(NULL, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); iQtrBox[0] = backEnd.viewParms.viewportX * tr.quarterImage[0]->width / (float)glConfig.vidWidth; iQtrBox[1] = backEnd.viewParms.viewportY * tr.quarterImage[0]->height / (float)glConfig.vidHeight; iQtrBox[2] = backEnd.viewParms.viewportWidth * tr.quarterImage[0]->width / (float)glConfig.vidWidth; iQtrBox[3] = backEnd.viewParms.viewportHeight * tr.quarterImage[0]->height / (float)glConfig.vidHeight; qglViewport(iQtrBox[0], iQtrBox[1], iQtrBox[2], iQtrBox[3]); qglScissor(iQtrBox[0], iQtrBox[1], iQtrBox[2], iQtrBox[3]); VectorSet4(box, 0.0f, 0.0f, 1.0f, 1.0f); texCoords[0][0] = box[0]; texCoords[0][1] = box[3]; texCoords[1][0] = box[2]; texCoords[1][1] = box[3]; texCoords[2][0] = box[2]; texCoords[2][1] = box[1]; texCoords[3][0] = box[0]; texCoords[3][1] = box[1]; VectorSet4(box, -1.0f, -1.0f, 1.0f, 1.0f); VectorSet4(quadVerts[0], box[0], box[3], 0, 1); VectorSet4(quadVerts[1], box[2], box[3], 0, 1); VectorSet4(quadVerts[2], box[2], box[1], 0, 1); VectorSet4(quadVerts[3], box[0], box[1], 0, 1); GL_State(GLS_DEPTHTEST_DISABLE); VectorSet4(viewInfo, backEnd.viewParms.zFar / r_znear->value, backEnd.viewParms.zFar, 0.0, 0.0); viewInfo[2] = scale / (float)(tr.quarterImage[0]->width); viewInfo[3] = scale / (float)(tr.quarterImage[0]->height); FBO_Bind(tr.quarterFbo[1]); GLSL_BindProgram(&tr.depthBlurShader[2]); GL_BindToTMU(tr.quarterImage[0], TB_COLORMAP); GLSL_SetUniformVec4(&tr.depthBlurShader[2], UNIFORM_VIEWINFO, viewInfo); RB_InstantQuad2(quadVerts, texCoords); FBO_Bind(tr.quarterFbo[0]); GLSL_BindProgram(&tr.depthBlurShader[3]); GL_BindToTMU(tr.quarterImage[1], TB_COLORMAP); GLSL_SetUniformVec4(&tr.depthBlurShader[3], UNIFORM_VIEWINFO, viewInfo); RB_InstantQuad2(quadVerts, texCoords); SetViewportAndScissor(); FBO_FastBlit(tr.quarterFbo[1], NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); FBO_Bind(NULL); } #endif if (0 && r_sunlightMode->integer) { ivec4_t dstBox; VectorSet4(dstBox, 0, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 128, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 256, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 384, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } #if 0 if (r_cubeMapping->integer && tr.numCubemaps) { ivec4_t dstBox; int cubemapIndex = R_CubemapForPoint( backEnd.viewParms.or.origin ); if (cubemapIndex) { VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256); //FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1].image, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); } } #endif backEnd.framePostProcessed = qtrue; return (const void *)(cmd + 1); }
/* ================= R_AddMD3Surfaces ================= */ void R_AddMD3Surfaces(trRefEntity_t *ent) { int i; mdvModel_t *model = NULL; mdvSurface_t *surface = NULL; shader_t *shader = NULL; int cull; int lod; int fogNum; int cubemapIndex; qboolean personalModel; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))); if (ent->e.renderfx & RF_WRAP_FRAMES) { ent->e.frame %= tr.currentModel->mdv[0]->numFrames; ent->e.oldframe %= tr.currentModel->mdv[0]->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ((ent->e.frame >= tr.currentModel->mdv[0]->numFrames) || (ent->e.frame < 0) || (ent->e.oldframe >= tr.currentModel->mdv[0]->numFrames) || (ent->e.oldframe < 0)) { ri.Printf(PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name); ent->e.frame = 0; ent->e.oldframe = 0; } // // compute LOD // lod = R_ComputeLOD(ent); model = tr.currentModel->mdv[lod]; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullModel (model, ent); if (cull == CULL_OUT) { return; } // // set up lighting now that we know we aren't culled // if (!personalModel || r_shadows->integer > 1) { R_SetupEntityLighting(&tr.refdef, ent); } // // see if we are in a fog volume // fogNum = R_ComputeFogNum(model, ent); cubemapIndex = R_CubemapForPoint(ent->e.origin); // // draw all surfaces // surface = model->surfaces; for (i = 0 ; i < model->numSurfaces ; i++) { if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t *skin; int j; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; //----(SA) added blink if (ent->e.renderfx & RF_BLINK) { const char *s = va("%s_b", surface->name); // append '_b' for 'blink' for (j = 0 ; j < skin->numSurfaces ; j++) { if (!strcmp(skin->surfaces[j]->name, s)) { shader = skin->surfaces[j]->shader; break; } } } if (shader == tr.defaultShader) { // blink reference in skin was not found for (j = 0 ; j < skin->numSurfaces ; j++) { // the names have both been lowercased if (!strcmp(skin->surfaces[j]->name, surface->name)) { shader = skin->surfaces[j]->shader; break; } } } //----(SA) end if (shader == tr.defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name); } else if (shader->defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } //} else if (surface->numShaders <= 0) { //shader = tr.defaultShader; } else { //md3Shader = (md3Shader_t *) ((byte *)surface + surface->ofsShaders); //md3Shader += ent->e.skinNum % surface->numShaders; //shader = tr.shaders[ md3Shader->shaderIndex ]; shader = tr.shaders[ surface->shaderIndexes[ ent->e.skinNum % surface->numShaderIndexes ] ]; } // for testing polygon shadows (on /all/ models) if (r_shadows->integer == 4) { R_AddDrawSurf((void *)surface, tr.projectionShadowShader, 0, qfalse, qfalse, 0); } // don't add third_person objects if not viewing through a portal if(!personalModel) { srfVaoMdvMesh_t *vaoSurface = &model->vaoSurfaces[i]; R_AddDrawSurf((void *)vaoSurface, shader, fogNum, qfalse, qfalse, cubemapIndex); } surface++; } }
/* ================= R_AddMD3Surfaces ================= */ void R_AddMD3Surfaces( trRefEntity_t *ent ) { int i; mdvModel_t *model = NULL; mdvSurface_t *surface = NULL; shader_t *shader = NULL; int cull; int lod; int fogNum; int cubemapIndex; qboolean personalModel; // don't add mirror only objects if not in a mirror/portal personalModel = (ent->e.renderfx & RF_ONLY_MIRROR) && !(tr.viewParms.isPortal || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))); if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= tr.currentModel->mdv[0]->numFrames; ent->e.oldframe %= tr.currentModel->mdv[0]->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ( (ent->e.frame >= tr.currentModel->mdv[0]->numFrames) || (ent->e.frame < 0) || (ent->e.oldframe >= tr.currentModel->mdv[0]->numFrames) || (ent->e.oldframe < 0) ) { ri.Printf( PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // compute LOD // lod = R_ComputeLOD( ent ); model = tr.currentModel->mdv[lod]; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullModel ( model, ent ); if ( cull == CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // // see if we are in a fog volume // fogNum = R_ComputeFogNum( model, ent ); cubemapIndex = R_CubemapForPoint(ent->e.origin); // // draw all surfaces // surface = model->surfaces; for ( i = 0 ; i < model->numSurfaces ; i++ ) { if ( ent->e.customShader || ent->e.customSkin ) { shader = R_CustomSurfaceShader( surface->name, ent->e.customShader, ent->e.customSkin ); if ( shader == tr.nodrawShader ) { surface++; continue; } //} else if ( surface->numShaders <= 0 ) { //shader = tr.defaultShader; } else { //md3Shader = (md3Shader_t *) ( (byte *)surface + surface->ofsShaders ); //md3Shader += ent->e.skinNum % surface->numShaders; //shader = tr.shaders[ md3Shader->shaderIndex ]; shader = tr.shaders[ surface->shaderIndexes[ ent->e.skinNum % surface->numShaderIndexes ] ]; } // don't add third_person objects if not viewing through a portal if(!personalModel) { srfVaoMdvMesh_t *vaoSurface = &model->vaoSurfaces[i]; R_AddEntDrawSurf( ent, (void *)vaoSurface, shader, fogNum, qfalse, 0, qfalse, cubemapIndex ); } surface++; } }
/* ================= R_AddMD3Surfaces ================= */ void R_AddMD3Surfaces( trRefEntity_t *ent ) { int i; mdvModel_t *model = NULL; mdvSurface_t *surface = NULL; shader_t *shader = NULL; int cull; int lod; int fogNum; int cubemapIndex; qboolean personalModel; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))); if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= tr.currentModel->mdv[0]->numFrames; ent->e.oldframe %= tr.currentModel->mdv[0]->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ( (ent->e.frame >= tr.currentModel->mdv[0]->numFrames) || ( ent->e.frame < 0 ) || (ent->e.oldframe >= tr.currentModel->mdv[0]->numFrames) || ( ent->e.oldframe < 0 ) ) { ri.Printf( PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // compute LOD // lod = R_ComputeLOD( ent ); model = tr.currentModel->mdv[lod]; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullModel ( model, ent ); if ( cull == CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // // see if we are in a fog volume // fogNum = R_ComputeFogNum( model, ent ); cubemapIndex = R_CubemapForPoint(ent->e.origin); // // draw all surfaces // surface = model->surfaces; for ( i = 0 ; i < model->numSurfaces ; i++ ) { int j; //----(SA) blink will change to be an overlay rather than replacing the head texture. // think of it like batman's mask. the polygons that have eye texture are duplicated // and the 'lids' rendered with polygonoffset shader parm over the top of the open eyes. this gives // minimal overdraw/alpha blending/texture use without breaking the model and causing seams if ( !Q_stricmp( surface->name, "h_blink" ) ) { if ( !( ent->e.renderfx & RF_BLINK ) ) { //surface = ( md3Surface_t * )( (byte *)surface + surface->ofsEnd ); //surface++; continue; } } //----(SA) end if ( ent->e.customShader ) { shader = R_GetShaderByHandle( ent->e.customShader ); } else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) { skin_t *skin; skin = R_GetSkinByHandle( ent->e.customSkin ); // match the surface name to something in the skin file shader = tr.defaultShader; for ( j = 0 ; j < skin->numSurfaces ; j++ ) { // the names have both been lowercased if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) { shader = skin->surfaces[j]->shader; break; } } if ( shader == tr.defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name ); } else if ( shader->defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name ); } //} else if ( surface->numShaders <= 0 ) { //shader = tr.defaultShader; } else { //md3Shader = ( md3Shader_t * )( (byte *)surface + surface->ofsShaders ); //md3Shader += ent->e.skinNum % surface->numShaders; shader = tr.shaders[ surface->shaderIndexes[ ent->e.skinNum % surface->numShaderIndexes ] ]; } // don't add third_person objects if not viewing through a portal if ( !personalModel ) { // GR - tessellate according to model capabilities srfVaoMdvMesh_t *vaoSurface = &model->vaoSurfaces[i]; R_AddDrawSurf( (void *)vaoSurface, shader, fogNum, qfalse, qfalse, cubemapIndex, tr.currentModel->ATI_tess ); } surface++; } }