Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_material.c
| Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| /* Structs */ | /* Structs */ | ||||
| typedef enum DynMatProperty { | typedef enum DynMatProperty { | ||||
| DYN_LAMP_CO = 1, | DYN_LAMP_CO = 1, | ||||
| DYN_LAMP_VEC = 2, | DYN_LAMP_VEC = 2, | ||||
| DYN_LAMP_IMAT = 4, | DYN_LAMP_IMAT = 4, | ||||
| DYN_LAMP_PERSMAT = 8, | DYN_LAMP_PERSMAT = 8, | ||||
| } DynMatProperty; | } DynMatProperty; | ||||
| static struct GPUWorld { | |||||
| float mistenabled; | |||||
| float mistype; | |||||
| float miststart; | |||||
| float mistdistance; | |||||
| float mistintensity; | |||||
| float mistcol[4]; | |||||
| float horicol[3]; | |||||
| float ambcol[4]; | |||||
brecht: Can you make this `static` and rename `gpuworld` to `GPUCurrentWorld` or something like that? | |||||
Not Done Inline ActionsI seems that the structure name and the variable name is always the same. I will rename the variable gpuworld to GPUWorld. hg1: I seems that the structure name and the variable name is always the same. I will rename the… | |||||
| } GPUWorld; | |||||
| struct GPUMaterial { | struct GPUMaterial { | ||||
| Scene *scene; | Scene *scene; | ||||
| Material *ma; | Material *ma; | ||||
| /* material for mesh surface, worlds or something else. | /* material for mesh surface, worlds or something else. | ||||
| * some code generation is done differently depending on the use case */ | * some code generation is done differently depending on the use case */ | ||||
| int type; | int type; | ||||
| ▲ Show 20 Lines • Show All 1,318 Lines • ▼ Show 20 Lines | if (ma->mtex[tex_nr]) { | ||||
| GPU_link(mat, "mtex_value_clamp_positive", shi->emit, &shi->emit); | GPU_link(mat, "mtex_value_clamp_positive", shi->emit, &shi->emit); | ||||
| } | } | ||||
| if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_HAR) { | if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_HAR) { | ||||
| GPUNodeLink *hardfac; | GPUNodeLink *hardfac; | ||||
| if (mtex->hardfac == 1.0f) hardfac = stencil; | if (mtex->hardfac == 1.0f) hardfac = stencil; | ||||
| else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->hardfac), stencil, &hardfac); | else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->hardfac), stencil, &hardfac); | ||||
| GPU_link(mat, "mtex_har_divide", shi->har, &shi->har); | GPU_link(mat, "mtex_har_divide", shi->har, &shi->har); | ||||
| texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->har, tin, hardfac, mtex->blendtype, &shi->har); | texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->har, tin, hardfac, mtex->blendtype, &shi->har); | ||||
| GPU_link(mat, "mtex_har_multiply_clamp", shi->har, &shi->har); | GPU_link(mat, "mtex_har_multiply_clamp", shi->har, &shi->har); | ||||
Not Done Inline Actionscan use copy_v3_v3 here and in other places. brecht: can use `copy_v3_v3` here and in other places. | |||||
| } | } | ||||
| if (mtex->mapto & MAP_ALPHA) { | if (mtex->mapto & MAP_ALPHA) { | ||||
| GPUNodeLink *alphafac; | GPUNodeLink *alphafac; | ||||
| if (mtex->alphafac == 1.0f) alphafac = stencil; | if (mtex->alphafac == 1.0f) alphafac = stencil; | ||||
| else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->alphafac), stencil, &alphafac); | else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->alphafac), stencil, &alphafac); | ||||
| texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->alpha, tin, alphafac, mtex->blendtype, &shi->alpha); | texture_value_blend(mat, GPU_uniform(&mtex->def_var), shi->alpha, tin, alphafac, mtex->blendtype, &shi->alpha); | ||||
| Show All 40 Lines | void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi) | ||||
| GPU_link(mat, "set_value", GPU_uniform(&ma->spectra), &shi->spectra); | GPU_link(mat, "set_value", GPU_uniform(&ma->spectra), &shi->spectra); | ||||
| GPU_link(mat, "shade_view", GPU_builtin(GPU_VIEW_POSITION), &shi->view); | GPU_link(mat, "shade_view", GPU_builtin(GPU_VIEW_POSITION), &shi->view); | ||||
| GPU_link(mat, "vcol_attribute", GPU_attribute(CD_MCOL, ""), &shi->vcol); | GPU_link(mat, "vcol_attribute", GPU_attribute(CD_MCOL, ""), &shi->vcol); | ||||
| if (GPU_material_do_color_management(mat)) | if (GPU_material_do_color_management(mat)) | ||||
| GPU_link(mat, "srgb_to_linearrgb", shi->vcol, &shi->vcol); | GPU_link(mat, "srgb_to_linearrgb", shi->vcol, &shi->vcol); | ||||
| GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref); | GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref); | ||||
| } | } | ||||
| void GPU_mist_update_enable(short enable) | |||||
| { | |||||
| GPUWorld.mistenabled = (float)enable; | |||||
| } | |||||
| void GPU_mist_update_values(int type, float start, float dist, float inten, float color[3]) | |||||
| { | |||||
| GPUWorld.mistype = (float)type; | |||||
| GPUWorld.miststart = start; | |||||
| GPUWorld.mistdistance = dist; | |||||
| GPUWorld.mistintensity = inten; | |||||
| copy_v3_v3(GPUWorld.mistcol, color); | |||||
| GPUWorld.mistcol[3] = 1.0f; | |||||
| } | |||||
| void GPU_horizon_update_color(float color[3]) | |||||
| { | |||||
| copy_v3_v3(GPUWorld.horicol, color); | |||||
| } | |||||
| void GPU_ambient_update_color(float color[3]) | |||||
| { | |||||
| copy_v3_v3(GPUWorld.ambcol, color); | |||||
| GPUWorld.ambcol[3] = 1.0f; | |||||
| } | |||||
| void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) | void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) | ||||
| { | { | ||||
| GPUMaterial *mat = shi->gpumat; | GPUMaterial *mat = shi->gpumat; | ||||
| GPUNodeLink *emit, *ulinfac, *ulogfac, *mistfac; | GPUNodeLink *emit, *ulinfac, *ulogfac, *mistfac; | ||||
| Material *ma = shi->mat; | Material *ma = shi->mat; | ||||
| World *world = mat->scene->world; | World *world = mat->scene->world; | ||||
| float linfac, logfac, misttype; | float linfac, logfac; | ||||
| memset(shr, 0, sizeof(*shr)); | memset(shr, 0, sizeof(*shr)); | ||||
| if (ma->mode & MA_VERTEXCOLP) | if (ma->mode & MA_VERTEXCOLP) | ||||
| shi->rgb = shi->vcol; | shi->rgb = shi->vcol; | ||||
| do_material_tex(shi); | do_material_tex(shi); | ||||
| Show All 34 Lines | if (world) { | ||||
| GPU_link(mat, "shade_exposure_correct", shr->combined, | GPU_link(mat, "shade_exposure_correct", shr->combined, | ||||
| ulinfac, ulogfac, &shr->combined); | ulinfac, ulogfac, &shr->combined); | ||||
| GPU_link(mat, "shade_exposure_correct", shr->spec, | GPU_link(mat, "shade_exposure_correct", shr->spec, | ||||
| ulinfac, ulogfac, &shr->spec); | ulinfac, ulogfac, &shr->spec); | ||||
| } | } | ||||
| /* ambient color */ | /* ambient color */ | ||||
| if (world->ambr != 0.0f || world->ambg != 0.0f || world->ambb != 0.0f) { | if (GPU_link_changed(shi->amb) || ma->amb != 0.0f) { | ||||
| if (GPU_link_changed(shi->amb) || ma->amb != 0.0f) | |||||
| GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb), | GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb), | ||||
| GPU_uniform(&world->ambr), &shr->combined); | GPU_dynamic_uniform(GPUWorld.ambcol, GPU_DYNAMIC_AMBIENT_COLOR, NULL), | ||||
| &shr->combined); | |||||
| } | } | ||||
| } | } | ||||
| if (ma->mode & MA_TRANSP && (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP))) { | if (ma->mode & MA_TRANSP && (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP))) { | ||||
| if (GPU_link_changed(shi->spectra) || ma->spectra != 0.0f) | if (GPU_link_changed(shi->spectra) || ma->spectra != 0.0f) | ||||
| GPU_link(mat, "alpha_spec_correction", shr->spec, shi->spectra, | GPU_link(mat, "alpha_spec_correction", shr->spec, shi->spectra, | ||||
| shi->alpha, &shr->alpha); | shi->alpha, &shr->alpha); | ||||
| } | } | ||||
| if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shi, &shr->combined); | if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shi, &shr->combined); | ||||
| if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shi, &shr->spec); | if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shi, &shr->spec); | ||||
| if (GPU_link_changed(shi->spec) || ma->spec != 0.0f) | if (GPU_link_changed(shi->spec) || ma->spec != 0.0f) | ||||
| GPU_link(mat, "shade_add", shr->combined, shr->spec, &shr->combined); | GPU_link(mat, "shade_add", shr->combined, shr->spec, &shr->combined); | ||||
| } | } | ||||
| GPU_link(mat, "mtex_alpha_to_col", shr->combined, shr->alpha, &shr->combined); | GPU_link(mat, "mtex_alpha_to_col", shr->combined, shr->alpha, &shr->combined); | ||||
| if (ma->shade_flag & MA_OBCOLOR) | if (ma->shade_flag & MA_OBCOLOR) | ||||
| GPU_link(mat, "shade_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined); | GPU_link(mat, "shade_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined); | ||||
| if (world && (world->mode & WO_MIST) && !(ma->mode & MA_NOMIST)) { | if (!(ma->mode & MA_NOMIST)) { | ||||
| misttype = world->mistype; | |||||
| GPU_link(mat, "shade_mist_factor", GPU_builtin(GPU_VIEW_POSITION), | GPU_link(mat, "shade_mist_factor", GPU_builtin(GPU_VIEW_POSITION), | ||||
| GPU_uniform(&world->miststa), GPU_uniform(&world->mistdist), | GPU_dynamic_uniform(&GPUWorld.mistenabled, GPU_DYNAMIC_MIST_ENABLE, NULL), | ||||
| GPU_uniform(&misttype), GPU_uniform(&world->misi), &mistfac); | GPU_dynamic_uniform(&GPUWorld.miststart, GPU_DYNAMIC_MIST_START, NULL), | ||||
| GPU_dynamic_uniform(&GPUWorld.mistdistance, GPU_DYNAMIC_MIST_DISTANCE, NULL), | |||||
| GPU_dynamic_uniform(&GPUWorld.mistype, GPU_DYNAMIC_MIST_TYPE, NULL), | |||||
| GPU_dynamic_uniform(&GPUWorld.mistintensity, GPU_DYNAMIC_MIST_INTENSITY, NULL), &mistfac); | |||||
| GPU_link(mat, "mix_blend", mistfac, shr->combined, | GPU_link(mat, "mix_blend", mistfac, shr->combined, | ||||
| GPU_uniform(&world->horr), &shr->combined); | GPU_dynamic_uniform(GPUWorld.mistcol, GPU_DYNAMIC_MIST_COLOR, NULL), &shr->combined); | ||||
| } | } | ||||
| if (!mat->alpha) { | if (!mat->alpha) { | ||||
| if (world && (GPU_link_changed(shr->alpha) || ma->alpha != 1.0f)) | if (world && (GPU_link_changed(shr->alpha) || ma->alpha != 1.0f)) | ||||
| GPU_link(mat, "shade_world_mix", GPU_uniform(&world->horr), | GPU_link(mat, "shade_world_mix", GPU_dynamic_uniform(GPUWorld.horicol, GPU_DYNAMIC_HORIZON_COLOR, NULL), | ||||
| shr->combined, &shr->combined); | shr->combined, &shr->combined); | ||||
| GPU_link(mat, "shade_alpha_opaque", shr->combined, &shr->combined); | GPU_link(mat, "shade_alpha_opaque", shr->combined, &shr->combined); | ||||
| } | } | ||||
| if (ma->shade_flag & MA_OBCOLOR) { | if (ma->shade_flag & MA_OBCOLOR) { | ||||
| mat->obcolalpha = 1; | mat->obcolalpha = 1; | ||||
| GPU_link(mat, "shade_alpha_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined); | GPU_link(mat, "shade_alpha_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 785 Lines • Show Last 20 Lines | |||||
Can you make this static and rename gpuworld to GPUCurrentWorld or something like that? There isn't really a convention for this but global variables are not typically lowercase.