diff options
author | Thomas Szepe <HG1_public@gmx.net> | 2015-03-24 00:32:49 +0300 |
---|---|---|
committer | Thomas Szepe <HG1_public@gmx.net> | 2015-03-24 00:32:49 +0300 |
commit | c73693d4a5c9b286333a90dd0fc6fd8a7e6ea753 (patch) | |
tree | d7a64433a1acf92a36bb0e064e18b72a729361ca /source/blender/gpu | |
parent | da5fb82a63ea95f75e42092bee60027d3706c9ce (diff) |
BGE: Fix T43592: World GLSL
This patch will fix the world GLSL (mist, background, ambient) update for the BGE.
Reviewers: moguri, brecht
Reviewed By: moguri, brecht
Subscribers: panzergame
Differential Revision: https://developer.blender.org/D151
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_material.h | 14 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 63 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 23 |
3 files changed, 78 insertions, 22 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 2d21b1aeb1d..e27916e5bf7 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -149,6 +149,14 @@ typedef enum GPUDynamicType { GPU_DYNAMIC_LAMP_ATT2 = 18, GPU_DYNAMIC_LAMP_SPOTSIZE = 19, GPU_DYNAMIC_LAMP_SPOTBLEND = 20, + GPU_DYNAMIC_MIST_ENABLE = 21, + GPU_DYNAMIC_MIST_START = 22, + GPU_DYNAMIC_MIST_DISTANCE = 23, + GPU_DYNAMIC_MIST_INTENSITY = 24, + GPU_DYNAMIC_MIST_TYPE = 25, + GPU_DYNAMIC_MIST_COLOR = 26, + GPU_DYNAMIC_HORIZON_COLOR = 27, + GPU_DYNAMIC_AMBIENT_COLOR = 28, } GPUDynamicType; GPUNodeLink *GPU_attribute(CustomDataType type, const char *name); @@ -273,6 +281,12 @@ void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend); int GPU_lamp_shadow_layer(GPULamp *lamp); GPUNodeLink *GPU_lamp_get_data(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **col, GPUNodeLink **lv, GPUNodeLink **dist, GPUNodeLink **shadow, GPUNodeLink **energy); +/* World */ +void GPU_mist_update_enable(short enable); +void GPU_mist_update_values(int type, float start, float dist, float inten, float color[3]); +void GPU_horizon_update_color(float color[3]); +void GPU_ambient_update_color(float color[3]); + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index a9c35896a89..480972d161f 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -76,6 +76,16 @@ typedef enum DynMatProperty { DYN_LAMP_PERSMAT = 8, } DynMatProperty; +static struct GPUWorld { + float mistenabled; + float mistype; + float miststart; + float mistdistance; + float mistintensity; + float mistcol[4]; + float horicol[3]; + float ambcol[4]; +} GPUWorld; struct GPUMaterial { Scene *scene; @@ -1469,13 +1479,39 @@ void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi) 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) { GPUMaterial *mat = shi->gpumat; GPUNodeLink *emit, *ulinfac, *ulogfac, *mistfac; Material *ma = shi->mat; World *world = mat->scene->world; - float linfac, logfac, misttype; + float linfac, logfac; memset(shr, 0, sizeof(*shr)); @@ -1526,10 +1562,10 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) } /* 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) - GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb), - GPU_uniform(&world->ambr), &shr->combined); + if (GPU_link_changed(shi->amb) || ma->amb != 0.0f) { + GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb), + GPU_dynamic_uniform(GPUWorld.ambcol, GPU_DYNAMIC_AMBIENT_COLOR, NULL), + &shr->combined); } } @@ -1551,21 +1587,22 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) if (ma->shade_flag & MA_OBCOLOR) GPU_link(mat, "shade_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined); - if (world && (world->mode & WO_MIST) && !(ma->mode & MA_NOMIST)) { - misttype = world->mistype; - + if (!(ma->mode & MA_NOMIST)) { GPU_link(mat, "shade_mist_factor", GPU_builtin(GPU_VIEW_POSITION), - GPU_uniform(&world->miststa), GPU_uniform(&world->mistdist), - GPU_uniform(&misttype), GPU_uniform(&world->misi), &mistfac); + GPU_dynamic_uniform(&GPUWorld.mistenabled, GPU_DYNAMIC_MIST_ENABLE, NULL), + 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_uniform(&world->horr), &shr->combined); + GPU_dynamic_uniform(GPUWorld.mistcol, GPU_DYNAMIC_MIST_COLOR, NULL), &shr->combined); } if (!mat->alpha) { if (world && (GPU_link_changed(shr->alpha) || ma->alpha != 1.0f)) - GPU_link(mat, "shade_world_mix", GPU_uniform(&world->horr), - shr->combined, &shr->combined); + GPU_link(mat, "shade_world_mix", GPU_dynamic_uniform(GPUWorld.horicol, GPU_DYNAMIC_HORIZON_COLOR, NULL), + shr->combined, &shr->combined); GPU_link(mat, "shade_alpha_opaque", shr->combined, &shr->combined); } diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 5268dea5d55..8edffe787eb 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2099,18 +2099,23 @@ void shade_exposure_correct(vec3 col, float linfac, float logfac, out vec3 outco outcol = linfac*(1.0 - exp(col*logfac)); } -void shade_mist_factor(vec3 co, float miststa, float mistdist, float misttype, float misi, out float outfac) +void shade_mist_factor(vec3 co, float enable, float miststa, float mistdist, float misttype, float misi, out float outfac) { - float fac, zcor; + if(enable == 1.0) { + float fac, zcor; - zcor = (gl_ProjectionMatrix[3][3] == 0.0)? length(co): -co[2]; - - fac = clamp((zcor-miststa)/mistdist, 0.0, 1.0); - if(misttype == 0.0) fac *= fac; - else if(misttype == 1.0); - else fac = sqrt(fac); + zcor = (gl_ProjectionMatrix[3][3] == 0.0)? length(co): -co[2]; + + fac = clamp((zcor - miststa) / mistdist, 0.0, 1.0); + if(misttype == 0.0) fac *= fac; + else if(misttype == 1.0); + else fac = sqrt(fac); - outfac = 1.0 - (1.0-fac)*(1.0-misi); + outfac = 1.0 - (1.0 - fac) * (1.0 - misi); + } + else { + outfac = 0.0; + } } void shade_world_mix(vec3 hor, vec4 col, out vec4 outcol) |