Skip to content

Commit

Permalink
UPBGE: Add lodbias option for world textures.
Browse files Browse the repository at this point in the history
Waiting for the debate about constant uniforms in the viewport, I added
GPU_uniform(&mtex->lodbias) in do_world_tex and the corresponding UI
  • Loading branch information
youle31 authored and panzergame committed Jul 26, 2016
1 parent 3bdba40 commit 2e2c55b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions release/scripts/startup/bl_ui/properties_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,9 @@ def factor_but(layout, toggle, factor, name):
col = split.column()
factor_but(col, "use_map_zenith_up", "zenith_up_factor", "Zenith Up")
factor_but(col, "use_map_zenith_down", "zenith_down_factor", "Zenith Down")

col = split.column()
col.prop(tex, "lod_bias")
elif isinstance(idblock, ParticleSettings):
split = layout.split()

Expand Down
8 changes: 4 additions & 4 deletions source/blender/gpu/intern/gpu_material.c
Original file line number Diff line number Diff line change
Expand Up @@ -2090,16 +2090,16 @@ static void do_world_tex(GPUShadeInput *shi, struct World *wo, GPUNodeLink **hor
if (ofs[0] != 0.0f || ofs[1] != 0.0f || ofs[2] != 0.0f)
GPU_link(mat, "mtex_mapping_ofs", texco, GPU_uniform(ofs), &texco);
if (mtex->texco == TEXCO_EQUIRECTMAP) {
GPU_link(mat, "node_tex_environment_equirectangular", texco, GPU_image(tex->ima, &tex->iuser, false), &trgb);
GPU_link(mat, "node_tex_environment_equirectangular", texco, GPU_image(tex->ima, &tex->iuser, false), GPU_uniform(&mtex->lodbias), &trgb);
}
else if (mtex->texco == TEXCO_ANGMAP) {
GPU_link(mat, "node_tex_environment_mirror_ball", texco, GPU_image(tex->ima, &tex->iuser, false), &trgb);
GPU_link(mat, "node_tex_environment_mirror_ball", texco, GPU_image(tex->ima, &tex->iuser, false), GPU_uniform(&mtex->lodbias), &trgb);
}
else {
if (tex->type == TEX_ENVMAP)
GPU_link(mat, "mtex_cube_map", texco, GPU_cube_map(tex->ima, &tex->iuser, false), GPU_uniform(&zero), &tin, &trgb);
GPU_link(mat, "mtex_cube_map", texco, GPU_cube_map(tex->ima, &tex->iuser, false), GPU_uniform(&mtex->lodbias), &tin, &trgb);
else if (tex->type == TEX_IMAGE)
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), GPU_uniform(&zero), &tin, &trgb);
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), GPU_uniform(&mtex->lodbias), &tin, &trgb);
}
rgbnor = TEX_RGB;
if (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)
Expand Down
8 changes: 4 additions & 4 deletions source/blender/gpu/shaders/gpu_shader_material.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2940,16 +2940,16 @@ void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac)
fac = 1.0;
}

void node_tex_environment_equirectangular(vec3 co, sampler2D ima, out vec4 color)
void node_tex_environment_equirectangular(vec3 co, sampler2D ima, float lodbias, out vec4 color)
{
vec3 nco = normalize(co);
float u = -atan(nco.y, nco.x) / (2.0 * M_PI) + 0.5;
float v = atan(nco.z, hypot(nco.x, nco.y)) / M_PI + 0.5;

color = texture2D(ima, vec2(u, v));
color = texture2D(ima, vec2(u, v), lodbias);
}

void node_tex_environment_mirror_ball(vec3 co, sampler2D ima, out vec4 color)
void node_tex_environment_mirror_ball(vec3 co, sampler2D ima, float lodbias, out vec4 color)
{
vec3 nco = normalize(co);

Expand All @@ -2962,7 +2962,7 @@ void node_tex_environment_mirror_ball(vec3 co, sampler2D ima, out vec4 color)
float u = 0.5 * (nco.x + 1.0);
float v = 0.5 * (nco.z + 1.0);

color = texture2D(ima, vec2(u, v));
color = texture2D(ima, vec2(u, v), lodbias);
}

void node_tex_environment_empty(vec3 co, out vec4 color)
Expand Down
6 changes: 6 additions & 0 deletions source/blender/makesrna/intern/rna_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ static void rna_def_world_mtex(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Zenith Down", "Affect the color of the zenith below");
RNA_def_property_update(prop, 0, "rna_World_update");

prop = RNA_def_property(srna, "lod_bias", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "lodbias");
RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 10, 3);
RNA_def_property_ui_text(prop, "Lod Bias", "Amount bias on mipmapping");
RNA_def_property_update(prop, 0, "rna_World_update");

prop = RNA_def_property(srna, "texture_coords", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "texco");
RNA_def_property_enum_items(prop, texco_items);
Expand Down

0 comments on commit 2e2c55b

Please sign in to comment.