Merge pull request #1337 from Naxela/master
Lens dirt masking + Chromatic Aberration
This commit is contained in:
commit
cb250a40f6
|
@ -0,0 +1,69 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.inc"
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec2 texCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
vec2 barrelDistortion(vec2 coord, float amt) {
|
||||
vec2 cc = coord - 0.5;
|
||||
float dist = dot(cc, cc);
|
||||
return coord + cc * dist * amt;
|
||||
}
|
||||
float sat(float value)
|
||||
{
|
||||
return clamp(value, 0.0, 1.0);
|
||||
}
|
||||
float linterp(float t) {
|
||||
return sat(1.0 - abs(2.0 * t - 1.0) );
|
||||
}
|
||||
float remap(float t, float a, float b ) {
|
||||
return sat((t - a) / (b - a));
|
||||
}
|
||||
vec4 spectrum_offset(float t) {
|
||||
vec4 ret;
|
||||
float low = step(t,0.5);
|
||||
float high = 1.0 - low;
|
||||
float minMap = 1.0;
|
||||
float maxMap = 6.0;
|
||||
float w = linterp( remap(t, minMap/maxMap, 5.0/maxMap ) );
|
||||
ret = vec4(low, 1.0, high, 1.) * vec4(1.0-w, w, 1.0-w, 1.0);
|
||||
|
||||
return pow(ret, vec4(1.0/2.2) );
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
float max_distort = compoChromaticStrength;
|
||||
int num_iter = compoChromaticSamples;
|
||||
|
||||
float reci_num_iter_f = 1.0 / float(num_iter);
|
||||
|
||||
if (compoChromaticType == 1) {
|
||||
vec2 resolution = vec2(1,1);
|
||||
vec2 uv = (texCoord.xy/resolution.xy);
|
||||
vec4 sumcol = vec4(0.0);
|
||||
vec4 sumw = vec4(0.0);
|
||||
for (int i=0; i < num_iter; ++i)
|
||||
{
|
||||
float t = float(i) * reci_num_iter_f;
|
||||
vec4 w = spectrum_offset(t);
|
||||
sumw += w;
|
||||
sumcol += w * texture(tex, barrelDistortion(uv, 0.6 * max_distort * t));
|
||||
}
|
||||
|
||||
fragColor = sumcol / sumw;
|
||||
|
||||
} else {
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
col.x = texture(tex, texCoord + ((vec2(0.0, 1.0) * max_distort) / vec2(1000.0))).x;
|
||||
col.y = texture(tex, texCoord + ((vec2(-0.85, -0.5) * max_distort) / vec2(1000.0))).y;
|
||||
col.z = texture(tex, texCoord + ((vec2(0.85, -0.5) * max_distort) / vec2(1000.0))).z;
|
||||
fragColor = vec4(col.x, col.y, col.z, fragColor.w);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"contexts": [
|
||||
{
|
||||
"name": "chromatic_aberration_pass",
|
||||
"depth_write": false,
|
||||
"color_write_alpha": false,
|
||||
"compare_mode": "always",
|
||||
"cull_mode": "none",
|
||||
"links": [],
|
||||
"texture_params": [],
|
||||
"vertex_shader": "../include/pass.vert.glsl",
|
||||
"fragment_shader": "chromatic_aberration_pass.frag.glsl"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -327,7 +327,23 @@ void main() {
|
|||
// #endif
|
||||
|
||||
#ifdef _CLensTex
|
||||
fragColor.rgb += textureLod(lensTexture, texCo, 0.0).rgb;
|
||||
#ifdef _CLensTexMasking
|
||||
vec4 scratches = texture(lensTexture, texCo);
|
||||
vec3 scratchBlend = fragColor.rgb + scratches.rgb;
|
||||
|
||||
float centerMaxClip = compoCenterMaxClip;
|
||||
float centerMinClip = compoCenterMinClip;
|
||||
float luminanceMax = compoLuminanceMax;
|
||||
float luminanceMin = compoLuminanceMin;
|
||||
float brightnessExp = compoBrightnessExponent;
|
||||
|
||||
float center = smoothstep(centerMaxClip, centerMinClip, length(texCo - 0.5));
|
||||
float luminance = dot(fragColor.rgb, vec3(0.299, 0.587, 0.114));
|
||||
float brightnessMap = smoothstep(luminanceMax, luminanceMin, luminance * center);
|
||||
fragColor.rgb = clamp(mix(fragColor.rgb, scratchBlend, brightnessMap * brightnessExp), 0, 1);
|
||||
#else
|
||||
fragColor.rgb += textureLod(lensTexture, texCo, 0.0).rgb;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _CLetterbox
|
||||
|
|
|
@ -378,6 +378,14 @@ class RenderPathDeferred {
|
|||
path.renderTargets.set(t.name, rt);
|
||||
}
|
||||
#end
|
||||
|
||||
#if rp_chromatic_aberration
|
||||
{
|
||||
path.loadShader("shader_datas/chromatic_aberration_pass/chromatic_aberration_pass");
|
||||
path.loadShader("shader_datas/copy_pass/copy_pass");
|
||||
}
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
@:access(iron.RenderPath)
|
||||
|
@ -775,6 +783,17 @@ class RenderPathDeferred {
|
|||
}
|
||||
#end
|
||||
|
||||
#if rp_chromatic_aberration
|
||||
{
|
||||
path.setTarget("buf");
|
||||
path.bindTarget("tex","tex");
|
||||
path.drawShader("shader_datas/chromatic_aberration_pass/chromatic_aberration_pass");
|
||||
path.setTarget("tex");
|
||||
path.bindTarget("buf", "tex");
|
||||
path.drawShader("shader_datas/copy_pass/copy_pass");
|
||||
}
|
||||
#end
|
||||
|
||||
// We are just about to enter compositing, add more custom passes here
|
||||
// #if rp_custom_pass
|
||||
// {
|
||||
|
|
|
@ -184,6 +184,8 @@ def build():
|
|||
if rpdat.arm_lens_texture != '':
|
||||
wrd.compo_defs += '_CLensTex'
|
||||
assets.add_embedded_data('lenstexture.jpg')
|
||||
if rpdat.arm_lens_texture_masking:
|
||||
wrd.compo_defs += '_CLensTexMasking'
|
||||
if rpdat.arm_fisheye:
|
||||
wrd.compo_defs += '_CFishEye'
|
||||
if rpdat.arm_vignette:
|
||||
|
@ -331,6 +333,11 @@ def build():
|
|||
if rpdat.rp_dynres:
|
||||
assets.add_khafile_def('rp_dynres')
|
||||
|
||||
if rpdat.rp_chromatic_aberration:
|
||||
assets.add_shader_pass('copy_pass')
|
||||
assets.add_khafile_def('rp_chromatic_aberration')
|
||||
assets.add_shader_pass('chromatic_aberration_pass')
|
||||
|
||||
gbuffer2 = '_Veloc' in wrd.world_defs
|
||||
if gbuffer2:
|
||||
assets.add_khafile_def('rp_gbuffer2')
|
||||
|
|
|
@ -379,6 +379,7 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
('Point', 'Closest', 'Point')],
|
||||
name="Filter", description="Scaling filter", default='Linear')
|
||||
rp_dynres: BoolProperty(name="Dynamic Resolution", description="Dynamic resolution scaling for performance", default=False, update=update_renderpath)
|
||||
rp_chromatic_aberration: BoolProperty(name="Chromatic Aberration", description="Add chromatic aberration (scene fringe)", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_ssr_half_res: BoolProperty(name="Half Res", description="Trace in half resolution", default=True, update=update_renderpath)
|
||||
arm_voxelgi_dimensions: FloatProperty(name="Dimensions", description="Voxelization bounds",default=16, update=assets.invalidate_compiled_data)
|
||||
arm_voxelgi_revoxelize: BoolProperty(name="Revoxelize", description="Revoxelize scene each frame", default=False, update=assets.invalidate_shader_cache)
|
||||
|
@ -447,6 +448,13 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
arm_autoexposure_strength: FloatProperty(name="Auto Exposure Strength", default=1.0, update=assets.invalidate_shader_cache)
|
||||
arm_autoexposure_speed: FloatProperty(name="Auto Exposure Speed", default=1.0, update=assets.invalidate_shader_cache)
|
||||
arm_ssrs_ray_step: FloatProperty(name="Step", default=0.01, update=assets.invalidate_shader_cache)
|
||||
arm_chromatic_aberration_type: EnumProperty(
|
||||
items=[('Simple', 'Simple', 'Simple'),
|
||||
('Spectral', 'Spectral', 'Spectral'),
|
||||
],
|
||||
name="Aberration type", description="Aberration type", default='Simple', update=assets.invalidate_shader_cache)
|
||||
arm_chromatic_aberration_strength: FloatProperty(name="Strength", default=2.00, update=assets.invalidate_shader_cache)
|
||||
arm_chromatic_aberration_samples: IntProperty(name="Samples", default=32, min=8, update=assets.invalidate_shader_cache)
|
||||
# Compositor
|
||||
arm_letterbox: BoolProperty(name="Letterbox", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_letterbox_size: FloatProperty(name="Size", default=0.1, update=assets.invalidate_shader_cache)
|
||||
|
@ -466,6 +474,12 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
('Uncharted', 'Uncharted', 'Uncharted')],
|
||||
name='Tonemap', description='Tonemapping operator', default='Filmic', update=assets.invalidate_shader_cache)
|
||||
arm_lens_texture: StringProperty(name="Lens Texture", default="")
|
||||
arm_lens_texture_masking: BoolProperty(name="Luminance Masking", description="Luminance masking", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_lens_texture_masking_centerMinClip : FloatProperty(name="Center Min Clip", default=0.5, update=assets.invalidate_shader_cache)
|
||||
arm_lens_texture_masking_centerMaxClip : FloatProperty(name="Center Max Clip", default=0.1, update=assets.invalidate_shader_cache)
|
||||
arm_lens_texture_masking_luminanceMax : FloatProperty(name="Luminance Min", default=0.1, update=assets.invalidate_shader_cache)
|
||||
arm_lens_texture_masking_luminanceMin : FloatProperty(name="Luminance Max", default=2.5, update=assets.invalidate_shader_cache)
|
||||
arm_lens_texture_masking_brightnessExp : FloatProperty(name="Brightness Exponent", default=2.0, update=assets.invalidate_shader_cache)
|
||||
arm_fisheye: BoolProperty(name="Fish Eye", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_vignette: BoolProperty(name="Vignette", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_vignette_strength: FloatProperty(name="Strength", default=0.7, update=assets.invalidate_shader_cache)
|
||||
|
|
|
@ -976,6 +976,14 @@ class ARM_PT_RenderPathPostProcessPanel(bpy.types.Panel):
|
|||
col.prop(rpdat, 'arm_volumetric_light_air_color')
|
||||
col.prop(rpdat, 'arm_volumetric_light_air_turbidity')
|
||||
col.prop(rpdat, 'arm_volumetric_light_steps')
|
||||
layout.separator()
|
||||
layout.prop(rpdat, "rp_chromatic_aberration")
|
||||
col = layout.column()
|
||||
col.enabled = rpdat.rp_chromatic_aberration
|
||||
col.prop(rpdat, 'arm_chromatic_aberration_type')
|
||||
col.prop(rpdat, 'arm_chromatic_aberration_strength')
|
||||
if rpdat.arm_chromatic_aberration_type == "Spectral":
|
||||
col.prop(rpdat, 'arm_chromatic_aberration_samples')
|
||||
|
||||
class ARM_PT_RenderPathCompositorPanel(bpy.types.Panel):
|
||||
bl_label = "Compositor"
|
||||
|
@ -1034,6 +1042,14 @@ class ARM_PT_RenderPathCompositorPanel(bpy.types.Panel):
|
|||
col.prop(rpdat, 'arm_autoexposure_strength', text='Strength')
|
||||
col.prop(rpdat, 'arm_autoexposure_speed', text='Speed')
|
||||
layout.prop(rpdat, 'arm_lens_texture')
|
||||
if rpdat.arm_lens_texture != "":
|
||||
layout.prop(rpdat, 'arm_lens_texture_masking')
|
||||
if rpdat.arm_lens_texture_masking:
|
||||
layout.prop(rpdat, 'arm_lens_texture_masking_centerMinClip')
|
||||
layout.prop(rpdat, 'arm_lens_texture_masking_centerMaxClip')
|
||||
layout.prop(rpdat, 'arm_lens_texture_masking_luminanceMin')
|
||||
layout.prop(rpdat, 'arm_lens_texture_masking_luminanceMax')
|
||||
layout.prop(rpdat, 'arm_lens_texture_masking_brightnessExp')
|
||||
layout.prop(rpdat, 'arm_lut_texture')
|
||||
|
||||
class ARM_PT_BakePanel(bpy.types.Panel):
|
||||
|
|
|
@ -554,6 +554,30 @@ const float autoExposureSpeed = """ + str(rpdat.arm_autoexposure_speed) + """;
|
|||
"""const float compoFogAmountA = """ + str(round(rpdat.arm_fog_amounta * 100) / 100) + """;
|
||||
const float compoFogAmountB = """ + str(round(rpdat.arm_fog_amountb * 100) / 100) + """;
|
||||
const vec3 compoFogColor = vec3(""" + str(round(rpdat.arm_fog_color[0] * 100) / 100) + """, """ + str(round(rpdat.arm_fog_color[1] * 100) / 100) + """, """ + str(round(rpdat.arm_fog_color[2] * 100) / 100) + """);
|
||||
""")
|
||||
|
||||
if rpdat.arm_lens_texture_masking:
|
||||
f.write(
|
||||
"""const float compoCenterMinClip = """ + str(round(rpdat.arm_lens_texture_masking_centerMinClip * 100) / 100) + """;
|
||||
const float compoCenterMaxClip = """ + str(round(rpdat.arm_lens_texture_masking_centerMaxClip * 100) / 100) + """;
|
||||
const float compoLuminanceMin = """ + str(round(rpdat.arm_lens_texture_masking_luminanceMin * 100) / 100) + """;
|
||||
const float compoLuminanceMax = """ + str(round(rpdat.arm_lens_texture_masking_luminanceMax * 100) / 100) + """;
|
||||
const float compoBrightnessExponent = """ + str(round(rpdat.arm_lens_texture_masking_brightnessExp * 100) / 100) + """;
|
||||
""")
|
||||
|
||||
if rpdat.rp_chromatic_aberration:
|
||||
f.write(
|
||||
"""const float compoChromaticStrength = """ + str(round(rpdat.arm_chromatic_aberration_strength * 100) / 100) + """;
|
||||
const int compoChromaticSamples = """ + str(rpdat.arm_chromatic_aberration_samples) + """;
|
||||
""")
|
||||
|
||||
if rpdat.arm_chromatic_aberration_type == "Spectral":
|
||||
f.write(
|
||||
"""const int compoChromaticType = """ + str(1) + """;
|
||||
""")
|
||||
else:
|
||||
f.write(
|
||||
"""const int compoChromaticType = """ + str(0) + """;
|
||||
""")
|
||||
|
||||
focus_distance = 0.0 # TODO: deprecated
|
||||
|
|
Loading…
Reference in a new issue