Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ===================================================================================
- // HUEING
- // ===================================================================================
- //Utility Functions
- float3 ExpandHSL(in float3 HSL)
- {
- //float3 outputVal = inVal * (maxVal - minVal) + minVal;
- float3 expanded = HSL;
- expanded.r = (HSL.r * (.706 - .3137)) + .3137; //reexpand hue
- expanded.r -= .41176; //offset hue
- expanded.g = (HSL.g * .5882);
- expanded.b = (HSL.b * .70588);
- return expanded;
- }
- float3 AdjustLightness(in float3 HSL, float brightness, float contrast) //Adjust the lightness of the HSL
- {
- HSL.b = pow(HSL.b, contrast) * contrast;
- HSL.b = brightness + ((1 - brightness) * HSL.b);
- return HSL;
- }
- float OffsetHue(in float hue, float hueOffset)
- {
- float H = frac(hue + hueOffset);
- return H;
- }
- float OffsetSaturation(in float saturation, float satOffset)
- {
- float S = saturation;
- S = pow(S, satOffset);
- S = S * (1 - satOffset);
- S = saturate(S);
- return S;
- }
- float3 OffsetHSL(in float3 HSL, float hueOffset, float satOffset)
- {
- float H = OffsetHue(HSL.x, hueOffset);
- float S = OffsetSaturation(HSL.y, satOffset);
- return float3(H, S, HSL.z);
- }
- float3 ConvertHSLToRGB(in float3 HSL)
- {
- const float fOneThird = 0.333333333f;
- const float fTwoThirds = 0.666666666f;
- float3 color;
- float temp1, temp2;
- float H = HSL.r;
- float S = HSL.g;
- float L = HSL.b;
- //if (S == 0)
- // return float3(L, L, L);
- float LtimesS = L*S;
- if (L<0.5f)
- temp2 = L + LtimesS;
- else
- temp2 = L + S - LtimesS;
- temp1 = 2.0f*L-temp2;
- float3 temp3 = frac(float3(H+fOneThird, H, H-fOneThird));
- float3 temp3Times6 = 6.0f * temp3;
- float3 temp3Times2 = 2.0f * temp3;
- float3 temp3Times1point5 = 1.5f * temp3;
- float3 firstEquation = temp1+(temp2-temp1)*6.0f*temp3;
- float3 secondEquation = temp1+(temp2-temp1)*(fTwoThirds-temp3)*6.0f;
- if (temp3Times6.r < 1.0f)
- color.r = firstEquation.r;
- else if (temp3Times2.r < 1.0f)
- color.r = temp2;
- else if (temp3Times1point5.r < 1.0f)
- color.r = secondEquation.r;
- else
- color.r = temp1;
- if (temp3Times6.g < 1.0f)
- color.g = firstEquation.g;
- else if (temp3Times2.g < 1.0f)
- color.g = temp2;
- else if (temp3Times1point5.g < 1.0f)
- color.g = secondEquation.g;
- else
- color.g = temp1;
- if (temp3Times6.b < 1.0f)
- color.b = firstEquation.b;
- else if (temp3Times2.b < 1.0f)
- color.b = temp2;
- else if (temp3Times1point5.b < 1.0f)
- color.b = secondEquation.b;
- else
- color.b = temp1;
- return color;
- }
- float3 ManipulateHSL(in float3 HSL, float4 palette)
- {
- HSL = ExpandHSL(HSL);
- HSL = AdjustLightness(HSL, palette.z, palette.w);
- HSL = OffsetHSL(HSL.rgb, palette.x, palette.y);
- return HSL;
- }
- float ManipulateAO(in float ao, float brightness, float contrast)
- {
- brightness += 1;
- //brightness + ((1 - brightness) * HSL.b);
- float ret = ao * (brightness + (1 - brightness) * ao);
- return saturate(ret);
- }
- void HuePixel(
- in float4 diffuseMapValue,
- in float4 specularMapValue,
- float4 paletteMaskMapValue,
- float4 paletteMapValue,
- out float3 fragmentDiffuseColor,
- out float4 fragmentSpecularColor
- )
- {
- fragmentDiffuseColor = diffuseMapValue.rgb;
- fragmentSpecularColor = specularMapValue;
- float paletteMaskSum = paletteMaskMapValue.x + paletteMaskMapValue.y;
- // Only use the palette that applies
- float4 palette;
- float3 chosenSpecColor, chosenMetallicSpecColor;
- if (paletteMaskMapValue.x < paletteMaskMapValue.y)
- {
- palette = palette2;
- chosenSpecColor = palette2Specular.rgb;
- chosenMetallicSpecColor = palette2MetallicSpecular.rgb;
- }
- else
- {
- palette = palette1;
- chosenSpecColor = palette1Specular.rgb;
- chosenMetallicSpecColor = palette1MetallicSpecular.rgb;
- }
- // Get the palette map, apply the deltas, and convert it to RGB
- float3 HSL = ManipulateHSL(float3(paletteMapValue.g, paletteMapValue.b, paletteMapValue.a), palette);
- float ambientOcclusion = ManipulateAO(paletteMapValue.r, palette.z, palette.w);
- HSL.z *= ambientOcclusion;
- float3 RGB = ConvertHSLToRGB(HSL);
- //Blend the result into the original diffuse
- fragmentDiffuseColor = lerp(diffuseMapValue.rgb, RGB.rgb, paletteMaskSum);
- // Determine the hue specular color
- float3 hueSpecColor;
- const float3 white = float3(1,1,1);
- float metallicMask = paletteMaskMapValue.b;
- //1.0 uses chosenMetallicSpecColor, .5 uses white, 0.0 uses chosenSpecColor
- if( metallicMask > .5 )
- {
- hueSpecColor = lerp(white, chosenMetallicSpecColor, (metallicMask - 0.5) * 2);
- }
- else
- {
- hueSpecColor = lerp(chosenSpecColor, white, metallicMask * 2);
- }
- hueSpecColor *= specularMapValue.r;
- fragmentSpecularColor.rgb = lerp(fragmentSpecularColor.rgb, hueSpecColor, paletteMaskSum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement