Blender V2.61 - r43446
Classes | Typedefs | Enumerations | Functions

gpu_material.c File Reference

#include <math.h>
#include <string.h>
#include "GL/glew.h"
#include "MEM_guardedalloc.h"
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_world_types.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BKE_anim.h"
#include "BKE_colortools.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_scene.h"
#include "BKE_texture.h"
#include "IMB_imbuf_types.h"
#include "GPU_extensions.h"
#include "GPU_material.h"
#include "gpu_codegen.h"

Go to the source code of this file.

Classes

struct  GPUMaterial
struct  GPULamp

Typedefs

typedef enum DynMatProperty DynMatProperty

Enumerations

enum  DynMatProperty { DYN_LAMP_CO = 1, DYN_LAMP_VEC = 2, DYN_LAMP_IMAT = 4, DYN_LAMP_PERSMAT = 8 }

Functions

static GPUMaterialGPU_material_construct_begin (Material *ma)
static void gpu_material_set_attrib_id (GPUMaterial *material)
static int GPU_material_construct_end (GPUMaterial *material)
void GPU_material_free (Material *ma)
void GPU_material_bind (GPUMaterial *material, int oblay, int viewlay, double time, int mipmap)
void GPU_material_bind_uniforms (GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4], float autobumpscale)
void GPU_material_unbind (GPUMaterial *material)
int GPU_material_bound (GPUMaterial *material)
void GPU_material_vertex_attributes (GPUMaterial *material, GPUVertexAttribs *attribs)
void GPU_material_output_link (GPUMaterial *material, GPUNodeLink *link)
void GPU_material_enable_alpha (GPUMaterial *material)
GPUBlendMode GPU_material_alpha_blend (GPUMaterial *material, float obcol[4])
void gpu_material_add_node (GPUMaterial *material, GPUNode *node)
static int gpu_do_color_management (GPUMaterial *mat)
static GPUNodeLinklamp_get_visibility (GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **lv, GPUNodeLink **dist)
static void ramp_blend (GPUMaterial *mat, GPUNodeLink *fac, GPUNodeLink *col1, GPUNodeLink *col2, int type, GPUNodeLink **outcol)
static void do_colorband_blend (GPUMaterial *mat, ColorBand *coba, GPUNodeLink *fac, float rampfac, int type, GPUNodeLink *incol, GPUNodeLink **outcol)
static void ramp_diffuse_result (GPUShadeInput *shi, GPUNodeLink **diff)
static void add_to_diffuse (GPUMaterial *mat, Material *ma, GPUShadeInput *shi, GPUNodeLink *is, GPUNodeLink *rgb, GPUNodeLink **diff)
static void ramp_spec_result (GPUShadeInput *shi, GPUNodeLink **spec)
static void do_specular_ramp (GPUShadeInput *shi, GPUNodeLink *is, GPUNodeLink *t, GPUNodeLink **spec)
static void add_user_list (ListBase *list, void *data)
static void shade_one_light (GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *lamp)
static void material_lights (GPUShadeInput *shi, GPUShadeResult *shr)
static void texture_rgb_blend (GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg, int blendtype, GPUNodeLink **in)
static void texture_value_blend (GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg, int blendtype, GPUNodeLink **in)
static void do_material_tex (GPUShadeInput *shi)
void GPU_shadeinput_set (GPUMaterial *mat, Material *ma, GPUShadeInput *shi)
void GPU_shaderesult_set (GPUShadeInput *shi, GPUShadeResult *shr)
static GPUNodeLinkGPU_blender_material (GPUMaterial *mat, Material *ma)
GPUMaterialGPU_material_from_blender (Scene *scene, Material *ma)
void GPU_materials_free (void)
void GPU_lamp_update (GPULamp *lamp, int lay, int hide, float obmat[][4])
void GPU_lamp_update_colors (GPULamp *lamp, float r, float g, float b, float energy)
static void gpu_lamp_from_blender (Scene *scene, Object *ob, Object *par, Lamp *la, GPULamp *lamp)
static void gpu_lamp_shadow_free (GPULamp *lamp)
GPULampGPU_lamp_from_blender (Scene *scene, Object *ob, Object *par)
void GPU_lamp_free (Object *ob)
int GPU_lamp_has_shadow_buffer (GPULamp *lamp)
void GPU_lamp_shadow_buffer_bind (GPULamp *lamp, float viewmat[][4], int *winsize, float winmat[][4])
void GPU_lamp_shadow_buffer_unbind (GPULamp *lamp)
int GPU_lamp_shadow_layer (GPULamp *lamp)
GPUShaderExportGPU_shader_export (struct Scene *scene, struct Material *ma)
void GPU_free_shader_export (GPUShaderExport *shader)

Detailed Description

Definition in file gpu_material.c.


Typedef Documentation


Enumeration Type Documentation

Enumerator:
DYN_LAMP_CO 
DYN_LAMP_VEC 
DYN_LAMP_IMAT 
DYN_LAMP_PERSMAT 

Definition at line 71 of file gpu_material.c.


Function Documentation

static void add_to_diffuse ( GPUMaterial mat,
Material ma,
GPUShadeInput shi,
GPUNodeLink is,
GPUNodeLink rgb,
GPUNodeLink **  diff 
) [static]
static void add_user_list ( ListBase list,
void *  data 
) [static]

Definition at line 611 of file gpu_material.c.

References BLI_addtail(), LinkData::data, data, link(), and MEM_callocN().

Referenced by shade_one_light().

static void do_colorband_blend ( GPUMaterial mat,
ColorBand coba,
GPUNodeLink fac,
float  rampfac,
int  type,
GPUNodeLink incol,
GPUNodeLink **  outcol 
) [static]
static void do_material_tex ( GPUShadeInput shi) [static]

(texco_uv && strcmp(mtex->uvname, lastuvname) == 0)) {

Definition at line 894 of file gpu_material.c.

References GPUShadeInput::alpha, MTex::alphafac, GPUShadeInput::amb, MTex::ambfac, BKE_image_get_ibuf(), MTex::blendtype, CD_MTFACE, CD_ORCO, CD_TANGENT, MTex::colfac, MTex::colspecfac, MTex::def_var, MTex::difffac, GPUShadeInput::emit, MTex::emitfac, fabsf, GameData::flag, GAME_GLSL_NO_EXTRA_TEX, Scene::gm, GPU_attribute(), GPU_AUTO_BUMPSCALE, GPU_bicubic_bump_support(), GPU_builtin(), gpu_do_color_management(), GPU_image(), GPU_INVERSE_OBJECT_MATRIX, GPU_INVERSE_VIEW_MATRIX, GPU_link(), GPU_link_changed(), GPU_OBJECT_MATRIX, GPU_uniform(), GPU_VIEW_MATRIX, GPU_VIEW_NORMAL, GPU_VIEW_POSITION, GPUShadeInput::gpumat, GPUShadeInput::har, MTex::hardfac, Tex::ima, Tex::imaflag, Tex::iuser, MAP_ALPHA, MAP_AMB, MAP_COL, MAP_COLSPEC, MAP_EMIT, MAP_HAR, MAP_NORM, MAP_REF, MAP_SPEC, MAP_VARS, MTex::mapto, GPUShadeInput::mat, MAX2, MAX_MTEX, MIN2, Material::mtex, MTEX_3TAP_BUMP, MTEX_5TAP_BUMP, MTEX_BICUBIC_BUMP, MTEX_BUMP_OBJECTSPACE, MTEX_BUMP_TEXTURESPACE, MTEX_NEGATIVE, MTEX_NSPACE_TANGENT, MTEX_RGBTOINT, MTEX_STENCIL, MTex::norfac, MTex::normapspace, NULL, MTex::ofs, MTex::r, GPUShadeInput::ref, GPUShadeInput::refl, GPUShadeInput::rgb, GPUMaterial::scene, Material::septex, MTex::size, GPUShadeInput::spec, MTex::specfac, GPUShadeInput::specrgb, sqrtf, MTex::tex, TEX_DERIVATIVEMAP, TEX_IMAGE, TEX_NORMALMAP, TEX_RGB, TEX_USEALPHA, MTex::texco, TEXCO_GLOB, TEXCO_NORM, TEXCO_OBJECT, TEXCO_ORCO, TEXCO_REFL, TEXCO_TANGENT, TEXCO_UV, MTex::texflag, texture_rgb_blend(), texture_value_blend(), Tex::type, MTex::uvname, GPUShadeInput::view, GPUShadeInput::vn, ImBuf::x, and ImBuf::y.

Referenced by displace_render_vert(), GPU_shaderesult_set(), RE_sample_material_color(), shade_color(), and shade_lamp_loop().

static void do_specular_ramp ( GPUShadeInput shi,
GPUNodeLink is,
GPUNodeLink t,
GPUNodeLink **  spec 
) [static]
static GPUNodeLink* GPU_blender_material ( GPUMaterial mat,
Material ma 
) [static]
static int gpu_do_color_management ( GPUMaterial mat) [static]
void GPU_free_shader_export ( GPUShaderExport shader)
void GPU_lamp_free ( Object ob)
static void gpu_lamp_from_blender ( Scene scene,
Object ob,
Object par,
Lamp la,
GPULamp lamp 
) [static]
GPULamp* GPU_lamp_from_blender ( Scene scene,
Object ob,
Object par 
)
int GPU_lamp_has_shadow_buffer ( GPULamp lamp)
void GPU_lamp_shadow_buffer_bind ( GPULamp lamp,
float  viewmat[][4],
int *  winsize,
float  winmat[][4] 
)
void GPU_lamp_shadow_buffer_unbind ( GPULamp lamp)
static void gpu_lamp_shadow_free ( GPULamp lamp) [static]
int GPU_lamp_shadow_layer ( GPULamp lamp)
void GPU_lamp_update ( GPULamp lamp,
int  lay,
int  hide,
float  obmat[][4] 
)
void GPU_lamp_update_colors ( GPULamp lamp,
float  r,
float  g,
float  b,
float  energy 
)

Definition at line 1509 of file gpu_material.c.

References GPULamp::col, GPULamp::energy, LA_NEG, and GPULamp::mode.

Referenced by gpu_render_lamp_update(), and KX_LightObject::Update().

void gpu_material_add_node ( GPUMaterial material,
GPUNode node 
)

Definition at line 370 of file gpu_material.c.

References BLI_addtail(), and GPUMaterial::nodes.

Referenced by GPU_link(), GPU_stack_link(), and GPU_stack_link_mute().

GPUBlendMode GPU_material_alpha_blend ( GPUMaterial material,
float  obcol[4] 
)
void GPU_material_bind ( GPUMaterial material,
int  oblay,
int  viewlay,
double  time,
int  mipmap 
)
void GPU_material_bind_uniforms ( GPUMaterial material,
float  obmat[][4],
float  viewmat[][4],
float  viewinv[][4],
float  obcol[4],
float  autobumpscale 
)
int GPU_material_bound ( GPUMaterial material)

Definition at line 341 of file gpu_material.c.

References GPUMaterial::bound.

Referenced by LOD_QuadricEditor::Update().

static GPUMaterial* GPU_material_construct_begin ( Material ma) [static]

Definition at line 141 of file gpu_material.c.

References GPUMaterial::ma, and MEM_callocN().

Referenced by GPU_material_from_blender().

static int GPU_material_construct_end ( GPUMaterial material) [static]
void GPU_material_enable_alpha ( GPUMaterial material)

Definition at line 357 of file gpu_material.c.

References GPUMaterial::alpha.

Referenced by GPU_shaderesult_set().

void GPU_material_free ( Material ma)
GPUMaterial* GPU_material_from_blender ( Scene scene,
Material ma 
)
void GPU_material_output_link ( GPUMaterial material,
GPUNodeLink link 
)
static void gpu_material_set_attrib_id ( GPUMaterial material) [static]
void GPU_material_unbind ( GPUMaterial material)
void GPU_material_vertex_attributes ( GPUMaterial material,
GPUVertexAttribs attribs 
)
void GPU_materials_free ( void  )
void GPU_shadeinput_set ( GPUMaterial mat,
Material ma,
GPUShadeInput shi 
)
GPUShaderExport* GPU_shader_export ( struct Scene scene,
struct Material ma 
)

Definition at line 1718 of file gpu_material.c.

References GPUVertexAttribs::attribid, GPUMaterial::attribs, GPUShaderExport::attributes, BLI_addtail(), BLI_snprintf(), BLI_strdup(), BLI_strncpy(), GPUMaterial::builtins, CD_MCOL, CD_MTFACE, CD_ORCO, CD_TANGENT, GPUInputUniform::datatype, GPUInputAttribute::datatype, GPUInput::dynamicdata, GPUInput::dynamictype, ListBase::first, GPUShaderExport::fragment, GPUPass::fragmentcode, GPUVertexAttribs::glindex, GPU_AUTO_BUMPSCALE, GPU_builtin_name(), GPU_DATA_16F, GPU_DATA_1F, GPU_DATA_1I, GPU_DATA_2F, GPU_DATA_3F, GPU_DATA_4F, GPU_DATA_4UB, GPU_DATA_9F, GPU_DATA_NONE, GPU_DYNAMIC_LAMP_FIRST, GPU_DYNAMIC_LAMP_LAST, GPU_DYNAMIC_NONE, GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE, GPU_DYNAMIC_OBJECT_COLOR, GPU_DYNAMIC_OBJECT_IMAT, GPU_DYNAMIC_OBJECT_MAT, GPU_DYNAMIC_OBJECT_VIEWIMAT, GPU_DYNAMIC_OBJECT_VIEWMAT, GPU_DYNAMIC_SAMPLER_2DBUFFER, GPU_DYNAMIC_SAMPLER_2DIMAGE, GPU_DYNAMIC_SAMPLER_2DSHADOW, GPU_glsl_support(), GPU_INVERSE_OBJECT_MATRIX, GPU_INVERSE_VIEW_MATRIX, GPU_material_from_blender(), GPU_OBCOLOR, GPU_OBJECT_MATRIX, GPU_SHADOW2D, GPU_TEX2D, GPU_texture_opengl_bindcode(), GPU_texture_opengl_height(), GPU_texture_opengl_width(), GPU_VIEW_MATRIX, i, GPUInput::ima, GPUInputUniform::image, GPUPass::inputs, GPUInputUniform::lamp, GPUVertexAttribs::layer, GPUPass::libcode, MEM_callocN(), MEM_freeN(), MEM_mallocN(), GPUInputAttribute::name, GPUVertexAttribs::name, GPUInput::next, NULL, GPUInputAttribute::number, GPUMaterial::pass, GPUInput::shadername, strlen(), GPUInput::tex, GPUInput::texid, GPUInputUniform::texnumber, GPUInputUniform::texpixels, GPUInputUniform::texsize, GPUInput::textype, GPUVertexAttribs::totlayer, GPUInput::type, GPUInputUniform::type, GPUVertexAttribs::type, GPUInputAttribute::type, GPUShaderExport::uniforms, GPUInputUniform::varname, GPUInputAttribute::varname, GPUShaderExport::vertex, and GPUPass::vertexcode.

Referenced by GPU_export_shader().

void GPU_shaderesult_set ( GPUShadeInput shi,
GPUShadeResult shr 
)
static GPUNodeLink* lamp_get_visibility ( GPUMaterial mat,
GPULamp lamp,
GPUNodeLink **  lv,
GPUNodeLink **  dist 
) [static]
static void material_lights ( GPUShadeInput shi,
GPUShadeResult shr 
) [static]
static void ramp_blend ( GPUMaterial mat,
GPUNodeLink fac,
GPUNodeLink col1,
GPUNodeLink col2,
int  type,
GPUNodeLink **  outcol 
) [static]

Definition at line 480 of file gpu_material.c.

References GPU_link(), and names.

static void ramp_diffuse_result ( GPUShadeInput shi,
GPUNodeLink **  diff 
) [static]
static void ramp_spec_result ( GPUShadeInput shi,
GPUNodeLink **  spec 
) [static]
static void shade_one_light ( GPUShadeInput shi,
GPUShadeResult shr,
GPULamp lamp 
) [static]

Definition at line 618 of file gpu_material.c.

References add_to_diffuse(), add_user_list(), GPULamp::bias, Material::darkness, GPUShadeResult::diff, Material::diff_shader, do_specular_ramp(), DYN_LAMP_CO, DYN_LAMP_PERSMAT, DYN_LAMP_VEC, GPULamp::dynco, GPULamp::dyncol, GPULamp::dynenergy, GPULamp::dynpersmat, GPUMaterial::dynproperty, GPULamp::dynvec, GameData::flag, GAME_GLSL_NO_SHADERS, GAME_GLSL_NO_SHADOWS, Scene::gm, GPU_builtin(), GPU_DYNAMIC_LAMP_DYNCO, GPU_DYNAMIC_LAMP_DYNCOL, GPU_DYNAMIC_LAMP_DYNENERGY, GPU_DYNAMIC_LAMP_DYNPERSMAT, GPU_DYNAMIC_LAMP_DYNVEC, GPU_DYNAMIC_SAMPLER_2DSHADOW, GPU_dynamic_texture(), GPU_dynamic_uniform(), GPU_lamp_has_shadow_buffer(), GPU_link(), GPU_link_changed(), GPU_uniform(), GPU_VIEW_POSITION, GPUShadeInput::gpumat, GPUShadeInput::har, i, GPULamp::k, LA_AREA, LA_HEMI, LA_NO_DIFF, LA_NO_SPEC, LA_ONLYSHADOW, lamp_get_visibility(), GPUMaterial::lamps, GPUMaterial::ma, MA_CUBIC, MA_DIFF_FRESNEL, MA_DIFF_MINNAERT, MA_DIFF_ORENNAYAR, MA_DIFF_TOON, MA_RAMP_SPEC, MA_SHADOW, MA_SPEC_BLINN, MA_SPEC_COOKTORR, MA_SPEC_PHONG, MA_SPEC_WARDISO, GPUShadeInput::mat, GPULamp::materials, Material::mode, GPULamp::mode, NULL, GPULamp::ob, Material::param, Material::ref, GPUShadeInput::refl, Material::refrac, GPUShadeInput::rgb, Material::rms, Material::roughness, GPUMaterial::scene, Material::shade_flag, spec(), Material::spec, GPUShadeInput::spec, GPUShadeResult::spec, Material::spec_shader, GPUShadeInput::specrgb, GPULamp::tex, GPULamp::type, GPUShadeInput::view, and GPUShadeInput::vn.

Referenced by material_lights().

static void texture_rgb_blend ( GPUMaterial mat,
GPUNodeLink tex,
GPUNodeLink out,
GPUNodeLink fact,
GPUNodeLink facg,
int  blendtype,
GPUNodeLink **  in 
) [static]
static void texture_value_blend ( GPUMaterial mat,
GPUNodeLink tex,
GPUNodeLink out,
GPUNodeLink fact,
GPUNodeLink facg,
int  blendtype,
GPUNodeLink **  in 
) [static]