Files
cruiseSimulator/Assets/BigShipTycoon/Resources/TycoonTexturing.cginc

89 lines
2.8 KiB
HLSL

#ifndef TYCOON_TEXTURING
#define TYCOON_TEXTURING
float TycoonCell(float2 cell)
{
float3 p = frac(cell.xyx * .1031);
p += dot(p, p.yzx + 33.33);
return frac((p.x + p.y) * p.z);
}
float TycoonDetail(float phase)
{
return 1 - smoothstep(.24, .82, fwidth(phase));
}
float TycoonDetail2(float2 phase)
{
float2 spread = fwidth(phase);
return 1 - smoothstep(.22, .75, max(spread.x, spread.y));
}
float TycoonJoint(float phase, float halfWidth)
{
float pixel = max(.0002, fwidth(phase));
float distance = abs(frac(phase + .5) - .5);
float core = max(0, halfWidth - pixel * .42);
float shoulder = halfWidth + pixel * .58;
float coverage = saturate((2 * halfWidth + .003) / pixel);
return (1 - smoothstep(core, shoulder, distance)) * coverage * (1 - smoothstep(.23, .77, pixel));
}
float2 TycoonPlane(float3 p, float3 normal)
{
float3 axis = abs(normal);
if (axis.y >= max(axis.x, axis.z))
return p.xz;
return axis.z >= axis.x ? p.xy : p.zy;
}
// Offset narrow strips by row to break straight cross joints without introducing mip shimmer.
float TycoonPanel(float2 uv, float2 piecesPerMeter, float stagger, float jointWidth, out float variation)
{
float2 cell = uv * piecesPerMeter;
float row = floor(cell.y);
float x = cell.x + frac(row * stagger);
variation = (TycoonCell(float2(floor(x), row)) - .5) * TycoonDetail2(cell);
return max(TycoonJoint(x, jointWidth * piecesPerMeter.x), TycoonJoint(cell.y, jointWidth * piecesPerMeter.y));
}
float TycoonWeave(float2 uv, float2 threadsPerMeter)
{
float2 thread = uv * threadsPerMeter;
float2 fibre = cos(thread * 6.283185);
return (fibre.x * .39 + fibre.y * .37 + fibre.x * fibre.y * .24) * TycoonDetail2(thread);
}
float TycoonGrain(float2 uv, float frequency)
{
float ribbon = uv.y * frequency + sin(uv.x * 2.78 + uv.y * 27.1) * .14
+ sin(uv.x * .92 - uv.y * 12.7) * .15;
float main = sin(ribbon * 6.283185) * TycoonDetail(uv.y * frequency);
float fine = sin((ribbon * 2.17 - uv.x * .13) * 6.283185) * TycoonDetail(uv.y * frequency * 2.17);
return main * .71 + fine * .29;
}
float TycoonVein(float2 uv)
{
float phase = uv.x * .92 + uv.y * .62 + sin(uv.y * 2.39) * .28
+ sin(uv.x * 5.4 - uv.y * 2.7) * .071;
float quartz = TycoonJoint(phase, .037);
float fine = TycoonJoint(phase * 2.69 + .263 + .12 * sin(uv.y * 9), .016);
return quartz * .71 + fine * .29;
}
float TycoonStipple(float2 uv, float grainsPerMeter)
{
float2 grit = uv * grainsPerMeter;
return (TycoonCell(floor(grit)) - .5) * TycoonDetail2(grit);
}
float3 TycoonHighlightRollOff(float3 color)
{
// Preserve detail on white enamel, limestone, and polished edges before the framebuffer clips.
float3 excess = max(0, color - .79);
return saturate(min(color, .79) + excess / (1 + excess * 4.76));
}
#endif