Skip to content

Instantly share code, notes, and snippets.

@thomashollier
Last active February 10, 2024 02:46
Show Gist options
  • Save thomashollier/ca709de4700bba2b7d49b0fb92c31d21 to your computer and use it in GitHub Desktop.
Save thomashollier/ca709de4700bba2b7d49b0fb92c31d21 to your computer and use it in GitHub Desktop.
A procedural jerusalem stone texture generator with controls on size variations, grout width and corner roundness
############### USER PARAMETERS ######################
$frequency = 1; # 1.0, 4
$irregularity = 0.075; # 0, 1
$cornerSharpness = 30; # 1,50
$groutWidth = 0.05; # 0,.5
$groutSharpness = 0.5; # 0,1
$numberOfRows = 20; # 10,30
$rowSizeVariation = 0; #0 , 1
$minNumberOfBricks = 10; #5,20
$maxNumberOfBricks = 10; #5, 20
$brickSizeVariation = 0; #0,1
$brickOffsetVariation = 0.5; # 0, 1
##### END OF USER PARAMETERS
############### OVERALL FIELD MODULATION #############
$noiseBigU = fbm([$u*12, $v*12,1],6,2,.75);
$u = $u + $noiseBigU*$irregularity/$numberOfRows;
$noiseBigV = fbm([111+$u*8, 111+$v*8,0],6,2,.75);
$v = $v + $noiseBigV*$irregularity/$numberOfRows;
$u *= $frequency;
$v *= $frequency;
############### ROW CREATION #########################
$vNum = $numberOfRows;
# variation in width of horizontal bands
$vVar = $rowSizeVariation;
# horizontal noise
$vNoise = noise($v*$vNum)*2-1;
$vNoise = $vNoise * $vVar;
# v2 is the noisy horizontal grad
$v2 = $v*$vNum+$vNoise;
# give each row an index
$rowIndex = floor($v2);
#give each row a random value
$rowRandom = hash($rowIndex);
############### BRICK CREATION #######################
# min and max number of bricks per row
$uNumMin = $minNumberOfBricks;
$uNumMax = $maxNumberOfBricks;
$uNum = compress($rowRandom, $uNumMin, $uNumMax);
#
$uVar = $brickSizeVariation;
$uNoise = noise($u* $uNum * .5)*2-1;
$uNoise = $uNoise * $uVar;
$u2 = ($u * $uNum + $uNoise) + ($rowIndex) * .5 + ($rowRandom-.5) * $brickOffsetVariation;
$colIndex = floor($u2);
$brickIndex = $rowIndex * $uNumMax + $colIndex;
$brickHash = hash($brickIndex);
############### BRICK PROFILE ########################
$v2Ramp = fmod($v2,1)-.5;
$u2Ramp = fmod($u2,1)-.5;
# super ellipse
$e = $cornerSharpness;
$vx = abs($u2Ramp);
$vy = abs($v2Ramp);
$vxx = $vx;
$vyy = $vy;
if ($vyy > $vxx) {
$vxx = $vy;
$vyy = $vx;
}
$vxx = e * log($vxx);
$vyy = e * log($vyy);
$logSumExp = $vxx + log(1.0 + exp($vyy - $vxx));
$logSumExp = exp($logSumExp/$e) * 1.9;
$groutStart = 1-$groutWidth*2;
$groutEnd = $groutStart + $groutWidth * (1-$groutSharpness);
$grout = gaussstep($logSumExp,$groutStart,$groutEnd);
$out = $brickHash * (1-$grout);
$color = [$out,$out,$out];
$color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment