Skip to content

Commit 4ac713c

Browse files
authored
Update AfflictionLib.glsllib
1 parent ad5a5ec commit 4ac713c

File tree

1 file changed

+5
-58
lines changed

1 file changed

+5
-58
lines changed

jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/AfflictionLib.glsllib

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
uniform sampler2D m_AfflictionAlphaMap;
1111
#endif
1212
#ifdef AFFLICTIONALBEDOMAP
13-
uniform sampler2D m_SplatAlbedoMap ;
13+
uniform sampler2D m_SplatAlbedoMap;
1414
#endif
1515
#ifdef AFFLICTIONNORMALMAP
16-
uniform sampler2D m_SplatNormalMap ;
16+
uniform sampler2D m_SplatNormalMap;
1717
#endif
1818
#ifdef AFFLICTIONROUGHNESSMETALLICMAP
1919
uniform sampler2D m_SplatRoughnessMetallicMap;
@@ -30,33 +30,24 @@
3030
uniform vec3 m_TileLocation;
3131
#endif
3232

33-
3433
uniform int m_AfflictionSplatScale;
3534
uniform float m_AfflictionRoughnessValue;
3635
uniform float m_AfflictionMetallicValue;
3736
uniform float m_AfflictionEmissiveValue;
3837
uniform vec4 m_AfflictionEmissiveColor;
3938

40-
41-
42-
4339
vec4 afflictionVector;
4440
float noiseHash;
4541
float livelinessValue;
4642
float afflictionValue;
4743
int afflictionMode = 1;
4844

49-
50-
//temporarily here, move triplanar import + define back to .frag shader soon:
51-
5245
vec4 desaturate(vec4 albedo, float deathVar){
53-
5446
vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), albedo.rgb));
5547
albedo = vec4(mix(albedo.rgb, gray, deathVar), 0.0);
5648

5749
return albedo;
5850
}
59-
6051
vec3 alterLiveliness(vec3 color, float liveVal, int mode){
6152

6253
float deathVar = (1.0 - (liveVal));
@@ -73,32 +64,26 @@
7364
color.g -= color.g*hueVar;
7465
color.b -= color.b*hueVar * 5.0 ;
7566

76-
7767
color = desaturate(vec4(color, 1.0), deathVar).rgb;
7868

7969
}
8070

81-
82-
8371
return color;
8472

8573
}
8674

8775

8876
vec3 alterLiveliness(vec3 color, float livelinessValue){
8977

90-
9178
float deathVar = (1.0 - (livelinessValue));
9279

9380
float hueVar = (deathVar) * 0.34;
9481
color.r += color.r*hueVar * 1.8;
9582
color.g -= color.g*hueVar;
9683
color.b -= color.b*hueVar*5.0 ;
9784

98-
9985
color = desaturate(vec4(color, 1.0), deathVar).rgb;
10086

101-
10287
return color;
10388
}
10489

@@ -135,21 +120,17 @@
135120

136121
float deathVar = 1.0 - livelinessValue;
137122

138-
139123
float hueVar = (deathVar);
140124
albedo.r += albedo.r*hueVar * 1.2;
141125
albedo.g += albedo.g*hueVar;
142126
albedo.b -= albedo.b*hueVar*3.14 ;
143127

144128
albedo = desaturate(albedo, deathVar * 1.7);
145129

146-
147-
148130
return albedo;
149131
}
150132

151133
vec3 desaturateVec(vec3 albedo, float deathVar){
152-
153134
vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), albedo.rgb));
154135
albedo = mix(albedo, gray, deathVar);
155136

@@ -160,26 +141,20 @@
160141

161142
float deathVar = 1.0 - livelinessValue;
162143

163-
164144
float hueVar = (deathVar);
165145
albedo.r += albedo.r*hueVar * 1.2;
166146
albedo.g += albedo.g*hueVar;
167147
albedo.b -= albedo.b*hueVar*3.14 ;
168148

169149
albedo = desaturateVec(albedo, deathVar * 1.7);
170150

171-
172-
173151
return albedo;
174152
}
175153

176-
177-
178154
//AFFLICTION METHODS
179155

180156
//adjusts the affliction value for the best visual representation (since 0.0 - 1.0 is not as visually linear as it is numerically)
181157
float getAdjustedAfflictionVar(float afflictionVar){
182-
183158
float adjustedVar = afflictionVar;
184159
if(afflictionVar > 0.02){
185160
adjustedVar = mix(0.02, 0.53, afflictionVar);
@@ -192,19 +167,15 @@
192167
}
193168

194169
float getAfflictionEdgeTaper(float noiseVar, float afflictionVar){
195-
196170
float amt = noiseVar - (0.4 * afflictionVar) - .04;
197171

198172
if(amt <= 0.05){
199173
amt = 0.05;
200174
}
201-
202-
203175
return amt;
204176
}
205177

206178
vec4 alterAfflictionColor(float afflictionVar, vec4 albedo, vec4 afflictionAlbedo, float noiseVar){
207-
208179
float originalAlpha = albedo.a;
209180

210181
float edgeTaper = getAfflictionEdgeTaper(noiseVar, afflictionVar);
@@ -217,11 +188,9 @@
217188
float edgeDiff = noiseVar - afflictionVar;
218189
edgeDiff = edgeDiff / afflictionVar;
219190

220-
221191
albedo.rgba = mix(afflictionAlbedo.rgba, albedo.rgba, edgeDiff);
222192
}
223193
else{
224-
225194
albedo.rgba = mix(albedo.rgba, afflictionAlbedo.rgba, afflictionVar);
226195
}
227196

@@ -230,24 +199,19 @@
230199

231200
return albedo;
232201
}
233-
vec4 alterAfflictionGlow(float afflictionVar, vec4 emissive, vec4 afflictionGlowColor, float noiseVar){
234-
235-
202+
vec4 alterAfflictionGlow(float afflictionVar, vec4 emissive, vec4 afflictionGlowColor, float noiseVar){
236203
emissive = mix(emissive, afflictionGlowColor, afflictionVar);
237204

238205
return emissive;
239206
}
240207

241208
float alterAfflictionEmissiveIntensity(float afflictionVar, float emissiveIntensity, float afflictionEmissiveIntensity, float noiseVar){
242-
243-
244209
emissiveIntensity = mix(emissiveIntensity, afflictionEmissiveIntensity, afflictionVar);
245210

246211
return emissiveIntensity;
247212
}
248213

249214
vec3 alterAfflictionNormals(float afflictionVar, vec3 normal, vec3 afflictionNormal, float noiseVar){
250-
251215
vec3 originalNorm = normal;
252216

253217
float edgeTaper = getAfflictionEdgeTaper(noiseVar, afflictionVar);
@@ -269,11 +233,7 @@
269233
}
270234

271235
vec3 alterAfflictionNormalsForTerrain(float afflictionVar, vec3 normal, vec3 afflictionNormal, float noiseVar, vec3 worldNorm){
272-
273-
274236
float edgeTaper = getAfflictionEdgeTaper(noiseVar, afflictionVar);
275-
276-
277237
vec3 blendedNormal = normal;
278238

279239
float blendValue = afflictionVar;
@@ -294,7 +254,6 @@
294254
blendAmt = min(1.0, blendAmt);
295255

296256
blendValue = blendAmt;
297-
298257
}
299258

300259
afflictionNormal = calculateTangentsAndApplyToNormals(afflictionNormal, worldNorm);
@@ -324,8 +283,6 @@
324283
}
325284

326285
float alterAfflictionRoughness(float afflictionVar, float originalRoughness, float afflictionRoughness, float noiseVar){
327-
328-
329286
float edgeTaper = getAfflictionEdgeTaper(noiseVar, afflictionVar);
330287
if(afflictionVar >= noiseVar){
331288
originalRoughness = afflictionRoughness;
@@ -345,8 +302,6 @@
345302
}
346303

347304
float alterAfflictionMetallic(float afflictionVar, float originalMetallic, float afflictionMetallic, float noiseVar){
348-
349-
350305
float edgeTaper = getAfflictionEdgeTaper(noiseVar, afflictionVar);
351306
if(afflictionVar >= noiseVar){
352307
originalMetallic = afflictionMetallic;
@@ -370,8 +325,7 @@
370325
void AfflictionLib_readAfflictionVector(){
371326
#ifdef AFFLICTIONTEXTURE
372327

373-
afflictionVector = vec4(1.0, 0.0, 1.0, 0.0); //r channel is sturation, g channel is affliction splat texture intensity, b and a unused (might use b channel for wetness eventually)
374-
328+
afflictionVector = vec4(1.0, 0.0, 1.0, 0.0); //r channel is saturation, g channel is affliction splat texture intensity, b and a unused (might use b channel for wetness eventually)
375329

376330
#ifdef TILELOCATION
377331
//subterrains that are not centred in tile or equal to tile width in total size need to have m_TileWidth pre-set. (tileWidth is the x,z dimesnions that the AfflictionAlphaMap represents)..
@@ -404,10 +358,7 @@
404358

405359
TriPlanarUtils_calculateBlending(surface.geometryNormal);
406360

407-
408-
#ifdef AFFLICTIONTEXTURE
409-
410-
361+
#ifdef AFFLICTIONTEXTURE
411362
vec4 afflictionAlbedo;
412363

413364
float newAfflictionScale = m_AfflictionSplatScale;
@@ -448,7 +399,6 @@
448399
float afflictionRoughness = m_AfflictionRoughnessValue;
449400
float afflictionAo = 1.0;
450401

451-
452402
vec4 afflictionEmissive = m_AfflictionEmissiveColor;
453403
float afflictionEmissiveIntensity = m_AfflictionEmissiveValue;
454404

@@ -503,10 +453,7 @@
503453
}
504454

505455
#endif
506-
507-
508456
}
509-
510457
#endif
511458

512459

0 commit comments

Comments
 (0)