Electrostat-Lab / jMonkeyBuilder

Alex's Jme3 Scene editor Maintained Version
https://hub.jmonkeyengine.org/t/editor-jmonkeybuilder/35179/1232
Apache License 2.0
6 stars 3 forks source link

Crash in terrian-editor when removing the diffuse map #1

Closed pavly-gerges closed 2 years ago

pavly-gerges commented 2 years ago

The exception takes place in the brush when trying to remove the diffuse map. Log :

WARNING: The texture graphics/textures/sky/studio.hdr has linear color space, but the material parameter Texture specifies no color space requirement, this may lead to unexpected behavior.
Check if the image was not set to another material parameter with a linear color space, or that you did not set the ColorSpace to Linear using texture.getImage.setColorSpace().
Mar 28, 2022 2:22:55 PM com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
WARNING: Bad compile of:
1   #version 110
2   #define FRAGMENT_SHADER 1
3   #define WARDISO 1
4   #define NORMALMAP 1
5   #define ALPHAMAP 1
6   #define ALPHAMAP_1 1
7   #define ALPHAMAP_2 1
8   #define DIFFUSEMAP_0_SCALE 1.0
9   #define SINGLE_PASS_LIGHTING 1
10  #define NB_LIGHTS 15
11  // -- begin import Common/ShaderLib/BlinnPhongLighting.glsllib --
12  /*Blinn Phong ligting*/
13  
14  /*
15  * Computes diffuse factor (Lambert)
16  */
17  float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){
18      return max(0.0, dot(norm, lightdir));
19  }
20  
21  /*
22  * Computes specular factor   (blinn phong) 
23  */
24  float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
25      vec3 H = normalize(viewdir + lightdir);
26      float HdotN = max(0.0, dot(H, norm));
27      return pow(HdotN, shiny);
28  }
29  
30  /*
31  *Computes standard phong specular lighting
32  */
33  float lightComputeSpecularPhong(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
34      vec3 R = reflect(-lightdir, norm);
35      return pow(max(dot(R, viewdir), 0.0), shiny);
36  }
37  
38  
39  /*
40  * Computes diffuse and specular factors and pack them in a vec2 (x=diffuse, y=specular)
41  */
42  vec2 computeLighting(in vec3 norm, in vec3 viewDir, in vec3 lightDir, in float attenuation, in float shininess){
43     float diffuseFactor = lightComputeDiffuse(norm, lightDir);
44     float specularFactor = lightComputeSpecular(norm, viewDir, lightDir, shininess);      
45     if (shininess <= 1.0) {
46         specularFactor = 0.0; // should be one instruction on most cards ..
47     }
48     specularFactor *= diffuseFactor;
49     return vec2(diffuseFactor, specularFactor) * vec2(attenuation);
50  }
51  // -- end import Common/ShaderLib/BlinnPhongLighting.glsllib --
52  // -- begin import Common/ShaderLib/Lighting.glsllib --
53  /*Common function for light calculations*/
54  
55  
56  /*
57  * Computes light direction 
58  * lightType should be 0.0,1.0,2.0, repectively for Directional, point and spot lights.
59  * Outputs the light direction and the light half vector. 
60  */
61  void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out vec4 lightDir, out vec3 lightVec){
62      float posLight = step(0.5, lightType);    
63      vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
64      lightVec = tempVec;          
65      float dist = length(tempVec);
66  #ifdef SRGB
67      lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
68      lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
69  #else
70      lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
71  #endif
72      lightDir.xyz = tempVec / vec3(dist);
73  }
74  
75  /*
76  * Computes the spot falloff for a spotlight
77  */
78  float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector){
79      vec3 L=normalize(lightVector);
80      vec3 spotdir = normalize(lightDirection.xyz);
81      float curAngleCos = dot(-L, spotdir);    
82      float innerAngleCos = floor(lightDirection.w) * 0.001;
83      float outerAngleCos = fract(lightDirection.w);
84      float innerMinusOuter = innerAngleCos - outerAngleCos;
85      float falloff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, step(lightDirection.w, 0.001), 1.0);
86  
87  #ifdef SRGB
88      // Use quadratic falloff (notice the ^4)
89      return pow(clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0), 4.0);
90  #else
91      // Use linear falloff
92      return falloff;
93  #endif
94  }
95  
96  // -- end import Common/ShaderLib/Lighting.glsllib --
97  
98  uniform float m_Shininess;
99  
100 varying vec4 AmbientSum;
101 varying vec4 DiffuseSum;
102 varying vec4 SpecularSum;
103 
104 uniform mat4 g_ViewMatrix;
105 uniform vec4 g_LightData[NB_LIGHTS];
106 varying vec3 vTangent;
107 varying vec3 vBinormal;
108 varying vec3 vPos;    
109 varying vec3 vNormal;
110 varying vec2 texCoord;
111 
112 
113 #ifdef DIFFUSEMAP
114   uniform sampler2D m_DiffuseMap;
115 #endif
116 #ifdef DIFFUSEMAP_1
117   uniform sampler2D m_DiffuseMap_1;
118 #endif
119 #ifdef DIFFUSEMAP_2
120   uniform sampler2D m_DiffuseMap_2;
121 #endif
122 #ifdef DIFFUSEMAP_3
123   uniform sampler2D m_DiffuseMap_3;
124 #endif
125 #ifdef DIFFUSEMAP_4
126   uniform sampler2D m_DiffuseMap_4;
127 #endif
128 #ifdef DIFFUSEMAP_5
129   uniform sampler2D m_DiffuseMap_5;
130 #endif
131 #ifdef DIFFUSEMAP_6
132   uniform sampler2D m_DiffuseMap_6;
133 #endif
134 #ifdef DIFFUSEMAP_7
135   uniform sampler2D m_DiffuseMap_7;
136 #endif
137 #ifdef DIFFUSEMAP_8
138   uniform sampler2D m_DiffuseMap_8;
139 #endif
140 #ifdef DIFFUSEMAP_9
141   uniform sampler2D m_DiffuseMap_9;
142 #endif
143 #ifdef DIFFUSEMAP_10
144   uniform sampler2D m_DiffuseMap_10;
145 #endif
146 #ifdef DIFFUSEMAP_11
147   uniform sampler2D m_DiffuseMap_11;
148 #endif
149 
150 
151 #ifdef DIFFUSEMAP_0_SCALE
152   uniform float m_DiffuseMap_0_scale;
153 #endif
154 #ifdef DIFFUSEMAP_1_SCALE
155   uniform float m_DiffuseMap_1_scale;
156 #endif
157 #ifdef DIFFUSEMAP_2_SCALE
158   uniform float m_DiffuseMap_2_scale;
159 #endif
160 #ifdef DIFFUSEMAP_3_SCALE
161   uniform float m_DiffuseMap_3_scale;
162 #endif
163 #ifdef DIFFUSEMAP_4_SCALE
164   uniform float m_DiffuseMap_4_scale;
165 #endif
166 #ifdef DIFFUSEMAP_5_SCALE
167   uniform float m_DiffuseMap_5_scale;
168 #endif
169 #ifdef DIFFUSEMAP_6_SCALE
170   uniform float m_DiffuseMap_6_scale;
171 #endif
172 #ifdef DIFFUSEMAP_7_SCALE
173   uniform float m_DiffuseMap_7_scale;
174 #endif
175 #ifdef DIFFUSEMAP_8_SCALE
176   uniform float m_DiffuseMap_8_scale;
177 #endif
178 #ifdef DIFFUSEMAP_9_SCALE
179   uniform float m_DiffuseMap_9_scale;
180 #endif
181 #ifdef DIFFUSEMAP_10_SCALE
182   uniform float m_DiffuseMap_10_scale;
183 #endif
184 #ifdef DIFFUSEMAP_11_SCALE
185   uniform float m_DiffuseMap_11_scale;
186 #endif
187 
188 
189 #ifdef ALPHAMAP
190   uniform sampler2D m_AlphaMap;
191 #endif
192 #ifdef ALPHAMAP_1
193   uniform sampler2D m_AlphaMap_1;
194 #endif
195 #ifdef ALPHAMAP_2
196   uniform sampler2D m_AlphaMap_2;
197 #endif
198 
199 #ifdef NORMALMAP
200   uniform sampler2D m_NormalMap;
201 #endif
202 #ifdef NORMALMAP_1
203   uniform sampler2D m_NormalMap_1;
204 #endif
205 #ifdef NORMALMAP_2
206   uniform sampler2D m_NormalMap_2;
207 #endif
208 #ifdef NORMALMAP_3
209   uniform sampler2D m_NormalMap_3;
210 #endif
211 #ifdef NORMALMAP_4
212   uniform sampler2D m_NormalMap_4;
213 #endif
214 #ifdef NORMALMAP_5
215   uniform sampler2D m_NormalMap_5;
216 #endif
217 #ifdef NORMALMAP_6
218   uniform sampler2D m_NormalMap_6;
219 #endif
220 #ifdef NORMALMAP_7
221   uniform sampler2D m_NormalMap_7;
222 #endif
223 #ifdef NORMALMAP_8
224   uniform sampler2D m_NormalMap_8;
225 #endif
226 #ifdef NORMALMAP_9
227   uniform sampler2D m_NormalMap_9;
228 #endif
229 #ifdef NORMALMAP_10
230   uniform sampler2D m_NormalMap_10;
231 #endif
232 #ifdef NORMALMAP_11
233   uniform sampler2D m_NormalMap_11;
234 #endif
235 
236 
237 #ifdef TRI_PLANAR_MAPPING
238   varying vec4 wVertex;
239   varying vec3 wNormal;
240 #endif
241 
242 
243 #ifdef ALPHAMAP
244 
245   vec4 calculateDiffuseBlend(in vec2 texCoord) {
246     vec4 alphaBlend   = texture2D( m_AlphaMap, texCoord.xy );
247     
248     #ifdef ALPHAMAP_1
249       vec4 alphaBlend1   = texture2D( m_AlphaMap_1, texCoord.xy );
250     #endif
251     #ifdef ALPHAMAP_2
252       vec4 alphaBlend2   = texture2D( m_AlphaMap_2, texCoord.xy );
253     #endif
254 
255     vec4 diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale);
256     diffuseColor *= alphaBlend.r;
257     #ifdef DIFFUSEMAP_1
258         vec4 diffuseColor1 = texture2D(m_DiffuseMap_1, texCoord * m_DiffuseMap_1_scale);
259         diffuseColor = mix( diffuseColor, diffuseColor1, alphaBlend.g );
260     #endif
261     #ifdef DIFFUSEMAP_2
262         vec4 diffuseColor2 = texture2D(m_DiffuseMap_2, texCoord * m_DiffuseMap_2_scale);
263         diffuseColor = mix( diffuseColor, diffuseColor2, alphaBlend.b );
264     #endif
265     #ifdef DIFFUSEMAP_3
266         vec4 diffuseColor3 = texture2D(m_DiffuseMap_3, texCoord * m_DiffuseMap_3_scale);
267         diffuseColor = mix( diffuseColor, diffuseColor3, alphaBlend.a );
268     #endif
269 
270     #ifdef ALPHAMAP_1
271         #ifdef DIFFUSEMAP_4
272             vec4 diffuseColor4 = texture2D(m_DiffuseMap_4, texCoord * m_DiffuseMap_4_scale);
273             diffuseColor = mix( diffuseColor, diffuseColor4, alphaBlend1.r );
274         #endif
275         #ifdef DIFFUSEMAP_5
276             vec4 diffuseColor5 = texture2D(m_DiffuseMap_5, texCoord * m_DiffuseMap_5_scale);
277             diffuseColor = mix( diffuseColor, diffuseColor5, alphaBlend1.g );
278         #endif
279         #ifdef DIFFUSEMAP_6
280             vec4 diffuseColor6 = texture2D(m_DiffuseMap_6, texCoord * m_DiffuseMap_6_scale);
281             diffuseColor = mix( diffuseColor, diffuseColor6, alphaBlend1.b );
282         #endif
283         #ifdef DIFFUSEMAP_7
284             vec4 diffuseColor7 = texture2D(m_DiffuseMap_7, texCoord * m_DiffuseMap_7_scale);
285             diffuseColor = mix( diffuseColor, diffuseColor7, alphaBlend1.a );
286         #endif
287     #endif
288 
289     #ifdef ALPHAMAP_2
290         #ifdef DIFFUSEMAP_8
291             vec4 diffuseColor8 = texture2D(m_DiffuseMap_8, texCoord * m_DiffuseMap_8_scale);
292             diffuseColor = mix( diffuseColor, diffuseColor8, alphaBlend2.r );
293         #endif
294         #ifdef DIFFUSEMAP_9
295             vec4 diffuseColor9 = texture2D(m_DiffuseMap_9, texCoord * m_DiffuseMap_9_scale);
296             diffuseColor = mix( diffuseColor, diffuseColor9, alphaBlend2.g );
297         #endif
298         #ifdef DIFFUSEMAP_10
299             vec4 diffuseColor10 = texture2D(m_DiffuseMap_10, texCoord * m_DiffuseMap_10_scale);
300             diffuseColor = mix( diffuseColor, diffuseColor10, alphaBlend2.b );
301         #endif
302         #ifdef DIFFUSEMAP_11
303             vec4 diffuseColor11 = texture2D(m_DiffuseMap_11, texCoord * m_DiffuseMap_11_scale);
304             diffuseColor = mix( diffuseColor, diffuseColor11, alphaBlend2.a );
305         #endif                   
306     #endif
307 
308     return diffuseColor;
309   }
310 
311   vec3 calculateNormal(in vec2 texCoord) {
312     vec3 normal = vec3(0,0,1);
313     vec3 n = vec3(0,0,0);
314 
315     vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy );
316 
317     #ifdef ALPHAMAP_1
318       vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy );
319     #endif
320     #ifdef ALPHAMAP_2
321       vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord.xy );
322     #endif
323 
324     #ifdef NORMALMAP
325       n = texture2D(m_NormalMap, texCoord * m_DiffuseMap_0_scale).xyz;
326       normal += n * alphaBlend.r;
327     #else
328       normal += vec3(0.5,0.5,1) * alphaBlend.r;
329     #endif
330 
331     #ifdef NORMALMAP_1
332       n = texture2D(m_NormalMap_1, texCoord * m_DiffuseMap_1_scale).xyz;
333       normal += n * alphaBlend.g;
334     #else
335       normal += vec3(0.5,0.5,1) * alphaBlend.g;
336     #endif
337 
338     #ifdef NORMALMAP_2
339       n = texture2D(m_NormalMap_2, texCoord * m_DiffuseMap_2_scale).xyz;
340       normal += n * alphaBlend.b;
341     #else
342       normal += vec3(0.5,0.5,1) * alphaBlend.b;
343     #endif
344 
345     #ifdef NORMALMAP_3
346       n = texture2D(m_NormalMap_3, texCoord * m_DiffuseMap_3_scale).xyz;
347       normal += n * alphaBlend.a;
348     #else
349       normal += vec3(0.5,0.5,1) * alphaBlend.a;
350     #endif
351 
352     #ifdef ALPHAMAP_1
353         #ifdef NORMALMAP_4
354           n = texture2D(m_NormalMap_4, texCoord * m_DiffuseMap_4_scale).xyz;
355           normal += n * alphaBlend1.r;
356         #endif
357 
358         #ifdef NORMALMAP_5
359           n = texture2D(m_NormalMap_5, texCoord * m_DiffuseMap_5_scale).xyz;
360           normal += n * alphaBlend1.g;
361         #endif
362 
363         #ifdef NORMALMAP_6
364           n = texture2D(m_NormalMap_6, texCoord * m_DiffuseMap_6_scale).xyz;
365           normal += n * alphaBlend1.b;
366         #endif
367 
368         #ifdef NORMALMAP_7
369           n = texture2D(m_NormalMap_7, texCoord * m_DiffuseMap_7_scale).xyz;
370           normal += n * alphaBlend1.a;
371         #endif
372     #endif
373 
374     #ifdef ALPHAMAP_2
375         #ifdef NORMALMAP_8
376           n = texture2D(m_NormalMap_8, texCoord * m_DiffuseMap_8_scale).xyz;
377           normal += n * alphaBlend2.r;
378         #endif
379 
380         #ifdef NORMALMAP_9
381           n = texture2D(m_NormalMap_9, texCoord * m_DiffuseMap_9_scale);
382           normal += n * alphaBlend2.g;
383         #endif
384 
385         #ifdef NORMALMAP_10
386           n = texture2D(m_NormalMap_10, texCoord * m_DiffuseMap_10_scale);
387           normal += n * alphaBlend2.b;
388         #endif
389 
390         #ifdef NORMALMAP_11
391           n = texture2D(m_NormalMap_11, texCoord * m_DiffuseMap_11_scale);
392           normal += n * alphaBlend2.a;
393         #endif
394     #endif
395 
396     normal = (normal.xyz * vec3(2.0) - vec3(1.0));
397     return normalize(normal);
398   }
399 
400   #ifdef TRI_PLANAR_MAPPING
401 
402     vec4 getTriPlanarBlend(in vec4 coords, in vec3 blending, in sampler2D map, in float scale) {
403       vec4 col1 = texture2D( map, coords.yz * scale);
404       vec4 col2 = texture2D( map, coords.xz * scale);
405       vec4 col3 = texture2D( map, coords.xy * scale);
406       // blend the results of the 3 planar projections.
407       vec4 tex = col1 * blending.x + col2 * blending.y + col3 * blending.z;
408       return tex;
409     }
410 
411     vec4 calculateTriPlanarDiffuseBlend(in vec3 wNorm, in vec4 wVert, in vec2 texCoord) {
412         // tri-planar texture bending factor for this fragment's normal
413         vec3 blending = abs( wNorm );
414         blending = (blending -0.2) * 0.7;
415         blending = normalize(max(blending, 0.00001));      // Force weights to sum to 1.0 (very important!)
416         float b = (blending.x + blending.y + blending.z);
417         blending /= vec3(b, b, b);
418 
419         // texture coords
420         vec4 coords = wVert;
421 
422         // blend the results of the 3 planar projections.
423         vec4 tex0 = getTriPlanarBlend(coords, blending, m_DiffuseMap, m_DiffuseMap_0_scale);
424 
425         #ifdef DIFFUSEMAP_1
426           // blend the results of the 3 planar projections.
427           vec4 tex1 = getTriPlanarBlend(coords, blending, m_DiffuseMap_1, m_DiffuseMap_1_scale);
428         #endif
429         #ifdef DIFFUSEMAP_2
430           // blend the results of the 3 planar projections.
431           vec4 tex2 = getTriPlanarBlend(coords, blending, m_DiffuseMap_2, m_DiffuseMap_2_scale);
432         #endif
433         #ifdef DIFFUSEMAP_3
434           // blend the results of the 3 planar projections.
435           vec4 tex3 = getTriPlanarBlend(coords, blending, m_DiffuseMap_3, m_DiffuseMap_3_scale);
436         #endif
437         #ifdef DIFFUSEMAP_4
438           // blend the results of the 3 planar projections.
439           vec4 tex4 = getTriPlanarBlend(coords, blending, m_DiffuseMap_4, m_DiffuseMap_4_scale);
440         #endif
441         #ifdef DIFFUSEMAP_5
442           // blend the results of the 3 planar projections.
443           vec4 tex5 = getTriPlanarBlend(coords, blending, m_DiffuseMap_5, m_DiffuseMap_5_scale);
444         #endif
445         #ifdef DIFFUSEMAP_6
446           // blend the results of the 3 planar projections.
447           vec4 tex6 = getTriPlanarBlend(coords, blending, m_DiffuseMap_6, m_DiffuseMap_6_scale);
448         #endif
449         #ifdef DIFFUSEMAP_7
450           // blend the results of the 3 planar projections.
451           vec4 tex7 = getTriPlanarBlend(coords, blending, m_DiffuseMap_7, m_DiffuseMap_7_scale);
452         #endif
453         #ifdef DIFFUSEMAP_8
454           // blend the results of the 3 planar projections.
455           vec4 tex8 = getTriPlanarBlend(coords, blending, m_DiffuseMap_8, m_DiffuseMap_8_scale);
456         #endif
457         #ifdef DIFFUSEMAP_9
458           // blend the results of the 3 planar projections.
459           vec4 tex9 = getTriPlanarBlend(coords, blending, m_DiffuseMap_9, m_DiffuseMap_9_scale);
460         #endif
461         #ifdef DIFFUSEMAP_10
462           // blend the results of the 3 planar projections.
463           vec4 tex10 = getTriPlanarBlend(coords, blending, m_DiffuseMap_10, m_DiffuseMap_10_scale);
464         #endif
465         #ifdef DIFFUSEMAP_11
466           // blend the results of the 3 planar projections.
467           vec4 tex11 = getTriPlanarBlend(coords, blending, m_DiffuseMap_11, m_DiffuseMap_11_scale);
468         #endif
469 
470         vec4 alphaBlend   = texture2D( m_AlphaMap, texCoord.xy );
471 
472         #ifdef ALPHAMAP_1
473           vec4 alphaBlend1   = texture2D( m_AlphaMap_1, texCoord.xy );
474         #endif
475         #ifdef ALPHAMAP_2
476           vec4 alphaBlend2   = texture2D( m_AlphaMap_2, texCoord.xy );
477         #endif
478 
479         vec4 diffuseColor = tex0 * alphaBlend.r;
480         #ifdef DIFFUSEMAP_1
481             diffuseColor = mix( diffuseColor, tex1, alphaBlend.g );
482         #endif
483         #ifdef DIFFUSEMAP_2
484             diffuseColor = mix( diffuseColor, tex2, alphaBlend.b );
485         #endif
486         #ifdef DIFFUSEMAP_3
487             diffuseColor = mix( diffuseColor, tex3, alphaBlend.a );
488         #endif
489         #ifdef ALPHAMAP_1
490             #ifdef DIFFUSEMAP_4
491                 diffuseColor = mix( diffuseColor, tex4, alphaBlend1.r );
492             #endif
493             #ifdef DIFFUSEMAP_5
494                 diffuseColor = mix( diffuseColor, tex5, alphaBlend1.g );
495             #endif
496             #ifdef DIFFUSEMAP_6
497                 diffuseColor = mix( diffuseColor, tex6, alphaBlend1.b );
498             #endif
499             #ifdef DIFFUSEMAP_7
500                 diffuseColor = mix( diffuseColor, tex7, alphaBlend1.a );
501             #endif
502         #endif
503         #ifdef ALPHAMAP_2
504             #ifdef DIFFUSEMAP_8
505                 diffuseColor = mix( diffuseColor, tex8, alphaBlend2.r );
506             #endif
507             #ifdef DIFFUSEMAP_9
508                 diffuseColor = mix( diffuseColor, tex9, alphaBlend2.g );
509             #endif
510             #ifdef DIFFUSEMAP_10
511                 diffuseColor = mix( diffuseColor, tex10, alphaBlend2.b );
512             #endif
513             #ifdef DIFFUSEMAP_11
514                 diffuseColor = mix( diffuseColor, tex11, alphaBlend2.a );
515             #endif
516         #endif
517 
518         return diffuseColor;
519     }
520 
521     vec3 calculateNormalTriPlanar(in vec3 wNorm, in vec4 wVert,in vec2 texCoord) {
522       // tri-planar texture bending factor for this fragment's world-space normal
523       vec3 blending = abs( wNorm );
524       blending = (blending -0.2) * 0.7;
525       blending = normalize(max(blending, 0.00001));      // Force weights to sum to 1.0 (very important!)
526       float b = (blending.x + blending.y + blending.z);
527       blending /= vec3(b, b, b);
528 
529       // texture coords
530       vec4 coords = wVert;
531       vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy );
532 
533       #ifdef ALPHAMAP_1
534         vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy );
535       #endif
536       #ifdef ALPHAMAP_2
537         vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord.xy );
538       #endif
539 
540       vec3 normal = vec3(0,0,1);
541       vec3 n = vec3(0,0,0);
542 
543       #ifdef NORMALMAP
544           n = getTriPlanarBlend(coords, blending, m_NormalMap, m_DiffuseMap_0_scale).xyz;
545           normal += n * alphaBlend.r;
546       #else
547           normal += vec3(0.5,0.5,1) * alphaBlend.r;
548       #endif
549 
550       #ifdef NORMALMAP_1
551           n = getTriPlanarBlend(coords, blending, m_NormalMap_1, m_DiffuseMap_1_scale).xyz;
552           normal += n * alphaBlend.g;
553       #else
554           normal += vec3(0.5,0.5,1) * alphaBlend.g;
555       #endif
556 
557       #ifdef NORMALMAP_2
558           n = getTriPlanarBlend(coords, blending, m_NormalMap_2, m_DiffuseMap_2_scale).xyz;
559           normal += n * alphaBlend.b;
560       #else
561           normal += vec3(0.5,0.5,1) * alphaBlend.b;
562       #endif
563 
564       #ifdef NORMALMAP_3
565           n = getTriPlanarBlend(coords, blending, m_NormalMap_3, m_DiffuseMap_3_scale).xyz;
566           normal += n * alphaBlend.a;
567       #else
568           normal += vec3(0.5,0.5,1) * alphaBlend.a;
569       #endif
570 
571       #ifdef ALPHAMAP_1
572           #ifdef NORMALMAP_4
573               n = getTriPlanarBlend(coords, blending, m_NormalMap_4, m_DiffuseMap_4_scale).xyz;
574               normal += n * alphaBlend1.r;
575           #else
576               normal += vec3(0.5,0.5,1) * alphaBlend.r;
577           #endif
578 
579           #ifdef NORMALMAP_5
580               n = getTriPlanarBlend(coords, blending, m_NormalMap_5, m_DiffuseMap_5_scale).xyz;
581               normal += n * alphaBlend1.g;
582           #else
583               normal += vec3(0.5,0.5,1) * alphaBlend.g;
584           #endif
585 
586           #ifdef NORMALMAP_6
587               n = getTriPlanarBlend(coords, blending, m_NormalMap_6, m_DiffuseMap_6_scale).xyz;
588               normal += n * alphaBlend1.b;
589           #else
590               normal += vec3(0.5,0.5,1) * alphaBlend.b;
591           #endif
592 
593           #ifdef NORMALMAP_7
594               n = getTriPlanarBlend(coords, blending, m_NormalMap_7, m_DiffuseMap_7_scale).xyz;
595               normal += n * alphaBlend1.a;
596           #else
597               normal += vec3(0.5,0.5,1) * alphaBlend.a;
598           #endif
599       #endif
600 
601       #ifdef ALPHAMAP_2
602           #ifdef NORMALMAP_8
603               n = getTriPlanarBlend(coords, blending, m_NormalMap_8, m_DiffuseMap_8_scale).xyz;
604               normal += n * alphaBlend2.r;
605           #else
606               normal += vec3(0.5,0.5,1) * alphaBlend.r;
607           #endif
608 
609           #ifdef NORMALMAP_9
610               n = getTriPlanarBlend(coords, blending, m_NormalMap_9, m_DiffuseMap_9_scale).xyz;
611               normal += n * alphaBlend2.g;
612           #else
613               normal += vec3(0.5,0.5,1) * alphaBlend.g;
614           #endif
615 
616           #ifdef NORMALMAP_10
617               n = getTriPlanarBlend(coords, blending, m_NormalMap_10, m_DiffuseMap_10_scale).xyz;
618               normal += n * alphaBlend2.b;
619           #else
620               normal += vec3(0.5,0.5,1) * alphaBlend.b;
621           #endif
622 
623           #ifdef NORMALMAP_11
624               n = getTriPlanarBlend(coords, blending, m_NormalMap_11, m_DiffuseMap_11_scale).xyz;
625               normal += n * alphaBlend2.a;
626           #else
627               normal += vec3(0.5,0.5,1) * alphaBlend.a;
628           #endif
629       #endif
630 
631       normal = (normal.xyz * vec3(2.0) - vec3(1.0));
632       return normalize(normal);
633     }
634   #endif
635 
636 #endif
637  
638 void main(){
639 
640     //----------------------
641     // diffuse calculations
642     //----------------------
643     #ifdef DIFFUSEMAP
644       #ifdef ALPHAMAP
645         #ifdef TRI_PLANAR_MAPPING
646             vec4 diffuseColor = calculateTriPlanarDiffuseBlend(wNormal, wVertex, texCoord);
647         #else
648             vec4 diffuseColor = calculateDiffuseBlend(texCoord);
649         #endif
650       #else
651         vec4 diffuseColor = texture2D(m_DiffuseMap, texCoord);
652       #endif
653     #else
654       vec4 diffuseColor = vec4(1.0);
655     #endif
656 
657     
658     //---------------------
659     // normal calculations
660     //---------------------
661     #if defined(NORMALMAP) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7) || defined(NORMALMAP_8) || defined(NORMALMAP_9) || defined(NORMALMAP_10) || defined(NORMALMAP_11)
662       #ifdef TRI_PLANAR_MAPPING
663         vec3 normal = calculateNormalTriPlanar(wNormal, wVertex, texCoord);
664       #else
665         vec3 normal = calculateNormal(texCoord);
666       #endif
667       mat3 tbnMat = mat3(normalize(vTangent.xyz) , normalize(vBinormal.xyz) , normalize(vNormal.xyz));
668     #else
669       vec3 normal = vNormal;
670     #endif
671 
672 
673     //-----------------------
674     // lighting calculations
675     //-----------------------
676     gl_FragColor = AmbientSum * diffuseColor;
677     for( int i = 0;i < NB_LIGHTS; i+=3){
678         vec4 lightColor = g_LightData[i];
679         vec4 lightData1 = g_LightData[i+1];                
680         vec4 lightDir;
681         vec3 lightVec;            
682         lightComputeDir(vPos, lightColor.w, lightData1, lightDir, lightVec);
683 
684         float spotFallOff = 1.0;
685         #if __VERSION__ >= 110
686             // allow use of control flow
687         if(lightColor.w > 1.0){
688         #endif
689             spotFallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
690         #if __VERSION__ >= 110
691         }
692         #endif
693 
694         #ifdef NORMALMAP         
695             //Normal map -> lighting is computed in tangent space
696            lightDir.xyz = normalize(lightDir.xyz * tbnMat);
697            vec3 viewDir = normalize(-vPos.xyz * tbnMat);
698         #else
699             //no Normal map -> lighting is computed in view space
700             lightDir.xyz = normalize(lightDir.xyz);
701             vec3 viewDir = normalize(-vPos.xyz);
702         #endif
703 
704         vec2 light = computeLighting(normal, viewDir, lightDir.xyz, lightDir.w  * spotFallOff, m_Shininess);       
705         gl_FragColor.rgb += DiffuseSum.rgb * lightColor.rgb * diffuseColor.rgb  * vec3(light.x) +
706                             SpecularSum.rgb * vec3(light.y);
707     }
708 
709 }

Mar 28, 2022 2:22:55 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,Editor-Group]
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Common/MatDefs/Terrain/SPTerrainLighting.frag, defines, type=Fragment, language=GLSL100]
0:255(32): error: `m_DiffuseMap' undeclared
0:255(22): error: no matching function for call to `texture2D(error, vec2)'; candidates are:
0:255(22): error:    vec4 texture2D(sampler2D, vec2)
0:255(22): error:    vec4 texture2D(sampler2D, vec2, float)

    at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1269)
    at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1296)
    at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1360)
    at com.jme3.material.logic.SinglePassLightingLogic.render(SinglePassLightingLogic.java:215)
    at com.jme3.material.Technique.render(Technique.java:166)
    at com.jme3.material.Material.render(Material.java:970)
    at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:614)
    at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
    at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
    at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:877)
    at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:779)
    at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1108)
    at com.jme3.renderer.RenderManager.render(RenderManager.java:1158)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
    at com.jme3x.jfx.injfx.JmeToJFXApplication.update(JmeToJFXApplication.java:24)
    at com.ss.editor.Editor.update(Editor.java:330)
    at com.jme3.system.lwjgl.LwjglOffscreenBuffer.runLoop(LwjglOffscreenBuffer.java:125)
    at com.jme3.system.lwjgl.LwjglOffscreenBuffer.run(LwjglOffscreenBuffer.java:156)
    at java.lang.Thread.run(Thread.java:748)
pavly-gerges commented 2 years ago

Suggestion :

pavly-gerges commented 2 years ago
  • Add a blank default diffuse map for the brush so when the user removes the current brush, its replaced with the color blank (or alpha) brush.

Alright, this approach works just fine !