__DEVICE__ float apply_linear_contrast(float in, float contrast, float pivot) { float out; out = (in - pivot) * contrast + pivot; return out; } __DEVICE__ float apply_rolling_contrast(float in, float contrast, float pivot) { float out; float zerocheck = 1.f; if (in <= pivot) { out = _powf((in / pivot), contrast) * pivot; } else { in = 1 - in; pivot = 1 - pivot; if (in < 0.f) { zerocheck = -1.f; } out = (_powf((in / pivot), contrast) * pivot) * zerocheck; out = 1 - out; } return out; } __DEVICE__ float3 apply_highlight_split(float3 in, float strength, float color_mix) { float3 out = in; float red_strength = ((1 - color_mix) * strength) + 1.f; float green_strength = (color_mix * strength) + 1.f; out.x = in.x * red_strength; out.y = in.y * green_strength; return out; } __DEVICE__ float3 apply_shadow_split(float3 in, float strength, float color_mix) { float3 out = in; in.x = (1 - in.x); in.y = (1 - in.y); in.z = (1 - in.z); float green_strength = (color_mix * strength) + 1.f; float blue_strength = ((1 - color_mix) * strength) + 1.f; out.x = in.x; out.y = in.y / green_strength; out.z = in.z / blue_strength; out.x = (1 - out.x); out.y = (1 - out.y); out.z = (1 - out.z); return out; } DEFINE_UI_PARAMS(contrast, Contrast, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 2.0, 0.1) DEFINE_UI_PARAMS(pivot, Pivot, DCTLUI_SLIDER_FLOAT, .435, 0.0, 1.0, 0.1) DEFINE_UI_PARAMS(contrast_type, Contrast Type, DCTLUI_COMBO_BOX, 0, { linear, S_curve }, { Linear, S-Curve }) DEFINE_UI_PARAMS(split_strength, Split Tone Strength, DCTLUI_SLIDER_FLOAT, 0.0, 0.0, 1.0, .1) DEFINE_UI_PARAMS(split_shadow_color_mix, Blue/Green Shadows, DCTLUI_SLIDER_FLOAT, .5, 0.0, 1.0, .1) DEFINE_UI_PARAMS(split_highlight_color_mix, Red/Green Highlights, DCTLUI_SLIDER_FLOAT, .5, 0.0, 1.0, .1) __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B) { float3 in = {p_R, p_G, p_B}; float3 out; if (contrast_type == linear) { out.x = apply_linear_contrast(in.x, contrast, pivot); out.y = apply_linear_contrast(in.y, contrast, pivot); out.z = apply_linear_contrast(in.z, contrast, pivot); } if (contrast_type == S_curve) { out.x = apply_rolling_contrast(in.x, contrast, pivot); out.y = apply_rolling_contrast(in.y, contrast, pivot); out.z = apply_rolling_contrast(in.z, contrast, pivot); } out = apply_shadow_split(out, split_strength, split_shadow_color_mix); out = apply_highlight_split(out, split_strength, split_highlight_color_mix); return out; }