UFO: Alien Invasion
r_material.cpp File Reference

Material related code. More...

#include "r_local.h"
#include "r_error.h"
#include "r_lightmap.h"
#include "../../shared/parse.h"
Include dependency graph for r_material.cpp:

Go to the source code of this file.

Macros

#define UPDATE_THRESHOLD   0.02
 

Functions

static void R_UpdateMaterial (material_t *m)
 Materials "think" every few milliseconds to advance animations. More...
 
static void R_StageGlow (const materialStage_t *stage)
 
static void R_StageLighting (const mBspSurface_t *surf, const materialStage_t *stage)
 Manages state for stages supporting static, dynamic, and per-pixel lighting. More...
 
static void R_StageVertex (const mBspSurface_t *surf, const materialStage_t *stage, const vec3_t in, vec3_t out)
 Vertex deformation. More...
 
static void R_StageTextureMatrix (const mBspSurface_t *surf, const materialStage_t *stage)
 Manages texture matrix manipulations for stages supporting rotations, scrolls, and stretches (rotate, translate, scale). More...
 
static void R_StageTexCoord (const materialStage_t *stage, const vec3_t v, const vec2_t in, vec2_t out)
 Generates a single texture coordinate for the specified stage and vertex. More...
 
static void R_StageColor (const materialStage_t *stage, const vec3_t v, vec4_t color)
 Generates a single color for the specified stage and vertex. More...
 
static void R_SetSurfaceStageState (const mBspSurface_t *surf, const materialStage_t *stage)
 Manages all state for the specified surface and stage. More...
 
static void R_DrawSurfaceStage (mBspSurface_t *surf, materialStage_t *stage)
 Render the specified stage for the surface. Resolve vertex attributes via helper functions, outputting to the default vertex arrays. More...
 
void R_DrawMaterialSurfaces (const mBspSurfaces_t *surfs, glElementIndex_t *indexPtr)
 Iterates the specified surfaces list, updating materials as they are encountered, and rendering all visible stages. State is lazily managed throughout the iteration, so there is a concerted effort to restore the state after all surface stages have been rendered. More...
 
static GLenum R_ConstByName (const char *c)
 Translate string into glmode. More...
 
static void R_CreateMaterialData_ (model_t *mod)
 
static void R_CreateMaterialData (void)
 
static int R_LoadAnimImages (materialStage_t *s)
 
static int R_ParseStage (materialStage_t *s, const char **buffer)
 Material stage parser. More...
 
void R_LoadMaterials (const char *map)
 Load material definitions for each map that has one. More...
 
void R_UpdateDefaultMaterial (const char *cvarName, const char *oldValue, const char *newValue, void *data)
 Change listener callback for material value cvars. More...
 

Variables

mBspSurfaces_t r_material_surfaces
 
material_t defaultMaterial = {0, 0.0f, DEFAULT_BUMP, DEFAULT_PARALLAX, DEFAULT_HARDNESS, DEFAULT_SPECULAR, DEFAULT_GLOWSCALE, nullptr, 0}
 
static const float dirtmap []
 Array with 'random' alpha values for the dirtmap. More...
 

Detailed Description

Material related code.

Definition in file r_material.cpp.

Macro Definition Documentation

◆ UPDATE_THRESHOLD

#define UPDATE_THRESHOLD   0.02

Definition at line 36 of file r_material.cpp.

Function Documentation

◆ R_ConstByName()

static GLenum R_ConstByName ( const char *  c)
static

Translate string into glmode.

Definition at line 480 of file r_material.cpp.

References Com_Printf(), and Q_streq.

Referenced by R_ParseStage().

◆ R_CreateMaterialData()

static void R_CreateMaterialData ( void  )
static

◆ R_CreateMaterialData_()

static void R_CreateMaterialData_ ( model_t mod)
static

◆ R_DrawMaterialSurfaces()

void R_DrawMaterialSurfaces ( const mBspSurfaces_t surfs,
glElementIndex_t indexPtr 
)

Iterates the specified surfaces list, updating materials as they are encountered, and rendering all visible stages. State is lazily managed throughout the iteration, so there is a concerted effort to restore the state after all surface stages have been rendered.

Todo:
  • integrate BSP lighting with model lighting

Definition at line 399 of file r_material.cpp.

References rstate_t::blend_enabled, mBspSurfaces_t::count, rlocals_t::frame, mBspSurface_t::frame, i, mBspTexInfo_t::image, cvar_t::integer, m, image_t::material, R_BlendFunc(), R_Color(), R_DrawSurfaceStage(), R_EnableBumpmap(), R_EnableColorArray(), R_EnableFog(), R_EnableGlowMap(), R_EnableLighting(), R_EnableModelLights(), R_EnableTexture(), r_locals, r_materials, R_ResetArrayState(), R_SetSurfaceStageState(), r_state, R_UpdateMaterial(), r_wire, STAGE_RENDER, mBspSurfaces_t::surfaces, mBspSurface_t::texinfo, and texunit_lightmap.

Referenced by R_RenderMaterialBspRRefs().

◆ R_DrawSurfaceStage()

◆ R_LoadAnimImages()

◆ R_LoadMaterials()

◆ R_ParseStage()

static int R_ParseStage ( materialStage_t s,
const char **  buffer 
)
static

Material stage parser.

See also
R_LoadMaterials

Definition at line 563 of file r_material.cpp.

References stretch_t::amp, materialStage_t::anim, ANIM_ALTERNATE, ANIM_BACKWARDS, ANIM_NORMAL, ANIM_RANDOM, ANIM_RANDOMFORCE, materialStage_t::blend, terrain_t::ceil, tape_t::ceil, tape_t::center, materialStage_t::color, Com_DPrintf(), Com_Parse(), Com_Printf(), DEBUG_RENDERER, defaultMaterial, blendmode_t::dest, materialStage_t::dirt, pulse_t::dutycycle, materialStage_t::flags, terrain_t::floor, tape_t::floor, anim_t::fps, materialStage_t::glowscale, material_t::glowscale, terrain_t::height, tape_t::height, rotate_t::hz, pulse_t::hz, stretch_t::hz, i, materialStage_t::image, dirt_t::intensity, it_material, tape_t::max, MAX_ANIM_FRAMES, MAX_ENVMAPTEXTURES, tape_t::min, NUM_FLARETEXTURES, anim_t::num_frames, materialStage_t::pulse, Q_streq, Q_strstart(), R_ConstByName(), r_envmaptextures, R_FindImage(), r_flaretextures, r_noTexture, materialStage_t::rotate, scroll_t::s, scale_t::s, materialStage_t::scale, materialStage_t::scroll, blendmode_t::src, STAGE_ANIM, STAGE_BLEND, STAGE_COLOR, STAGE_DIRTMAP, STAGE_ENVMAP, STAGE_FLARE, STAGE_GLOWMAPLINK, STAGE_LIGHTING, STAGE_LIGHTMAP, STAGE_PULSE, STAGE_RENDER, STAGE_ROTATE, STAGE_SCALE_S, STAGE_SCALE_T, STAGE_SCROLL_S, STAGE_SCROLL_T, STAGE_STRETCH, STAGE_TAPE, STAGE_TERRAIN, STAGE_TEXTURE, materialStage_t::stretch, scroll_t::t, scale_t::t, materialStage_t::tape, materialStage_t::terrain, anim_t::type, and va().

Referenced by R_LoadMaterials().

◆ R_SetSurfaceStageState()

◆ R_StageColor()

◆ R_StageGlow()

◆ R_StageLighting()

static void R_StageLighting ( const mBspSurface_t surf,
const materialStage_t stage 
)
static

◆ R_StageTexCoord()

static void R_StageTexCoord ( const materialStage_t stage,
const vec3_t  v,
const vec2_t  in,
vec2_t  out 
)
static

Generates a single texture coordinate for the specified stage and vertex.

Definition at line 219 of file r_material.cpp.

References materialStage_t::flags, refdef, STAGE_ENVMAP, v, Vector2Copy, VectorNormalizeFast(), VectorSubtract, and rendererData_t::viewOrigin.

Referenced by R_DrawSurfaceStage().

◆ R_StageTextureMatrix()

static void R_StageTextureMatrix ( const mBspSurface_t surf,
const materialStage_t stage 
)
inlinestatic

◆ R_StageVertex()

static void R_StageVertex ( const mBspSurface_t surf,
const materialStage_t stage,
const vec3_t  in,
vec3_t  out 
)
inlinestatic

Vertex deformation.

Todo:
implement this

Definition at line 162 of file r_material.cpp.

References VectorCopy.

Referenced by R_DrawSurfaceStage().

◆ R_UpdateDefaultMaterial()

void R_UpdateDefaultMaterial ( const char *  cvarName,
const char *  oldValue,
const char *  newValue,
void data 
)

Change listener callback for material value cvars.

Definition at line 1092 of file r_material.cpp.

References defaultMaterial, material_t::hardness, r_default_hardness, r_default_specular, material_t::specular, and cvar_t::value.

Referenced by R_Init(), R_RegisterSystemVars(), and R_ReinitOpenglContext().

◆ R_UpdateMaterial()

static void R_UpdateMaterial ( material_t m)
static

Materials "think" every few milliseconds to advance animations.

Definition at line 40 of file r_material.cpp.

References ANIM_ALTERNATE, ANIM_BACKWARDS, ANIM_NORMAL, ANIM_RANDOM, ANIM_RANDOMFORCE, m, M_PI, refdef, STAGE_ANIM, STAGE_PULSE, STAGE_ROTATE, STAGE_SCROLL_S, STAGE_SCROLL_T, STAGE_STRETCH, rendererData_t::time, and UPDATE_THRESHOLD.

Referenced by R_DrawMaterialSurfaces().

Variable Documentation

◆ defaultMaterial

◆ dirtmap

const float dirtmap[]
static
Initial value:
= {
0.6, 0.5, 0.3, 0.4, 0.7, 0.3, 0.0, 0.4,
0.5, 0.2, 0.8, 0.5, 0.3, 0.2, 0.5, 0.3
}

Array with 'random' alpha values for the dirtmap.

Definition at line 232 of file r_material.cpp.

Referenced by R_StageColor().

◆ r_material_surfaces

mBspSurfaces_t r_material_surfaces

Definition at line 31 of file r_material.cpp.