diff --git a/Shader/ColorGrading.fxsub b/Shader/ColorGrading.fxsub index 2ff7d2e0..b1b4726e 100644 --- a/Shader/ColorGrading.fxsub +++ b/Shader/ColorGrading.fxsub @@ -15,6 +15,12 @@ float3 ColorDithering(float3 color, float2 uv) return color; } +float3 ColorVignette(float3 color, float2 coord) +{ + float L = length(coord * 2 - 1); + return color * smoothstep(mVignetteOuter - mVignette * 2, mVignetteInner - mVignette, L); +} + float3 ColorTemperature(float3 color, float kelvin) { float temp = kelvin / 100; diff --git a/Shader/PostProcessHDR.fxsub b/Shader/PostProcessHDR.fxsub index b374d829..081cf049 100644 --- a/Shader/PostProcessHDR.fxsub +++ b/Shader/PostProcessHDR.fxsub @@ -1,3 +1,52 @@ +#if POST_DISPERSION_MODE == 2 +float3 SampleSpectrum(float x) +{ + float t = 3.0 * x - 1.5; + return saturate(float3(-t, 1 - abs(t), t)); +} + +float3 ChromaticAberration(sampler source, float2 coord, float2 offset) +{ + const int samples = 8; + + float3 totalColor = 0.0; + float3 totalWeight = 0.0; + float2 delta = offset / samples; + + [unroll] + for (int i = 0; i <= samples; i++, coord += delta) + { + float3 w = SampleSpectrum(float(i) / samples); + + totalWeight += w; + totalColor += w * tex2Dlod(source, float4(coord, 0, 0)).rgb; + } + + return totalColor / totalWeight; +} +#endif + +float3 ColorDispersion(sampler source, float2 coord, float inner, float outer) +{ + const float scale = ((ViewportSize.x * 0.5) / 512); +#if POST_DISPERSION_MODE == 1 + float L = length(coord * 2 - 1); + L = 1 - smoothstep(outer, inner, L); + float2 offset = ViewportOffset2 * L * (mDispersion * 8) * scale; + float3 shift1 = tex2Dlod(source, float4(coord - offset, 0, 0)).rgb; + float3 shift2 = tex2Dlod(source, float4(coord, 0, 0)).rgb; + float3 shift3 = tex2Dlod(source, float4(coord + offset, 0, 0)).rgb; + return float3(shift1.r, shift2.g, shift3.b); +#elif POST_DISPERSION_MODE == 2 + float L = 1 - smoothstep(outer, inner, length(coord * 2 - 1)); + float2 dist = ViewportOffset2 * L * (mDispersion * 16) * scale; + float2 offset = (coord * 2 - 1.0) * dist; + return ChromaticAberration(source, coord, offset); +#else + return tex2Dlod(source, float4(coord, 0, 0)).rgb; +#endif +} + float4 HDRTonemappingVS( in float4 Position : POSITION, in float4 Texcoord : TEXCOORD, @@ -18,23 +67,24 @@ float4 HDRTonemappingVS( float4 HDRTonemappingPS(in float4 coord: TEXCOORD0, uniform sampler source) : COLOR { - float3 color = tex2Dlod(source, float4(coord.xy, 0, 0)).rgb; + float3 color = ColorDispersion(source, coord.xy, mDispersionRadius, 1.0 + mDispersionRadius); color *= coord.z; -#if HDR_BLOOM_MODE +#if HDR_BLOOM_MODE > 0 float3 bloom = tex2Dlod(BloomSamp1st, float4(coord.xy, 0, 0)).rgb; color += bloom; #endif color = ColorTemperature(color, mColorTemperature); color = ColorCorrect(color, mColorSaturation, mColorContrast, mColorGamma, mColorBalanceP, mColorBalanceM); + color = ColorVignette(color, coord.xy); color = ColorToneMapping(color); color = linear2srgb(color); color = ColorDithering(color, coord.xy); -#if AA_QUALITY +#if AA_QUALITY > 0 return float4(color, luminance(color)); #else return float4(color, 1); diff --git a/Shader/ibl.fxsub b/Shader/ibl.fxsub index 7c1cdf82..d921c575 100644 --- a/Shader/ibl.fxsub +++ b/Shader/ibl.fxsub @@ -13,14 +13,6 @@ float3 FresnelSchlickGlass(float3 N, float3 V, float smoothness, float3 specular return lerp(specular, 1.0, pow5(1 - saturate(dot(N, V))) / (40 - 39 * smoothness)); } -float FresnelSchlickSkin(float3 N, float3 V, float smoothness) -{ - const float2 c0 = float2(-1, -0.0275); - const float2 c1 = float2(1, 0.0425); - float2 r = smoothness * c0 + c1; - return min(r.x * r.x, exp2(-4.28 * abs(dot(N, V)))) * r.x + r.y; -} - float FresnelSchlickClearCoat(float nv, float smoothness, float specular) { return specular + (max(smoothness, specular) - specular) * pow5(1 - nv); diff --git a/ray.conf b/ray.conf index d753b6b4..d2939880 100644 --- a/ray.conf +++ b/ray.conf @@ -117,4 +117,10 @@ // 3 : SMAAx1-high // 4 : SMAAx2-medium // 5 : SMAAx2-high -#define AA_QUALITY 1 \ No newline at end of file +#define AA_QUALITY 1 + +// Postprocess Dispersion +// 0 : None +// 1 : Color Shift +// 2 : Chromatic Aberration // https://twitter.com/nnnnoby/status/818710634682585088 +#define POST_DISPERSION_MODE 1 \ No newline at end of file diff --git a/ray.fx b/ray.fx index 0ecb9e66..1523d010 100644 --- a/ray.fx +++ b/ray.fx @@ -32,6 +32,9 @@ float mFocalRegionP : CONTROLOBJECT; float mMeasureMode : CONTROLOBJECT; float mTestMode : CONTROLOBJECT; +float mVignette : CONTROLOBJECT; +float mDispersion : CONTROLOBJECT; +float mDispersionRadius : CONTROLOBJECT; float mBloomThresholdP : CONTROLOBJECT; float mBloomRadiusP : CONTROLOBJECT; float mBloomRadiusM : CONTROLOBJECT; diff --git a/ray_controller.pmx b/ray_controller.pmx index d5c5a0f4..87523fcd 100644 Binary files a/ray_controller.pmx and b/ray_controller.pmx differ