It is currently Fri Jun 19, 2026 12:11 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: [Plugin Request] Palette Mask
PostPosted: Sat Apr 02, 2016 11:43 pm  (#1) 
Offline
New Member

Joined: Apr 02, 2016
Posts: 1
Hi, I don't know if anyone here is taking plugin requests, but if they are, I have one.

So... I need a 'Palette Mask' plugin, for textures. I tried learning how to make a plugin, but I couldn't, and I really only want to make this one plugin.
The idea is simple, but the actual creation, I assume not so much.

Basically, how it works is:
There's a little UI, you pick two colors, a primary (palette1), and a secondary (palette2).
You open a file browser, and choose a 'Palette Mask' image.
You open another file browser, and choose a 'Palette Map' image

If the palette mask is black, then the diffuse texture (base image) is displayed.
If it's red, then the palette1 color mixed with the palette map texture is displayed.
If it's green, then the palette2 color mixed with the palette map texture is displayed.
If it's blue, then this pixel has a metallic specular color
The alpha value of the palette mask is not used.
Any other colors (cyan, purple etc.) are just combinations of these cases.

If you are interested in how the palette1/palette2 colors are mixed with the palette map, here's some HLSL shader code:

// ===================================================================================
// 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);

}



I am willing to pay for this plugin, if it works correctly.
If you're interested in my request, please reply, and I will give you a few sample textures to work with.



Thank you,
-Nen


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group