Skip to content

Commit

Permalink
Rebase for Vignette and ColorDispersion
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-cast committed Dec 21, 2017
1 parent f4685ac commit 1b86125
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Shader/ColorGrading.fxsub
Expand Up @@ -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;
Expand Down
56 changes: 53 additions & 3 deletions 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,
Expand All @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions Shader/ibl.fxsub
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion ray.conf
Expand Up @@ -117,4 +117,10 @@
// 3 : SMAAx1-high
// 4 : SMAAx2-medium
// 5 : SMAAx2-high
#define AA_QUALITY 1
#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
3 changes: 3 additions & 0 deletions ray.fx
Expand Up @@ -32,6 +32,9 @@ float mFocalRegionP : CONTROLOBJECT<string name="ray_controller.pmx"; string ite
float mFocalRegionM : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "FocalRegion-";>;
float mMeasureMode : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "MeasureMode";>;
float mTestMode : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "TestMode";>;
float mVignette : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "Vignette";>;
float mDispersion : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "Dispersion";>;
float mDispersionRadius : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "DispersionRadius";>;
float mBloomThresholdP : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "BloomThreshold";>;
float mBloomRadiusP : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "BloomRadius+";>;
float mBloomRadiusM : CONTROLOBJECT<string name="ray_controller.pmx"; string item = "BloomRadius-";>;
Expand Down
Binary file modified ray_controller.pmx
Binary file not shown.

0 comments on commit 1b86125

Please sign in to comment.