diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpu/GPU_material.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 7 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 11 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_material.c | 2 |
4 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index a111401343e..fab9c28cb61 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -159,6 +159,7 @@ typedef struct GPUShadeInput { GPUNodeLink *rgb, *specrgb, *vn, *view, *vcol, *ref; GPUNodeLink *alpha, *refl, *spec, *emit, *har, *amb; + GPUNodeLink *spectra; } GPUShadeInput; typedef struct GPUShadeResult { diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 32d7e04aeea..fa22783ba2a 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1426,6 +1426,7 @@ void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi) GPU_link(mat, "set_value", GPU_uniform(&ma->emit), &shi->emit); GPU_link(mat, "set_value", GPU_uniform(&hard), &shi->har); GPU_link(mat, "set_value", GPU_uniform(&ma->amb), &shi->amb); + 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, "vcol_attribute", GPU_attribute(CD_MCOL, ""), &shi->vcol); if (GPU_material_do_color_management(mat)) @@ -1497,6 +1498,12 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) } } + if (ma->mode & MA_TRANSP && (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP))) { + if (GPU_link_changed(shi->spectra) || ma->spectra != 0.0f) + GPU_link(mat, "alpha_spec_correction", shr->spec, shi->spectra, + shi->alpha, &shr->alpha); + } + if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shi, &shr->combined); if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shi, &shr->spec); diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index d5bc65eff4f..a737741975e 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -1935,6 +1935,17 @@ void shade_add_spec(float t, vec3 lampcol, vec3 speccol, out vec3 outcol) outcol = t*lampcol*speccol; } +void alpha_spec_correction(vec3 spec, float spectra, float alpha, out float outalpha) +{ + if (spectra > 0.0) { + float t = clamp(max(max(spec.r, spec.g), spec.b) * spectra, 0.0, 1.0); + outalpha = (1.0 - t) * alpha + t; + } + else { + outalpha = alpha; + } +} + void shade_add(vec4 col1, vec4 col2, out vec4 outcol) { outcol = col1 + col2; diff --git a/source/blender/nodes/shader/nodes/node_shader_material.c b/source/blender/nodes/shader/nodes/node_shader_material.c index 79d66495ad7..b7e10c7e9df 100644 --- a/source/blender/nodes/shader/nodes/node_shader_material.c +++ b/source/blender/nodes/shader/nodes/node_shader_material.c @@ -267,6 +267,8 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU shi.amb = gpu_get_input_link(&in[MAT_IN_AMB]); if (hasinput[MAT_IN_EMIT]) shi.emit = gpu_get_input_link(&in[MAT_IN_EMIT]); + if (hasinput[MAT_IN_SPECTRA]) + shi.spectra = gpu_get_input_link(&in[MAT_IN_SPECTRA]); if (hasinput[MAT_IN_ALPHA]) shi.alpha = gpu_get_input_link(&in[MAT_IN_ALPHA]); } |