Skip to content

Commit a31bab0

Browse files
committed
Terasalization shader
1 parent ae3bb12 commit a31bab0

File tree

10 files changed

+53
-62
lines changed

10 files changed

+53
-62
lines changed

src/main/resources/shaders/experimental/animated.fs.glsl

Lines changed: 51 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ uniform float emiIntensity4;
4747
uniform float emiIntensity5;
4848
uniform bool useLight;
4949

50-
// Tersalziation details
51-
in vec3 fragNormal;
52-
in vec3 fragViewDir;
53-
uniform bool tera;
5450
uniform vec3 Light0_Direction;
5551
uniform vec3 Light1_Direction;
5652

@@ -77,14 +73,13 @@ float linear_fog_fade(float vertexDistance, float fogStart, float fogEnd) {
7773
return smoothstep(fogEnd, fogStart, vertexDistance);
7874
}
7975

76+
// ===== Lighting Method =====
77+
8078
vec4 minecraft_sample_lightmap(sampler2D lightMap, ivec2 uv) {
8179
return texture(lightMap, (vec2(uv) + 0.5) / 16.0);
8280
}
8381

84-
//Methods to get the color
85-
86-
//layered color method
87-
82+
// ===== Layered Color Method =====
8883
vec4 adjust(vec4 color) {
8984
return clamp(color * 2, 0, 1);
9085
}
@@ -121,8 +116,7 @@ vec4 layered(vec2 texCoord) {
121116
return vec4(base, color.a);
122117
}
123118

124-
// masked
125-
119+
// ===== Masked Color Method =====
126120
vec4 masked(vec2 texCoord) {
127121
vec4 outColor = texture(diffuse, texCoord);
128122

@@ -141,9 +135,7 @@ vec4 getColor(vec2 texCoord) {
141135
return texture(diffuse, texCoord);
142136
}
143137

144-
//Effects
145-
146-
//Cartoon
138+
// ===== Cartoon Effect =====
147139

148140
const float edgeThreshold = 0.08;
149141
const float blockSize = 0.0015;
@@ -194,8 +186,7 @@ vec4 cartoon(vec4 inColor) {
194186
return vec4(mix(color, inColor.rgb, edge), 1.0);
195187
}
196188

197-
//paradox
198-
189+
// ===== Paradox Effect =====
199190
float getParadoxIntensity() {
200191
vec2 effectTexCoord = vec2(texCoord0);
201192

@@ -215,8 +206,7 @@ vec4 paradox(vec4 color) {
215206
return mix(color, vec4(1.0), getParadoxIntensity());
216207
}
217208

218-
//galaxy
219-
209+
// ===== Galaxy Effect =====
220210
const float darkenFactor = 0.3;
221211

222212
vec4 galaxy(vec4 inColor) {
@@ -230,8 +220,7 @@ vec4 galaxy(vec4 inColor) {
230220
return mix(inColor, vec4(1.0), getParadoxIntensity());
231221
}
232222

233-
//pastel
234-
223+
// ===== Pastel Effect =====
235224
vec4 pastel(vec4 inColor) {
236225
vec2 wrappedUV = fract(texCoord0 * 5.0);
237226

@@ -247,7 +236,7 @@ vec4 pastel(vec4 inColor) {
247236
return vec4(mix(inColor.rgb, pastelColor, 0.5), inColor.a);
248237
}
249238

250-
//shadow
239+
// ===== Shadow Effect =====
251240
vec4 shadow(vec4 inColor) {
252241
float grayscale = 0.2126 * inColor.r + 0.7152 * inColor.g + 0.0722 * inColor.b;
253242

@@ -272,22 +261,9 @@ vec4 shadow(vec4 inColor) {
272261
return vec4(finalColor, inColor.a);
273262
}
274263

275-
//sketch
276-
//TODO: See if edgeDetect produces better results
264+
// ===== Sketch Effect =====
277265

278266
vec4 sketch(vec4 inColor) {
279-
// float grayscale = 0.2126 * inColor.r + 0.7152 * inColor.g + 0.0722 * inColor.b;
280-
//
281-
// float luminanceDx = dFdx(grayscale);
282-
// float luminanceDy = dFdy(grayscale);
283-
// float edgeFactor = length(vec2(luminanceDx, luminanceDy));
284-
//
285-
// float outline = 1.0 - smoothstep(0.02, 0.05, edgeFactor);
286-
// vec3 edgeColor = vec3(0.0);
287-
//
288-
// vec3 finalColor = mix(vec3(grayscale), edgeColor, outline);
289-
//
290-
// return vec4(finalColor, inColor.a);
291267

292268
const vec3 luminanceWeights = vec3(0.2126, 0.7152, 0.0722);
293269
const float subtleThreshold = 0.02; // Lower threshold for fine differences
@@ -308,7 +284,7 @@ vec4 sketch(vec4 inColor) {
308284
return vec4(value, value, value, inColor.a);
309285
}
310286

311-
//vintage
287+
// ===== Vintage Effect =====
312288
vec4 vintage(vec4 inColor) {
313289
float grayscale = 0.2126 * inColor.r + 0.7152 * inColor.g + 0.0722 * inColor.b;
314290

@@ -334,42 +310,59 @@ vec4 process(vec4 color) {
334310
return color;
335311
}
336312

337-
//////////////////////////////////////
313+
// ===== Tersaalization Effect =====
314+
315+
#define TERA_LIGHT_DIRECT vec3(0.3f, 0.9f, 0.0f)
316+
#define TERATYPE_TINT vec3(0.161, 0.502, 0.937)
317+
318+
#define FACET_RES 8.0
319+
#define SHIMMER_BANDS 5.0
320+
#define GAMMA_CORRECTION 1.4
321+
#define SHIMMER_STRENGTH 0.8
322+
#define IRIDESCENCE_STRENGTH 0.2
323+
324+
uniform bool tera;
325+
326+
in vec3 fragViewDir;
327+
in vec3 worldPos;
338328

339-
#define TERA_LIGHT_DIRECT (vec3(0.3f, 0.9f, 0.0f))
340-
#define TERATYPE_TINT (vec3(0.161, 0.502, 0.937))
341-
//Terastalization effect
342329
vec3 calculateTersaalizationEffect(
343-
vec3 baseColor,
344-
vec3 normal,
345-
vec3 viewDirection
330+
vec3 baseColor
346331
) {
347-
vec3 N = normalize(normal);
348-
vec3 V = normalize(viewDirection);
332+
vec3 N = normalize(cross(dFdx(worldPos), dFdy(worldPos)));
333+
vec3 V = normalize(fragViewDir);
349334

350-
// Lighting and view terms
335+
// Fresnel rim lighting
336+
float fresnel = pow(1.0 - max(dot(N, V), 0.0), 5.0);
337+
338+
// Directional lighting response
351339
float lightResponse = max(dot(N, TERA_LIGHT_DIRECT), 0.0);
352-
float fresnel = pow(1.0 - max(dot(N, V), 0.0), 5.0);
353340

354-
// Fake faceted look via quantized normal
355-
vec3 faceted = normalize(floor(N * 6.0) / 6.0);
341+
// Facet simulation via quantized normals
342+
vec3 faceted = normalize(floor(N * FACET_RES + 0.5) / FACET_RES);
356343
float facetResponse = pow(max(dot(faceted, V), 0.0), 6.0);
357344

358-
// Combine components
345+
// Composite shimmer signal
359346
float shimmer = fresnel * 0.5 + lightResponse * 0.3 + facetResponse * 0.8;
360-
shimmer = clamp(shimmer, 0.0, 1.0);
347+
shimmer = pow(clamp(shimmer, 0.0, 1.0), GAMMA_CORRECTION);
348+
349+
// Posterization
350+
shimmer = floor(shimmer * SHIMMER_BANDS) / SHIMMER_BANDS;
361351

362-
// Optional gamma push for highlight falloff
363-
shimmer = pow(shimmer, 1.4);
352+
// Micro-noise based on 3D direction
353+
float angleNoise = abs(sin(dot(N.xyz, vec3(12.9898, 78.233, 45.164)) * 43758.5453));
354+
shimmer += angleNoise * 0.02;
364355

365-
// Quantize the result to enforce banding
366-
shimmer = floor(shimmer * 5.0) / 5.0;
356+
// Optional iridescent variation
357+
vec3 iridescent = vec3(1.0, 0.9, 0.8) + vec3(0.05, -0.02, 0.03) * sin(shimmer * 20.0);
367358

368-
// Optional: micro-noise (disabled by default)
369-
shimmer += fract(sin(dot(N.xy, vec2(13.3, 7.7))) * 43758.5) * 0.03;
359+
// Tint variation based on light response
360+
vec3 directionalTint = mix(TERATYPE_TINT, vec3(1.0), lightResponse);
370361

371362
// Final output
372-
return baseColor + TERATYPE_TINT * shimmer * 0.8;
363+
return baseColor
364+
+ directionalTint * shimmer * SHIMMER_STRENGTH
365+
+ iridescent * shimmer * IRIDESCENCE_STRENGTH;
373366
}
374367
//////////////////////////////////////
375368

@@ -383,7 +376,7 @@ void main() {
383376
outColor.rgb *= tint;
384377

385378
if(tera) {
386-
outColor.rgb = calculateTersaalizationEffect(outColor.rgb, fragNormal, fragViewDir);
379+
outColor.rgb = calculateTersaalizationEffect(outColor.rgb);
387380
} else if (useLight) {
388381
outColor *= vertexColor;
389382
// Sample Minecraft's light level from the lightmap texture

src/main/resources/shaders/experimental/animated.vs.glsl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ out vec4 vertexColor;
1414
out vec2 texCoord0;
1515
out vec3 fragNormal;
1616
out vec3 fragViewDir;
17+
out vec3 worldPos;
1718

1819
uniform bool dynamicVertexColor;
1920

@@ -70,9 +71,6 @@ void main() {
7071
vertexDistance = fog_distance(worldSpace * modelTransform, positions, FogShape);
7172
vertexColor = getVertexColor();
7273

73-
// Transform normal into world space
74-
fragNormal = normalize(mat3(modelTransform) * inNormal);
75-
76-
// View direction (camera is at origin in view space)
7774
fragViewDir = normalize(-(viewMatrix * worldPosition).xyz);
75+
worldPos = worldPosition.xyz;
7876
}

src/main/resources/shaders/experimental/process/cartoon.lib.glsl renamed to src/main/resources/shaders/experimental/effect/cartoon.lib.glsl

File renamed without changes.

src/main/resources/shaders/experimental/process/galaxy.lib.glsl renamed to src/main/resources/shaders/experimental/effect/galaxy.lib.glsl

File renamed without changes.

src/main/resources/shaders/experimental/process/paradox.lib.glsl renamed to src/main/resources/shaders/experimental/effect/paradox.lib.glsl

File renamed without changes.

src/main/resources/shaders/experimental/process/passthrough.lib.glsl renamed to src/main/resources/shaders/experimental/effect/passthrough.lib.glsl

File renamed without changes.

src/main/resources/shaders/experimental/process/pastel.lib.glsl renamed to src/main/resources/shaders/experimental/effect/pastel.lib.glsl

File renamed without changes.

src/main/resources/shaders/experimental/process/shadow.lib.glsl renamed to src/main/resources/shaders/experimental/effect/shadow.lib.glsl

File renamed without changes.

src/main/resources/shaders/experimental/process/sketch.lib.glsl renamed to src/main/resources/shaders/experimental/effect/sketch.lib.glsl

File renamed without changes.

src/main/resources/shaders/experimental/process/vintage.lib.glsl renamed to src/main/resources/shaders/experimental/effect/vintage.lib.glsl

File renamed without changes.

0 commit comments

Comments
 (0)