UFO: Alien Invasion
Loading...
Searching...
No Matches
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.
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.
static void R_StageVertex (const mBspSurface_t *surf, const materialStage_t *stage, const vec3_t in, vec3_t out)
 Vertex deformation.
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).
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.
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.
static void R_SetSurfaceStageState (const mBspSurface_t *surf, const materialStage_t *stage)
 Manages all state for the specified surface and stage.
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.
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.
static GLenum R_ConstByName (const char *c)
 Translate string into glmode.
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.
void R_LoadMaterials (const char *map)
 Load material definitions for each map that has one.
void R_UpdateDefaultMaterial (const char *cvarName, const char *oldValue, const char *newValue, void *data)
 Change listener callback for material value cvars.

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.

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.

Referenced by R_UpdateMaterial().

Function Documentation

◆ R_ConstByName()

GLenum R_ConstByName ( const char * c)
static

Translate string into glmode.

Definition at line 480 of file r_material.cpp.

References Com_Printf(), GLenum, and Q_streq.

Referenced by R_ParseStage().

◆ R_CreateMaterialData()

void R_CreateMaterialData ( void )
static

◆ R_CreateMaterialData_()

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 mBspSurfaces_t::count, mBspSurface_t::frame, i, mBspTexInfo_t::image, 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()

void R_DrawSurfaceStage ( mBspSurface_t * surf,
materialStage_t * stage )
static

Render the specified stage for the surface. Resolve vertex attributes via helper functions, outputting to the default vertex arrays.

Definition at line 349 of file r_material.cpp.

References i, mBspSurface_t::index, mBspSurface_t::numedges, R_CheckError, r_mapTiles, R_ReallocateStateArrays(), R_ReallocateTexunitArray(), R_StageColor(), R_StageTexCoord(), R_StageVertex(), r_state, refdef, texunit_diffuse, texunit_lightmap, mBspSurface_t::tile, and v.

Referenced by R_DrawMaterialSurfaces().

◆ R_LoadAnimImages()

◆ R_LoadMaterials()

◆ R_ParseStage()

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

◆ R_SetSurfaceStageState()

◆ R_StageColor()

◆ R_StageGlow()

◆ R_StageLighting()

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

Manages state for stages supporting static, dynamic, and per-pixel lighting.

Todo
fix it and enable it back for r_materials 1

Definition at line 130 of file r_material.cpp.

References materialStage_t::flags, mBspSurface_t::flags, materialStage_t::image, mBspSurface_t::lightmap_texnum, MSURF_LIGHTMAP, R_BindLightmapTexture(), R_EnableLighting(), R_EnableTexture(), r_materials, R_SetSurfaceBumpMappingParameters(), r_state, STAGE_LIGHTING, STAGE_LIGHTMAP, and texunit_lightmap.

Referenced by R_SetSurfaceStageState().

◆ R_StageTexCoord()

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(), and VectorSubtract.

Referenced by R_DrawSurfaceStage().

◆ R_StageTextureMatrix()

◆ R_StageVertex()

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 data, defaultMaterial, r_default_hardness, and r_default_specular.

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

◆ R_UpdateMaterial()

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, 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.