@@ -37,25 +37,6 @@ float noisePattern(float2 uv) {
3737 return mix (a, b, u.x ) + (c - a) * u.y * (1.0 - u.x ) + (d - b) * u.x * u.y ;
3838}
3939
40- // Checker pattern function to create a diamond (lozenge) effect
41- float checkerPattern (float2 uv, float scale, float degreesAngle) {
42- float radiansAngle = degreesAngle * M_PI_F / 180 ;
43-
44- // Scale the UV coordinates
45- uv *= scale;
46-
47- // Rotate the UV coordinates by the specified angle
48- float cosAngle = cos (radiansAngle);
49- float sinAngle = sin (radiansAngle);
50- float2 rotatedUV = float2 (
51- cosAngle * uv.x - sinAngle * uv.y ,
52- sinAngle * uv.x + cosAngle * uv.y
53- );
54-
55- // Determine if the current tile is black or white
56- return fmod (floor (rotatedUV.x ) + floor (rotatedUV.y ), 2.0 ) == 0.0 ? 0.0 : 1.0 ;
57- }
58-
5940// Function to mix colors with more intensity on lighter colors
6041half4 lightnessMix (half4 baseColor, half4 overlayColor, float intensity, float baselineFactor) {
6142 // Calculate brightness of the base color
@@ -92,9 +73,9 @@ float squarePattern(float2 uv, float scale, float degreesAngle) {
9273 float cosAngle = cos (radiansAngle);
9374 float sinAngle = sin (radiansAngle);
9475 float2 rotatedUV = float2 (
95- cosAngle * uv.x - sinAngle * uv.y ,
96- sinAngle * uv.x + cosAngle * uv.y
97- );
76+ cosAngle * uv.x - sinAngle * uv.y ,
77+ sinAngle * uv.x + cosAngle * uv.y
78+ );
9879
9980 // Determine if the current tile is black or white
10081 return fmod (floor (rotatedUV.x ) + floor (rotatedUV.y ), 2.0 ) == 0.0 ? 0.0 : 1.0 ;
@@ -116,17 +97,34 @@ float stickerPattern(int option, float2 uv, float scale) {
11697 }
11798}
11899
100+ [[ stitchable ]] half4 foil (
101+ float2 position,
102+ half4 color,
103+ float2 offset,
104+ float2 size,
105+ float scale,
106+ float intensity,
107+ float contrast,
108+ float blendFactor,
109+ float checkerScale,
110+ float checkerIntensity,
111+ float noiseScale,
112+ float noiseIntensity,
113+ float patternType
114+ ) {
115+ // Calculate aspect ratio (width / height)
116+ float aspectRatio = size.x / size.y ;
119117
120- [[ stitchable ]] half4 foil (float2 position, half4 color, float2 offset, float2 size, float scale, float intensity, float contrast, float blendFactor, float checkerScale, float checkerIntensity, float noiseScale, float noiseIntensity, float patternType) {
121118 // Normalize the offset by dividing by size to keep it consistent across different view sizes
122119 float2 normalizedOffset = (offset + size * 250 ) / (size * scale) * 0.01 ;
120+ float2 normalizedPosition = float2 (position.x * aspectRatio, position.y );
123121
124122 // Adjust UV coordinates by adding the normalized offset, then apply scaling
125123 float2 uv = (position / (size * scale)) + normalizedOffset;
126124
127125 // Scale the noise based on the normalized position and noiseScale parameter
128126 float gradientNoise = random (position) * 0.1 ;
129- float pattern = stickerPattern (patternType, position / size * checkerScale, checkerScale);
127+ float pattern = stickerPattern (patternType, normalizedPosition / size * checkerScale, checkerScale);
130128 float noise = noisePattern (position / size * noiseScale);
131129
132130 // Calculate less saturated color shifts for a metallic effect
0 commit comments