Advertisement
Guest User

Untitled

a guest
Dec 6th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.58 KB | None | 0 0
  1. ant -f C:\\eclipse\\workspaces\\jme\\BasicGame -Dnb.internal.action.name=run.single -Djavac.includes=mygame/MySimpleApplication.java -Drun.class=mygame.MySimpleApplication run-single
  2. init:
  3. Deleting: C:\eclipse\workspaces\jme\BasicGame\build\built-jar.properties
  4. deps-jar:
  5. Updating property file: C:\eclipse\workspaces\jme\BasicGame\build\built-jar.properties
  6. Compiling 1 source file to C:\eclipse\workspaces\jme\BasicGame\build\classes
  7. warning: [options] bootstrap class path not set in conjunction with -source 7
  8. 1 warning
  9. compile-single:
  10. run-single:
  11. gru 06, 2021 10:38:56 AM com.jme3.system.JmeDesktopSystem initialize
  12. INFO: Running on jMonkeyEngine 3.3.0-stable
  13. * Branch: HEAD
  14. * Git Hash: 391e0dc
  15. * Build Date: 2021-04-05
  16. gru 06, 2021 10:38:56 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
  17. INFO: LWJGL 2.9.3 context running on thread jME3 Main
  18. * Graphics Adapter: igdumd64
  19. * Driver Version: null
  20. * Scaling Factor: 1
  21. WARNING: An illegal reflective access operation has occurred
  22. WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/C:/Program%20Files%20(x86)/jmonkeyplatform/jmonkeyplatform/libs/jme3-core-3.3.0-stable.jar) to method sun.nio.ch.DirectBuffer.cleaner()
  23. WARNING: Please consider reporting this to the maintainers of com.jme3.util.ReflectionAllocator
  24. WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
  25. WARNING: All illegal access operations will be denied in a future release
  26. gru 06, 2021 10:38:56 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
  27. INFO: OpenGL Renderer Information
  28. * Vendor: Intel
  29. * Renderer: Intel(R) HD Graphics 4000
  30. * OpenGL Version: 3.2.0 - Build 9.17.10.2867
  31. * GLSL Version: 1.50 - Build 9.17.10.2867
  32. * Profile: Core
  33. gru 06, 2021 10:38:56 AM com.jme3.asset.AssetConfig loadText
  34. WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
  35. gru 06, 2021 10:38:56 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  36. INFO: Audio Renderer Information
  37. * Device: OpenAL Soft
  38. * Vendor: OpenAL Community
  39. * Renderer: OpenAL Soft
  40. * Version: 1.1 ALSOFT 1.15.1
  41. * Supported channels: 64
  42. * ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
  43. * AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
  44. gru 06, 2021 10:38:56 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  45. WARNING: Pausing audio device not supported.
  46. gru 06, 2021 10:38:56 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  47. INFO: Audio effect extension version: 1.0
  48. gru 06, 2021 10:38:56 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  49. INFO: Audio max auxiliary sends: 4
  50. gru 06, 2021 10:38:57 AM com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
  51. WARNING: Bad compile of:
  52. 1 #version 150 core
  53. 2 #define FRAGMENT_SHADER 1
  54. 3 #define NUM_BONES 10
  55. 4 #define NORMAL_TYPE -1.0
  56. 5 #define SINGLE_PASS_LIGHTING 1
  57. 6 #define NB_LIGHTS 3
  58. 7 #extension GL_ARB_shader_texture_lod : enable
  59. 8 // -- begin import Common/ShaderLib/GLSLCompat.glsllib --
  60. 9 #if defined GL_ES
  61. 10 # define hfloat highp float
  62. 11 # define hvec2 highp vec2
  63. 12 # define hvec3 highp vec3
  64. 13 # define hvec4 highp vec4
  65. 14 # define lfloat lowp float
  66. 15 # define lvec2 lowp vec2
  67. 16 # define lvec3 lowp vec3
  68. 17 # define lvec4 lowp vec4
  69. 18 #else
  70. 19 # define hfloat float
  71. 20 # define hvec2 vec2
  72. 21 # define hvec3 vec3
  73. 22 # define hvec4 vec4
  74. 23 # define lfloat float
  75. 24 # define lvec2 vec2
  76. 25 # define lvec3 vec3
  77. 26 # define lvec4 vec4
  78. 27 #endif
  79. 28
  80. 29 #if __VERSION__ >= 130
  81. 30 # ifdef GL_ES
  82. 31 out highp vec4 outFragColor;
  83. 32 # else
  84. 33 out vec4 outFragColor;
  85. 34 #endif
  86. 35 # define texture1D texture
  87. 36 # define texture2D texture
  88. 37 # define texture3D texture
  89. 38 # define textureCube texture
  90. 39 # define texture2DLod textureLod
  91. 40 # define textureCubeLod textureLod
  92. 41 # define texture2DArray texture
  93. 42 # if defined VERTEX_SHADER
  94. 43 # define varying out
  95. 44 # define attribute in
  96. 45 # elif defined FRAGMENT_SHADER
  97. 46 # define varying in
  98. 47 # define gl_FragColor outFragColor
  99. 48 # endif
  100. 49 #else
  101. 50 # define isnan(val) !(val<0.0||val>0.0||val==0.0)
  102. 51 #endif
  103. 52
  104. 53
  105. 54 // -- end import Common/ShaderLib/GLSLCompat.glsllib --
  106. 55 // -- begin import Common/ShaderLib/PBR.glsllib --
  107. 56 #ifndef PI
  108. 57 #define PI 3.14159265358979323846264
  109. 58 #endif
  110. 59
  111. 60 //Specular fresnel computation
  112. 61 vec3 F_Shlick(float vh, vec3 F0){
  113. 62 float fresnelFact = pow(2.0, (-5.55473*vh - 6.98316) * vh);
  114. 63 return mix(F0, vec3(1.0, 1.0, 1.0), fresnelFact);
  115. 64 }
  116. 65
  117. 66 vec3 sphericalHarmonics( const in vec3 normal, const vec3 sph[9] ){
  118. 67 float x = normal.x;
  119. 68 float y = normal.y;
  120. 69 float z = normal.z;
  121. 70
  122. 71 vec3 result = (
  123. 72 sph[0] +
  124. 73
  125. 74 sph[1] * y +
  126. 75 sph[2] * z +
  127. 76 sph[3] * x +
  128. 77
  129. 78 sph[4] * y * x +
  130. 79 sph[5] * y * z +
  131. 80 sph[6] * (3.0 * z * z - 1.0) +
  132. 81 sph[7] * (z * x) +
  133. 82 sph[8] * (x*x - y*y)
  134. 83 );
  135. 84
  136. 85 return max(result, vec3(0.0));
  137. 86 }
  138. 87
  139. 88
  140. 89 float PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir,
  141. 90 vec3 lightColor, vec3 fZero, float roughness, float ndotv,
  142. 91 out vec3 outDiffuse, out vec3 outSpecular){
  143. 92 // Compute halfway vector.
  144. 93 vec3 halfVec = normalize(lightDir + viewDir);
  145. 94
  146. 95 // Compute ndotl, ndoth, vdoth terms which are needed later.
  147. 96 float ndotl = max( dot(normal, lightDir), 0.0);
  148. 97 float ndoth = max( dot(normal, halfVec), 0.0);
  149. 98 float hdotv = max( dot(viewDir, halfVec), 0.0);
  150. 99
  151. 100 // Compute diffuse using energy-conserving Lambert.
  152. 101 // Alternatively, use Oren-Nayar for really rough
  153. 102 // materials or if you have lots of processing power ...
  154. 103 outDiffuse = vec3(ndotl) * lightColor;
  155. 104
  156. 105 //cook-torrence, microfacet BRDF : http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
  157. 106
  158. 107 float alpha = roughness * roughness;
  159. 108
  160. 109 //D, GGX normaal Distribution function
  161. 110 float alpha2 = alpha * alpha;
  162. 111 float sum = ((ndoth * ndoth) * (alpha2 - 1.0) + 1.0);
  163. 112 float denom = PI * sum * sum;
  164. 113 float D = alpha2 / denom;
  165. 114
  166. 115 // Compute Fresnel function via Schlick's approximation.
  167. 116 vec3 fresnel = F_Shlick(hdotv, fZero);
  168. 117
  169. 118 //G Shchlick GGX Gometry shadowing term, k = alpha/2
  170. 119 float k = alpha * 0.5;
  171. 120
  172. 121 /*
  173. 122 //classic Schlick ggx
  174. 123 float G_V = ndotv / (ndotv * (1.0 - k) + k);
  175. 124 float G_L = ndotl / (ndotl * (1.0 - k) + k);
  176. 125 float G = ( G_V * G_L );
  177. 126
  178. 127 float specular =(D* fresnel * G) /(4 * ndotv);
  179. 128 */
  180. 129
  181. 130 // UE4 way to optimise shlick GGX Gometry shadowing term
  182. 131 //http://graphicrants.blogspot.co.uk/2013/08/specular-brdf-reference.html
  183. 132 float G_V = ndotv + sqrt( (ndotv - ndotv * k) * ndotv + k );
  184. 133 float G_L = ndotl + sqrt( (ndotl - ndotl * k) * ndotl + k );
  185. 134 // the max here is to avoid division by 0 that may cause some small glitches.
  186. 135 float G = 1.0/max( G_V * G_L ,0.01);
  187. 136
  188. 137 float specular = D * G * ndotl;
  189. 138
  190. 139 outSpecular = vec3(specular) * fresnel * lightColor;
  191. 140 return hdotv;
  192. 141 }
  193. 142
  194. 143 vec3 integrateBRDFApprox( const in vec3 specular, float roughness, float NoV ){
  195. 144 const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022 );
  196. 145 const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04 );
  197. 146 vec4 r = roughness * c0 + c1;
  198. 147 float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;
  199. 148 vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
  200. 149 return specular * AB.x + AB.y;
  201. 150 }
  202. 151
  203. 152 // from Sebastien Lagarde https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf page 69
  204. 153 vec3 getSpecularDominantDir(const in vec3 N, const in vec3 R, const in float realRoughness){
  205. 154 vec3 dominant;
  206. 155
  207. 156 float smoothness = 1.0 - realRoughness;
  208. 157 float lerpFactor = smoothness * (sqrt(smoothness) + realRoughness);
  209. 158 // The result is not normalized as we fetch in a cubemap
  210. 159 dominant = mix(N, R, lerpFactor);
  211. 160
  212. 161 return dominant;
  213. 162 }
  214. 163
  215. 164 vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  216. 165 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  217. 166 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb;
  218. 167 vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg;
  219. 168 return PrefilteredColor * ( SpecularColor * EnvBRDF.x+ EnvBRDF.y );
  220. 169 }
  221. 170
  222. 171 vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  223. 172 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  224. 173 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz, Lod).rgb;
  225. 174 return PrefilteredColor * integrateBRDFApprox(SpecularColor, Roughness, ndotv);
  226. 175 }
  227. 176
  228. 177
  229. 178 float renderProbe(vec3 viewDir, vec3 worldPos, vec3 normal, vec3 norm, float Roughness, vec4 diffuseColor, vec4 specularColor, float ndotv, vec3 ao, mat4 lightProbeData,vec3 shCoeffs[9],samplerCube prefEnvMap, inout vec3 color ){
  230. 179
  231. 180 // lightProbeData is a mat4 with this layout
  232. 181 // 3x3 rot mat|
  233. 182 // 0 1 2 | 3
  234. 183 // 0 | ax bx cx | px | )
  235. 184 // 1 | ay by cy | py | probe position
  236. 185 // 2 | az bz cz | pz | )
  237. 186 // --|----------|
  238. 187 // 3 | sx sy sz sp | -> 1/probe radius + nbMipMaps
  239. 188 // --scale--
  240. 189 // parallax fix for spherical / obb bounds and probe blending from
  241. 190 // from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
  242. 191 vec3 rv = reflect(-viewDir, normal);
  243. 192 vec4 probePos = lightProbeData[3];
  244. 193 float invRadius = fract( probePos.w);
  245. 194 float nbMipMaps = probePos.w - invRadius;
  246. 195 vec3 direction = worldPos - probePos.xyz;
  247. 196 float ndf = 0.0;
  248. 197
  249. 198 if(lightProbeData[0][3] != 0.0){
  250. 199 // oriented box probe
  251. 200 mat3 wToLocalRot = mat3(lightProbeData);
  252. 201 wToLocalRot = inverse(wToLocalRot);
  253. 202 vec3 scale = vec3(lightProbeData[0][3], lightProbeData[1][3], lightProbeData[2][3]);
  254. 203 #if NB_PROBES >= 2
  255. 204 // probe blending
  256. 205 // compute fragment position in probe local space
  257. 206 vec3 localPos = wToLocalRot * worldPos;
  258. 207 localPos -= probePos.xyz;
  259. 208 // compute normalized distance field
  260. 209 vec3 localDir = abs(localPos);
  261. 210 localDir /= scale;
  262. 211 ndf = max(max(localDir.x, localDir.y), localDir.z);
  263. 212 #endif
  264. 213 // parallax fix
  265. 214 vec3 rayLs = wToLocalRot * rv;
  266. 215 rayLs /= scale;
  267. 216
  268. 217 vec3 positionLs = worldPos - probePos.xyz;
  269. 218 positionLs = wToLocalRot * positionLs;
  270. 219 positionLs /= scale;
  271. 220
  272. 221 vec3 unit = vec3(1.0);
  273. 222 vec3 firstPlaneIntersect = (unit - positionLs) / rayLs;
  274. 223 vec3 secondPlaneIntersect = (-unit - positionLs) / rayLs;
  275. 224 vec3 furthestPlane = max(firstPlaneIntersect, secondPlaneIntersect);
  276. 225 float distance = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
  277. 226
  278. 227 vec3 intersectPositionWs = worldPos + rv * distance;
  279. 228 rv = intersectPositionWs - probePos.xyz;
  280. 229
  281. 230 } else {
  282. 231 // spherical probe
  283. 232 // paralax fix
  284. 233 rv = invRadius * direction + rv;
  285. 234
  286. 235 #if NB_PROBES >= 2
  287. 236 // probe blending
  288. 237 float dist = sqrt(dot(direction, direction));
  289. 238 ndf = dist * invRadius;
  290. 239 #endif
  291. 240 }
  292. 241
  293. 242 vec3 indirectDiffuse = vec3(0.0);
  294. 243 vec3 indirectSpecular = vec3(0.0);
  295. 244 indirectDiffuse = sphericalHarmonics(normal.xyz, shCoeffs) * diffuseColor.rgb;
  296. 245 vec3 dominantR = getSpecularDominantDir( normal, rv.xyz, Roughness * Roughness );
  297. 246 indirectSpecular = ApproximateSpecularIBLPolynomial(prefEnvMap, specularColor.rgb, Roughness, ndotv, dominantR, nbMipMaps);
  298. 247
  299. 248 #ifdef HORIZON_FADE
  300. 249 //horizon fade from http://marmosetco.tumblr.com/post/81245981087
  301. 250 float horiz = dot(rv, norm);
  302. 251 float horizFadePower = 1.0 - Roughness;
  303. 252 horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
  304. 253 horiz *= horiz;
  305. 254 indirectSpecular *= vec3(horiz);
  306. 255 #endif
  307. 256
  308. 257 vec3 indirectLighting = (indirectDiffuse + indirectSpecular) * ao;
  309. 258
  310. 259 color = indirectLighting * step( 0.0, probePos.w);
  311. 260 return ndf;
  312. 261 }
  313. 262
  314. 263
  315. 264
  316. 265
  317. 266
  318. 267 // -- end import Common/ShaderLib/PBR.glsllib --
  319. 268 // -- begin import Common/ShaderLib/Parallax.glsllib --
  320. 269 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
  321. 270 vec2 steepParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  322. 271 vec2 vParallaxDirection = normalize( vViewDir.xy );
  323. 272
  324. 273 // The length of this vector determines the furthest amount of displacement: (Ati's comment)
  325. 274 float fLength = length( vViewDir );
  326. 275 float fParallaxLength = sqrt( fLength * fLength - vViewDir.z * vViewDir.z ) / vViewDir.z;
  327. 276
  328. 277 // Compute the actual reverse parallax displacement vector: (Ati's comment)
  329. 278 vec2 vParallaxOffsetTS = vParallaxDirection * fParallaxLength;
  330. 279
  331. 280 // Need to scale the amount of displacement to account for different height ranges
  332. 281 // in height maps. This is controlled by an artist-editable parameter: (Ati's comment)
  333. 282 parallaxScale *=0.3;
  334. 283 vParallaxOffsetTS *= parallaxScale;
  335. 284
  336. 285 vec3 eyeDir = normalize(vViewDir).xyz;
  337. 286
  338. 287 float nMinSamples = 6.0;
  339. 288 float nMaxSamples = 1000.0 * parallaxScale;
  340. 289 float nNumSamples = mix( nMinSamples, nMaxSamples, 1.0 - eyeDir.z ); //In reference shader: int nNumSamples = (int)(lerp( nMinSamples, nMaxSamples, dot( eyeDirWS, N ) ));
  341. 290 float fStepSize = 1.0 / nNumSamples;
  342. 291 float fCurrHeight = 0.0;
  343. 292 float fPrevHeight = 1.0;
  344. 293 float fNextHeight = 0.0;
  345. 294 float nStepIndex = 0.0;
  346. 295 vec2 vTexOffsetPerStep = fStepSize * vParallaxOffsetTS;
  347. 296 vec2 vTexCurrentOffset = texCoord;
  348. 297 float fCurrentBound = 1.0;
  349. 298 float fParallaxAmount = 0.0;
  350. 299
  351. 300 while ( nStepIndex < nNumSamples && fCurrHeight <= fCurrentBound ) {
  352. 301 vTexCurrentOffset -= vTexOffsetPerStep;
  353. 302 fPrevHeight = fCurrHeight;
  354. 303
  355. 304
  356. 305 #ifdef NORMALMAP_PARALLAX
  357. 306 //parallax map is stored in the alpha channel of the normal map
  358. 307 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).a;
  359. 308 #else
  360. 309 //parallax map is a texture
  361. 310 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).r;
  362. 311 #endif
  363. 312
  364. 313 fCurrentBound -= fStepSize;
  365. 314 nStepIndex+=1.0;
  366. 315 }
  367. 316 vec2 pt1 = vec2( fCurrentBound, fCurrHeight );
  368. 317 vec2 pt2 = vec2( fCurrentBound + fStepSize, fPrevHeight );
  369. 318
  370. 319 float fDelta2 = pt2.x - pt2.y;
  371. 320 float fDelta1 = pt1.x - pt1.y;
  372. 321
  373. 322 float fDenominator = fDelta2 - fDelta1;
  374. 323
  375. 324 fParallaxAmount = (pt1.x * fDelta2 - pt2.x * fDelta1 ) / fDenominator;
  376. 325
  377. 326 vec2 vParallaxOffset = vParallaxOffsetTS * (1.0 - fParallaxAmount );
  378. 327 return texCoord - vParallaxOffset;
  379. 328 }
  380. 329
  381. 330 vec2 classicParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  382. 331 float h;
  383. 332 #ifdef NORMALMAP_PARALLAX
  384. 333 //parallax map is stored in the alpha channel of the normal map
  385. 334 h = texture2D(parallaxMap, texCoord).a;
  386. 335 #else
  387. 336 //parallax map is a texture
  388. 337 h = texture2D(parallaxMap, texCoord).r;
  389. 338 #endif
  390. 339 float heightScale = parallaxScale;
  391. 340 float heightBias = heightScale* -0.6;
  392. 341 vec3 normView = normalize(vViewDir);
  393. 342 h = (h * heightScale + heightBias) * normView.z;
  394. 343 return texCoord + (h * normView.xy);
  395. 344 }
  396. 345 #endif
  397. 346 // -- end import Common/ShaderLib/Parallax.glsllib --
  398. 347 // -- begin import Common/ShaderLib/Lighting.glsllib --
  399. 348 /*Common function for light calculations*/
  400. 349
  401. 350
  402. 351 /*
  403. 352 * Computes light direction
  404. 353 * lightType should be 0.0,1.0,2.0, repectively for Directional, point and spot lights.
  405. 354 * Outputs the light direction and the light half vector.
  406. 355 */
  407. 356 void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out vec4 lightDir, out vec3 lightVec){
  408. 357 float posLight = step(0.5, lightType);
  409. 358 vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
  410. 359 lightVec = tempVec;
  411. 360 float dist = length(tempVec);
  412. 361 #ifdef SRGB
  413. 362 lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
  414. 363 lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
  415. 364 #else
  416. 365 lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
  417. 366 #endif
  418. 367 lightDir.xyz = tempVec / vec3(dist);
  419. 368 }
  420. 369
  421. 370 /*
  422. 371 * Computes the spot falloff for a spotlight
  423. 372 */
  424. 373 float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector){
  425. 374 vec3 L=normalize(lightVector);
  426. 375 vec3 spotdir = normalize(lightDirection.xyz);
  427. 376 float curAngleCos = dot(-L, spotdir);
  428. 377 float innerAngleCos = floor(lightDirection.w) * 0.001;
  429. 378 float outerAngleCos = fract(lightDirection.w);
  430. 379 float innerMinusOuter = innerAngleCos - outerAngleCos;
  431. 380 float falloff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, step(lightDirection.w, 0.001), 1.0);
  432. 381
  433. 382 #ifdef SRGB
  434. 383 // Use quadratic falloff (notice the ^4)
  435. 384 return pow(clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0), 4.0);
  436. 385 #else
  437. 386 // Use linear falloff
  438. 387 return falloff;
  439. 388 #endif
  440. 389 }
  441. 390
  442. 391 // -- end import Common/ShaderLib/Lighting.glsllib --
  443. 392
  444. 393 varying vec2 texCoord;
  445. 394 #ifdef SEPARATE_TEXCOORD
  446. 395 varying vec2 texCoord2;
  447. 396 #endif
  448. 397
  449. 398 varying vec4 Color;
  450. 399
  451. 400 uniform vec4 g_LightData[NB_LIGHTS];
  452. 401 uniform vec3 g_CameraPosition;
  453. 402 uniform vec4 g_AmbientLightColor;
  454. 403
  455. 404 uniform float m_Roughness;
  456. 405 uniform float m_Metallic;
  457. 406
  458. 407 varying vec3 wPosition;
  459. 408
  460. 409
  461. 410 #if NB_PROBES >= 1
  462. 411 uniform samplerCube g_PrefEnvMap;
  463. 412 uniform vec3 g_ShCoeffs[9];
  464. 413 uniform mat4 g_LightProbeData;
  465. 414 #endif
  466. 415 #if NB_PROBES >= 2
  467. 416 uniform samplerCube g_PrefEnvMap2;
  468. 417 uniform vec3 g_ShCoeffs2[9];
  469. 418 uniform mat4 g_LightProbeData2;
  470. 419 #endif
  471. 420 #if NB_PROBES == 3
  472. 421 uniform samplerCube g_PrefEnvMap3;
  473. 422 uniform vec3 g_ShCoeffs3[9];
  474. 423 uniform mat4 g_LightProbeData3;
  475. 424 #endif
  476. 425
  477. 426 #ifdef BASECOLORMAP
  478. 427 uniform sampler2D m_BaseColorMap;
  479. 428 #endif
  480. 429
  481. 430 #ifdef USE_PACKED_MR
  482. 431 uniform sampler2D m_MetallicRoughnessMap;
  483. 432 #else
  484. 433 #ifdef METALLICMAP
  485. 434 uniform sampler2D m_MetallicMap;
  486. 435 #endif
  487. 436 #ifdef ROUGHNESSMAP
  488. 437 uniform sampler2D m_RoughnessMap;
  489. 438 #endif
  490. 439 #endif
  491. 440
  492. 441 #ifdef EMISSIVE
  493. 442 uniform vec4 m_Emissive;
  494. 443 #endif
  495. 444 #ifdef EMISSIVEMAP
  496. 445 uniform sampler2D m_EmissiveMap;
  497. 446 #endif
  498. 447 #if defined(EMISSIVE) || defined(EMISSIVEMAP)
  499. 448 uniform float m_EmissivePower;
  500. 449 uniform float m_EmissiveIntensity;
  501. 450 #endif
  502. 451
  503. 452 #ifdef SPECGLOSSPIPELINE
  504. 453
  505. 454 uniform vec4 m_Specular;
  506. 455 uniform float m_Glossiness;
  507. 456 #ifdef USE_PACKED_SG
  508. 457 uniform sampler2D m_SpecularGlossinessMap;
  509. 458 #else
  510. 459 uniform sampler2D m_SpecularMap;
  511. 460 uniform sampler2D m_GlossinessMap;
  512. 461 #endif
  513. 462 #endif
  514. 463
  515. 464 #ifdef PARALLAXMAP
  516. 465 uniform sampler2D m_ParallaxMap;
  517. 466 #endif
  518. 467 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  519. 468 uniform float m_ParallaxHeight;
  520. 469 #endif
  521. 470
  522. 471 #ifdef LIGHTMAP
  523. 472 uniform sampler2D m_LightMap;
  524. 473 #endif
  525. 474
  526. 475 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  527. 476 uniform sampler2D m_NormalMap;
  528. 477 varying vec4 wTangent;
  529. 478 #endif
  530. 479 varying vec3 wNormal;
  531. 480
  532. 481 #ifdef DISCARD_ALPHA
  533. 482 uniform float m_AlphaDiscardThreshold;
  534. 483 #endif
  535. 484
  536. 485 void main(){
  537. 486 vec2 newTexCoord;
  538. 487 vec3 viewDir = normalize(g_CameraPosition - wPosition);
  539. 488
  540. 489 vec3 norm = normalize(wNormal);
  541. 490 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  542. 491 vec3 tan = normalize(wTangent.xyz);
  543. 492 mat3 tbnMat = mat3(tan, wTangent.w * cross( (norm), (tan)), norm);
  544. 493 #endif
  545. 494
  546. 495 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  547. 496 vec3 vViewDir = viewDir * tbnMat;
  548. 497 #ifdef STEEP_PARALLAX
  549. 498 #ifdef NORMALMAP_PARALLAX
  550. 499 //parallax map is stored in the alpha channel of the normal map
  551. 500 newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  552. 501 #else
  553. 502 //parallax map is a texture
  554. 503 newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  555. 504 #endif
  556. 505 #else
  557. 506 #ifdef NORMALMAP_PARALLAX
  558. 507 //parallax map is stored in the alpha channel of the normal map
  559. 508 newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  560. 509 #else
  561. 510 //parallax map is a texture
  562. 511 newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  563. 512 #endif
  564. 513 #endif
  565. 514 #else
  566. 515 newTexCoord = texCoord;
  567. 516 #endif
  568. 517
  569. 518 #ifdef BASECOLORMAP
  570. 519 vec4 albedo = texture2D(m_BaseColorMap, newTexCoord) * Color;
  571. 520 #else
  572. 521 vec4 albedo = Color;
  573. 522 #endif
  574. 523
  575. 524 #ifdef USE_PACKED_MR
  576. 525 vec2 rm = texture2D(m_MetallicRoughnessMap, newTexCoord).gb;
  577. 526 float Roughness = rm.x * max(m_Roughness, 1e-4);
  578. 527 float Metallic = rm.y * max(m_Metallic, 0.0);
  579. 528 #else
  580. 529 #ifdef ROUGHNESSMAP
  581. 530 float Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness, 1e-4);
  582. 531 #else
  583. 532 float Roughness = max(m_Roughness, 1e-4);
  584. 533 #endif
  585. 534 #ifdef METALLICMAP
  586. 535 float Metallic = texture2D(m_MetallicMap, newTexCoord).r * max(m_Metallic, 0.0);
  587. 536 #else
  588. 537 float Metallic = max(m_Metallic, 0.0);
  589. 538 #endif
  590. 539 #endif
  591. 540
  592. 541 float alpha = albedo.a;
  593. 542
  594. 543 #ifdef DISCARD_ALPHA
  595. 544 if(alpha < m_AlphaDiscardThreshold){
  596. 545 discard;
  597. 546 }
  598. 547 #endif
  599. 548
  600. 549 // ***********************
  601. 550 // Read from textures
  602. 551 // ***********************
  603. 552 #if defined(NORMALMAP)
  604. 553 vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
  605. 554 //Note the -2.0 and -1.0. We invert the green channel of the normal map,
  606. 555 //as it's complient with normal maps generated with blender.
  607. 556 //see http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898
  608. 557 //for more explanation.
  609. 558 vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)));
  610. 559 normal = normalize(tbnMat * normal);
  611. 560 //normal = normalize(normal * inverse(tbnMat));
  612. 561 #else
  613. 562 vec3 normal = norm;
  614. 563 #endif
  615. 564
  616. 565 #ifdef SPECGLOSSPIPELINE
  617. 566
  618. 567 #ifdef USE_PACKED_SG
  619. 568 vec4 specularColor = texture2D(m_SpecularGlossinessMap, newTexCoord);
  620. 569 float glossiness = specularColor.a * m_Glossiness;
  621. 570 specularColor *= m_Specular;
  622. 571 #else
  623. 572 #ifdef SPECULARMAP
  624. 573 vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
  625. 574 #else
  626. 575 vec4 specularColor = vec4(1.0);
  627. 576 #endif
  628. 577 #ifdef GLOSSINESSMAP
  629. 578 float glossiness = texture2D(m_GlossinessMap, newTexCoord).r * m_Glossiness;
  630. 579 #else
  631. 580 float glossiness = m_Glossiness;
  632. 581 #endif
  633. 582 specularColor *= m_Specular;
  634. 583 #endif
  635. 584 vec4 diffuseColor = albedo;// * (1.0 - max(max(specularColor.r, specularColor.g), specularColor.b));
  636. 585 Roughness = 1.0 - glossiness;
  637. 586 vec3 fZero = specularColor.xyz;
  638. 587 #else
  639. 588 float specular = 0.5;
  640. 589 float nonMetalSpec = 0.08 * specular;
  641. 590 vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
  642. 591 vec4 diffuseColor = albedo - albedo * Metallic;
  643. 592 vec3 fZero = vec3(specular);
  644. 593 #endif
  645. 594
  646. 595 gl_FragColor.rgb = vec3(0.0);
  647. 596 vec3 ao = vec3(1.0);
  648. 597
  649. 598 #ifdef LIGHTMAP
  650. 599 vec3 lightMapColor;
  651. 600 #ifdef SEPARATE_TEXCOORD
  652. 601 lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
  653. 602 #else
  654. 603 lightMapColor = texture2D(m_LightMap, texCoord).rgb;
  655. 604 #endif
  656. 605 #ifdef AO_MAP
  657. 606 lightMapColor.gb = lightMapColor.rr;
  658. 607 ao = lightMapColor;
  659. 608 #else
  660. 609 gl_FragColor.rgb += diffuseColor.rgb * lightMapColor;
  661. 610 #endif
  662. 611 specularColor.rgb *= lightMapColor;
  663. 612 #endif
  664. 613
  665. 614
  666. 615 float ndotv = max( dot( normal, viewDir ),0.0);
  667. 616 for( int i = 0;i < NB_LIGHTS; i+=3){
  668. 617 vec4 lightColor = g_LightData[i];
  669. 618 vec4 lightData1 = g_LightData[i+1];
  670. 619 vec4 lightDir;
  671. 620 vec3 lightVec;
  672. 621 lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec);
  673. 622
  674. 623 float fallOff = 1.0;
  675. 624 #if __VERSION__ >= 110
  676. 625 // allow use of control flow
  677. 626 if(lightColor.w > 1.0){
  678. 627 #endif
  679. 628 fallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
  680. 629 #if __VERSION__ >= 110
  681. 630 }
  682. 631 #endif
  683. 632 //point light attenuation
  684. 633 fallOff *= lightDir.w;
  685. 634
  686. 635 lightDir.xyz = normalize(lightDir.xyz);
  687. 636 vec3 directDiffuse;
  688. 637 vec3 directSpecular;
  689. 638
  690. 639 float hdotv = PBR_ComputeDirectLight(normal, lightDir.xyz, viewDir,
  691. 640 lightColor.rgb, fZero, Roughness, ndotv,
  692. 641 directDiffuse, directSpecular);
  693. 642
  694. 643 vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular;
  695. 644
  696. 645 gl_FragColor.rgb += directLighting * fallOff;
  697. 646 }
  698. 647
  699. 648 #if NB_PROBES >= 1
  700. 649 vec3 color1 = vec3(0.0);
  701. 650 vec3 color2 = vec3(0.0);
  702. 651 vec3 color3 = vec3(0.0);
  703. 652 float weight1 = 1.0;
  704. 653 float weight2 = 0.0;
  705. 654 float weight3 = 0.0;
  706. 655
  707. 656 float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1);
  708. 657 #if NB_PROBES >= 2
  709. 658 float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2);
  710. 659 #endif
  711. 660 #if NB_PROBES == 3
  712. 661 float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
  713. 662 #endif
  714. 663
  715. 664 #if NB_PROBES >= 2
  716. 665 float invNdf = max(1.0 - ndf,0.0);
  717. 666 float invNdf2 = max(1.0 - ndf2,0.0);
  718. 667 float sumNdf = ndf + ndf2;
  719. 668 float sumInvNdf = invNdf + invNdf2;
  720. 669 #if NB_PROBES == 3
  721. 670 float invNdf3 = max(1.0 - ndf3,0.0);
  722. 671 sumNdf += ndf3;
  723. 672 sumInvNdf += invNdf3;
  724. 673 weight3 = ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) * (invNdf3 / sumInvNdf);
  725. 674 #endif
  726. 675
  727. 676 weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) * (invNdf / sumInvNdf);
  728. 677 weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) * (invNdf2 / sumInvNdf);
  729. 678
  730. 679 float weightSum = weight1 + weight2 + weight3;
  731. 680
  732. 681 weight1 /= weightSum;
  733. 682 weight2 /= weightSum;
  734. 683 weight3 /= weightSum;
  735. 684 #endif
  736. 685
  737. 686 #ifdef USE_AMBIENT_LIGHT
  738. 687 color1.rgb *= g_AmbientLightColor.rgb;
  739. 688 color2.rgb *= g_AmbientLightColor.rgb;
  740. 689 color3.rgb *= g_AmbientLightColor.rgb;
  741. 690 #endif
  742. 691 gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);
  743. 692
  744. 693 #endif
  745. 694
  746. 695 #if defined(EMISSIVE) || defined (EMISSIVEMAP)
  747. 696 #ifdef EMISSIVEMAP
  748. 697 vec4 emissive = texture2D(m_EmissiveMap, newTexCoord);
  749. 698 #else
  750. 699 vec4 emissive = m_Emissive;
  751. 700 #endif
  752. 701 gl_FragColor += emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
  753. 702 #endif
  754. 703 gl_FragColor.a = alpha;
  755. 704
  756. 705 }
  757.  
  758. gru 06, 2021 10:38:57 AM com.jme3.anim.SkinningControl testHardwareSupported
  759. WARNING: Could not enable HW skinning due to shader compile error:
  760. com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Common/MatDefs/Light/PBRLighting.frag, defines, type=Fragment, language=GLSL150]
  761. WARNING: 0:? : '' : Version number deprecated in OGL 3.0 forward compatible context driver
  762. ERROR: 0:203: '' : syntax error: incorrect preprocessor directive
  763. WARNING: 0:203: unexpected tokens following the preprocessor directive - expected a newline
  764. ERROR: 0:235: '' : syntax error: incorrect preprocessor directive
  765. WARNING: 0:235: unexpected tokens following the preprocessor directive - expected a newline
  766. ERROR: 0:410: '' : syntax error: incorrect preprocessor directive
  767. WARNING: 0:410: unexpected tokens following the preprocessor directive - expected a newline
  768. ERROR: 0:415: '' : syntax error: incorrect preprocessor directive
  769. WARNING: 0:415: unexpected tokens following the preprocessor directive - expected a newline
  770. ERROR: 0:420: '' : syntax error: incorrect preprocessor directive
  771. WARNING: 0:420: unexpected tokens following the preprocessor directive - expected a newline
  772. ERROR: 0:648: '' : syntax error: incorrect preprocessor directive
  773. WARNING: 0:648: unexpected tokens following the preprocessor directive - expected a newline
  774. ERROR: 0:657: '' : syntax error: incorrect preprocessor directive
  775. WARNING: 0:657: unexpected tokens following the preprocessor directive - expected a newline
  776. ERROR: 0:660: '' : syntax error: incorrect preprocessor directive
  777. WARNING: 0:660: unexpected tokens following the preprocessor directive - expected a newline
  778. ERROR: 0:664: '' : syntax error: incorrect preprocessor directive
  779. WARNING: 0:664: unexpected tokens following the preprocessor directive - expected a newline
  780. ERROR: 0:669: '' : syntax error: incorrect preprocessor directive
  781. WARNING: 0:669: unexpected tokens following the preprocessor directive - expected a newline
  782. ERROR: 0:673: 'NB_PROBES' : undeclared identifier
  783.  
  784.  
  785. at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1476)
  786. at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1503)
  787. at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1567)
  788. at com.jme3.material.Material.preload(Material.java:905)
  789. at com.jme3.renderer.RenderManager.preloadScene(RenderManager.java:663)
  790. at com.jme3.renderer.RenderManager.preloadScene(RenderManager.java:654)
  791. at com.jme3.anim.SkinningControl.testHardwareSupported(SkinningControl.java:175)
  792. at com.jme3.anim.SkinningControl.controlRender(SkinningControl.java:283)
  793. at com.jme3.scene.control.AbstractControl.render(AbstractControl.java:118)
  794. at com.jme3.scene.Spatial.runControlRender(Spatial.java:757)
  795. at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:721)
  796. at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:731)
  797. at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:731)
  798. at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:710)
  799. at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1096)
  800. at com.jme3.renderer.RenderManager.render(RenderManager.java:1158)
  801. at com.jme3.app.SimpleApplication.update(SimpleApplication.java:272)
  802. at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
  803. at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
  804. at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
  805. at java.base/java.lang.Thread.run(Thread.java:834)
  806.  
  807. gru 06, 2021 10:38:57 AM com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
  808. WARNING: Bad compile of:
  809. 1 #version 150 core
  810. 2 #define FRAGMENT_SHADER 1
  811. 3 #define NORMAL_TYPE -1.0
  812. 4 #define NUM_MORPH_TARGETS 1
  813. 5 #define NUM_TARGETS_BUFFERS 2
  814. 6 #define SINGLE_PASS_LIGHTING 1
  815. 7 #define NB_LIGHTS 3
  816. 8 #extension GL_ARB_shader_texture_lod : enable
  817. 9 // -- begin import Common/ShaderLib/GLSLCompat.glsllib --
  818. 10 #if defined GL_ES
  819. 11 # define hfloat highp float
  820. 12 # define hvec2 highp vec2
  821. 13 # define hvec3 highp vec3
  822. 14 # define hvec4 highp vec4
  823. 15 # define lfloat lowp float
  824. 16 # define lvec2 lowp vec2
  825. 17 # define lvec3 lowp vec3
  826. 18 # define lvec4 lowp vec4
  827. 19 #else
  828. 20 # define hfloat float
  829. 21 # define hvec2 vec2
  830. 22 # define hvec3 vec3
  831. 23 # define hvec4 vec4
  832. 24 # define lfloat float
  833. 25 # define lvec2 vec2
  834. 26 # define lvec3 vec3
  835. 27 # define lvec4 vec4
  836. 28 #endif
  837. 29
  838. 30 #if __VERSION__ >= 130
  839. 31 # ifdef GL_ES
  840. 32 out highp vec4 outFragColor;
  841. 33 # else
  842. 34 out vec4 outFragColor;
  843. 35 #endif
  844. 36 # define texture1D texture
  845. 37 # define texture2D texture
  846. 38 # define texture3D texture
  847. 39 # define textureCube texture
  848. 40 # define texture2DLod textureLod
  849. 41 # define textureCubeLod textureLod
  850. 42 # define texture2DArray texture
  851. 43 # if defined VERTEX_SHADER
  852. 44 # define varying out
  853. 45 # define attribute in
  854. 46 # elif defined FRAGMENT_SHADER
  855. 47 # define varying in
  856. 48 # define gl_FragColor outFragColor
  857. 49 # endif
  858. 50 #else
  859. 51 # define isnan(val) !(val<0.0||val>0.0||val==0.0)
  860. 52 #endif
  861. 53
  862. 54
  863. 55 // -- end import Common/ShaderLib/GLSLCompat.glsllib --
  864. 56 // -- begin import Common/ShaderLib/PBR.glsllib --
  865. 57 #ifndef PI
  866. 58 #define PI 3.14159265358979323846264
  867. 59 #endif
  868. 60
  869. 61 //Specular fresnel computation
  870. 62 vec3 F_Shlick(float vh, vec3 F0){
  871. 63 float fresnelFact = pow(2.0, (-5.55473*vh - 6.98316) * vh);
  872. 64 return mix(F0, vec3(1.0, 1.0, 1.0), fresnelFact);
  873. 65 }
  874. 66
  875. 67 vec3 sphericalHarmonics( const in vec3 normal, const vec3 sph[9] ){
  876. 68 float x = normal.x;
  877. 69 float y = normal.y;
  878. 70 float z = normal.z;
  879. 71
  880. 72 vec3 result = (
  881. 73 sph[0] +
  882. 74
  883. 75 sph[1] * y +
  884. 76 sph[2] * z +
  885. 77 sph[3] * x +
  886. 78
  887. 79 sph[4] * y * x +
  888. 80 sph[5] * y * z +
  889. 81 sph[6] * (3.0 * z * z - 1.0) +
  890. 82 sph[7] * (z * x) +
  891. 83 sph[8] * (x*x - y*y)
  892. 84 );
  893. 85
  894. 86 return max(result, vec3(0.0));
  895. 87 }
  896. 88
  897. 89
  898. 90 float PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir,
  899. 91 vec3 lightColor, vec3 fZero, float roughness, float ndotv,
  900. 92 out vec3 outDiffuse, out vec3 outSpecular){
  901. 93 // Compute halfway vector.
  902. 94 vec3 halfVec = normalize(lightDir + viewDir);
  903. 95
  904. 96 // Compute ndotl, ndoth, vdoth terms which are needed later.
  905. 97 float ndotl = max( dot(normal, lightDir), 0.0);
  906. 98 float ndoth = max( dot(normal, halfVec), 0.0);
  907. 99 float hdotv = max( dot(viewDir, halfVec), 0.0);
  908. 100
  909. 101 // Compute diffuse using energy-conserving Lambert.
  910. 102 // Alternatively, use Oren-Nayar for really rough
  911. 103 // materials or if you have lots of processing power ...
  912. 104 outDiffuse = vec3(ndotl) * lightColor;
  913. 105
  914. 106 //cook-torrence, microfacet BRDF : http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
  915. 107
  916. 108 float alpha = roughness * roughness;
  917. 109
  918. 110 //D, GGX normaal Distribution function
  919. 111 float alpha2 = alpha * alpha;
  920. 112 float sum = ((ndoth * ndoth) * (alpha2 - 1.0) + 1.0);
  921. 113 float denom = PI * sum * sum;
  922. 114 float D = alpha2 / denom;
  923. 115
  924. 116 // Compute Fresnel function via Schlick's approximation.
  925. 117 vec3 fresnel = F_Shlick(hdotv, fZero);
  926. 118
  927. 119 //G Shchlick GGX Gometry shadowing term, k = alpha/2
  928. 120 float k = alpha * 0.5;
  929. 121
  930. 122 /*
  931. 123 //classic Schlick ggx
  932. 124 float G_V = ndotv / (ndotv * (1.0 - k) + k);
  933. 125 float G_L = ndotl / (ndotl * (1.0 - k) + k);
  934. 126 float G = ( G_V * G_L );
  935. 127
  936. 128 float specular =(D* fresnel * G) /(4 * ndotv);
  937. 129 */
  938. 130
  939. 131 // UE4 way to optimise shlick GGX Gometry shadowing term
  940. 132 //http://graphicrants.blogspot.co.uk/2013/08/specular-brdf-reference.html
  941. 133 float G_V = ndotv + sqrt( (ndotv - ndotv * k) * ndotv + k );
  942. 134 float G_L = ndotl + sqrt( (ndotl - ndotl * k) * ndotl + k );
  943. 135 // the max here is to avoid division by 0 that may cause some small glitches.
  944. 136 float G = 1.0/max( G_V * G_L ,0.01);
  945. 137
  946. 138 float specular = D * G * ndotl;
  947. 139
  948. 140 outSpecular = vec3(specular) * fresnel * lightColor;
  949. 141 return hdotv;
  950. 142 }
  951. 143
  952. 144 vec3 integrateBRDFApprox( const in vec3 specular, float roughness, float NoV ){
  953. 145 const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022 );
  954. 146 const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04 );
  955. 147 vec4 r = roughness * c0 + c1;
  956. 148 float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;
  957. 149 vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
  958. 150 return specular * AB.x + AB.y;
  959. 151 }
  960. 152
  961. 153 // from Sebastien Lagarde https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf page 69
  962. 154 vec3 getSpecularDominantDir(const in vec3 N, const in vec3 R, const in float realRoughness){
  963. 155 vec3 dominant;
  964. 156
  965. 157 float smoothness = 1.0 - realRoughness;
  966. 158 float lerpFactor = smoothness * (sqrt(smoothness) + realRoughness);
  967. 159 // The result is not normalized as we fetch in a cubemap
  968. 160 dominant = mix(N, R, lerpFactor);
  969. 161
  970. 162 return dominant;
  971. 163 }
  972. 164
  973. 165 vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  974. 166 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  975. 167 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb;
  976. 168 vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg;
  977. 169 return PrefilteredColor * ( SpecularColor * EnvBRDF.x+ EnvBRDF.y );
  978. 170 }
  979. 171
  980. 172 vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  981. 173 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  982. 174 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz, Lod).rgb;
  983. 175 return PrefilteredColor * integrateBRDFApprox(SpecularColor, Roughness, ndotv);
  984. 176 }
  985. 177
  986. 178
  987. 179 float renderProbe(vec3 viewDir, vec3 worldPos, vec3 normal, vec3 norm, float Roughness, vec4 diffuseColor, vec4 specularColor, float ndotv, vec3 ao, mat4 lightProbeData,vec3 shCoeffs[9],samplerCube prefEnvMap, inout vec3 color ){
  988. 180
  989. 181 // lightProbeData is a mat4 with this layout
  990. 182 // 3x3 rot mat|
  991. 183 // 0 1 2 | 3
  992. 184 // 0 | ax bx cx | px | )
  993. 185 // 1 | ay by cy | py | probe position
  994. 186 // 2 | az bz cz | pz | )
  995. 187 // --|----------|
  996. 188 // 3 | sx sy sz sp | -> 1/probe radius + nbMipMaps
  997. 189 // --scale--
  998. 190 // parallax fix for spherical / obb bounds and probe blending from
  999. 191 // from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
  1000. 192 vec3 rv = reflect(-viewDir, normal);
  1001. 193 vec4 probePos = lightProbeData[3];
  1002. 194 float invRadius = fract( probePos.w);
  1003. 195 float nbMipMaps = probePos.w - invRadius;
  1004. 196 vec3 direction = worldPos - probePos.xyz;
  1005. 197 float ndf = 0.0;
  1006. 198
  1007. 199 if(lightProbeData[0][3] != 0.0){
  1008. 200 // oriented box probe
  1009. 201 mat3 wToLocalRot = mat3(lightProbeData);
  1010. 202 wToLocalRot = inverse(wToLocalRot);
  1011. 203 vec3 scale = vec3(lightProbeData[0][3], lightProbeData[1][3], lightProbeData[2][3]);
  1012. 204 #if NB_PROBES >= 2
  1013. 205 // probe blending
  1014. 206 // compute fragment position in probe local space
  1015. 207 vec3 localPos = wToLocalRot * worldPos;
  1016. 208 localPos -= probePos.xyz;
  1017. 209 // compute normalized distance field
  1018. 210 vec3 localDir = abs(localPos);
  1019. 211 localDir /= scale;
  1020. 212 ndf = max(max(localDir.x, localDir.y), localDir.z);
  1021. 213 #endif
  1022. 214 // parallax fix
  1023. 215 vec3 rayLs = wToLocalRot * rv;
  1024. 216 rayLs /= scale;
  1025. 217
  1026. 218 vec3 positionLs = worldPos - probePos.xyz;
  1027. 219 positionLs = wToLocalRot * positionLs;
  1028. 220 positionLs /= scale;
  1029. 221
  1030. 222 vec3 unit = vec3(1.0);
  1031. 223 vec3 firstPlaneIntersect = (unit - positionLs) / rayLs;
  1032. 224 vec3 secondPlaneIntersect = (-unit - positionLs) / rayLs;
  1033. 225 vec3 furthestPlane = max(firstPlaneIntersect, secondPlaneIntersect);
  1034. 226 float distance = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
  1035. 227
  1036. 228 vec3 intersectPositionWs = worldPos + rv * distance;
  1037. 229 rv = intersectPositionWs - probePos.xyz;
  1038. 230
  1039. 231 } else {
  1040. 232 // spherical probe
  1041. 233 // paralax fix
  1042. 234 rv = invRadius * direction + rv;
  1043. 235
  1044. 236 #if NB_PROBES >= 2
  1045. 237 // probe blending
  1046. 238 float dist = sqrt(dot(direction, direction));
  1047. 239 ndf = dist * invRadius;
  1048. 240 #endif
  1049. 241 }
  1050. 242
  1051. 243 vec3 indirectDiffuse = vec3(0.0);
  1052. 244 vec3 indirectSpecular = vec3(0.0);
  1053. 245 indirectDiffuse = sphericalHarmonics(normal.xyz, shCoeffs) * diffuseColor.rgb;
  1054. 246 vec3 dominantR = getSpecularDominantDir( normal, rv.xyz, Roughness * Roughness );
  1055. 247 indirectSpecular = ApproximateSpecularIBLPolynomial(prefEnvMap, specularColor.rgb, Roughness, ndotv, dominantR, nbMipMaps);
  1056. 248
  1057. 249 #ifdef HORIZON_FADE
  1058. 250 //horizon fade from http://marmosetco.tumblr.com/post/81245981087
  1059. 251 float horiz = dot(rv, norm);
  1060. 252 float horizFadePower = 1.0 - Roughness;
  1061. 253 horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
  1062. 254 horiz *= horiz;
  1063. 255 indirectSpecular *= vec3(horiz);
  1064. 256 #endif
  1065. 257
  1066. 258 vec3 indirectLighting = (indirectDiffuse + indirectSpecular) * ao;
  1067. 259
  1068. 260 color = indirectLighting * step( 0.0, probePos.w);
  1069. 261 return ndf;
  1070. 262 }
  1071. 263
  1072. 264
  1073. 265
  1074. 266
  1075. 267
  1076. 268 // -- end import Common/ShaderLib/PBR.glsllib --
  1077. 269 // -- begin import Common/ShaderLib/Parallax.glsllib --
  1078. 270 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
  1079. 271 vec2 steepParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  1080. 272 vec2 vParallaxDirection = normalize( vViewDir.xy );
  1081. 273
  1082. 274 // The length of this vector determines the furthest amount of displacement: (Ati's comment)
  1083. 275 float fLength = length( vViewDir );
  1084. 276 float fParallaxLength = sqrt( fLength * fLength - vViewDir.z * vViewDir.z ) / vViewDir.z;
  1085. 277
  1086. 278 // Compute the actual reverse parallax displacement vector: (Ati's comment)
  1087. 279 vec2 vParallaxOffsetTS = vParallaxDirection * fParallaxLength;
  1088. 280
  1089. 281 // Need to scale the amount of displacement to account for different height ranges
  1090. 282 // in height maps. This is controlled by an artist-editable parameter: (Ati's comment)
  1091. 283 parallaxScale *=0.3;
  1092. 284 vParallaxOffsetTS *= parallaxScale;
  1093. 285
  1094. 286 vec3 eyeDir = normalize(vViewDir).xyz;
  1095. 287
  1096. 288 float nMinSamples = 6.0;
  1097. 289 float nMaxSamples = 1000.0 * parallaxScale;
  1098. 290 float nNumSamples = mix( nMinSamples, nMaxSamples, 1.0 - eyeDir.z ); //In reference shader: int nNumSamples = (int)(lerp( nMinSamples, nMaxSamples, dot( eyeDirWS, N ) ));
  1099. 291 float fStepSize = 1.0 / nNumSamples;
  1100. 292 float fCurrHeight = 0.0;
  1101. 293 float fPrevHeight = 1.0;
  1102. 294 float fNextHeight = 0.0;
  1103. 295 float nStepIndex = 0.0;
  1104. 296 vec2 vTexOffsetPerStep = fStepSize * vParallaxOffsetTS;
  1105. 297 vec2 vTexCurrentOffset = texCoord;
  1106. 298 float fCurrentBound = 1.0;
  1107. 299 float fParallaxAmount = 0.0;
  1108. 300
  1109. 301 while ( nStepIndex < nNumSamples && fCurrHeight <= fCurrentBound ) {
  1110. 302 vTexCurrentOffset -= vTexOffsetPerStep;
  1111. 303 fPrevHeight = fCurrHeight;
  1112. 304
  1113. 305
  1114. 306 #ifdef NORMALMAP_PARALLAX
  1115. 307 //parallax map is stored in the alpha channel of the normal map
  1116. 308 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).a;
  1117. 309 #else
  1118. 310 //parallax map is a texture
  1119. 311 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).r;
  1120. 312 #endif
  1121. 313
  1122. 314 fCurrentBound -= fStepSize;
  1123. 315 nStepIndex+=1.0;
  1124. 316 }
  1125. 317 vec2 pt1 = vec2( fCurrentBound, fCurrHeight );
  1126. 318 vec2 pt2 = vec2( fCurrentBound + fStepSize, fPrevHeight );
  1127. 319
  1128. 320 float fDelta2 = pt2.x - pt2.y;
  1129. 321 float fDelta1 = pt1.x - pt1.y;
  1130. 322
  1131. 323 float fDenominator = fDelta2 - fDelta1;
  1132. 324
  1133. 325 fParallaxAmount = (pt1.x * fDelta2 - pt2.x * fDelta1 ) / fDenominator;
  1134. 326
  1135. 327 vec2 vParallaxOffset = vParallaxOffsetTS * (1.0 - fParallaxAmount );
  1136. 328 return texCoord - vParallaxOffset;
  1137. 329 }
  1138. 330
  1139. 331 vec2 classicParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  1140. 332 float h;
  1141. 333 #ifdef NORMALMAP_PARALLAX
  1142. 334 //parallax map is stored in the alpha channel of the normal map
  1143. 335 h = texture2D(parallaxMap, texCoord).a;
  1144. 336 #else
  1145. 337 //parallax map is a texture
  1146. 338 h = texture2D(parallaxMap, texCoord).r;
  1147. 339 #endif
  1148. 340 float heightScale = parallaxScale;
  1149. 341 float heightBias = heightScale* -0.6;
  1150. 342 vec3 normView = normalize(vViewDir);
  1151. 343 h = (h * heightScale + heightBias) * normView.z;
  1152. 344 return texCoord + (h * normView.xy);
  1153. 345 }
  1154. 346 #endif
  1155. 347 // -- end import Common/ShaderLib/Parallax.glsllib --
  1156. 348 // -- begin import Common/ShaderLib/Lighting.glsllib --
  1157. 349 /*Common function for light calculations*/
  1158. 350
  1159. 351
  1160. 352 /*
  1161. 353 * Computes light direction
  1162. 354 * lightType should be 0.0,1.0,2.0, repectively for Directional, point and spot lights.
  1163. 355 * Outputs the light direction and the light half vector.
  1164. 356 */
  1165. 357 void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out vec4 lightDir, out vec3 lightVec){
  1166. 358 float posLight = step(0.5, lightType);
  1167. 359 vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
  1168. 360 lightVec = tempVec;
  1169. 361 float dist = length(tempVec);
  1170. 362 #ifdef SRGB
  1171. 363 lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
  1172. 364 lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
  1173. 365 #else
  1174. 366 lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
  1175. 367 #endif
  1176. 368 lightDir.xyz = tempVec / vec3(dist);
  1177. 369 }
  1178. 370
  1179. 371 /*
  1180. 372 * Computes the spot falloff for a spotlight
  1181. 373 */
  1182. 374 float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector){
  1183. 375 vec3 L=normalize(lightVector);
  1184. 376 vec3 spotdir = normalize(lightDirection.xyz);
  1185. 377 float curAngleCos = dot(-L, spotdir);
  1186. 378 float innerAngleCos = floor(lightDirection.w) * 0.001;
  1187. 379 float outerAngleCos = fract(lightDirection.w);
  1188. 380 float innerMinusOuter = innerAngleCos - outerAngleCos;
  1189. 381 float falloff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, step(lightDirection.w, 0.001), 1.0);
  1190. 382
  1191. 383 #ifdef SRGB
  1192. 384 // Use quadratic falloff (notice the ^4)
  1193. 385 return pow(clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0), 4.0);
  1194. 386 #else
  1195. 387 // Use linear falloff
  1196. 388 return falloff;
  1197. 389 #endif
  1198. 390 }
  1199. 391
  1200. 392 // -- end import Common/ShaderLib/Lighting.glsllib --
  1201. 393
  1202. 394 varying vec2 texCoord;
  1203. 395 #ifdef SEPARATE_TEXCOORD
  1204. 396 varying vec2 texCoord2;
  1205. 397 #endif
  1206. 398
  1207. 399 varying vec4 Color;
  1208. 400
  1209. 401 uniform vec4 g_LightData[NB_LIGHTS];
  1210. 402 uniform vec3 g_CameraPosition;
  1211. 403 uniform vec4 g_AmbientLightColor;
  1212. 404
  1213. 405 uniform float m_Roughness;
  1214. 406 uniform float m_Metallic;
  1215. 407
  1216. 408 varying vec3 wPosition;
  1217. 409
  1218. 410
  1219. 411 #if NB_PROBES >= 1
  1220. 412 uniform samplerCube g_PrefEnvMap;
  1221. 413 uniform vec3 g_ShCoeffs[9];
  1222. 414 uniform mat4 g_LightProbeData;
  1223. 415 #endif
  1224. 416 #if NB_PROBES >= 2
  1225. 417 uniform samplerCube g_PrefEnvMap2;
  1226. 418 uniform vec3 g_ShCoeffs2[9];
  1227. 419 uniform mat4 g_LightProbeData2;
  1228. 420 #endif
  1229. 421 #if NB_PROBES == 3
  1230. 422 uniform samplerCube g_PrefEnvMap3;
  1231. 423 uniform vec3 g_ShCoeffs3[9];
  1232. 424 uniform mat4 g_LightProbeData3;
  1233. 425 #endif
  1234. 426
  1235. 427 #ifdef BASECOLORMAP
  1236. 428 uniform sampler2D m_BaseColorMap;
  1237. 429 #endif
  1238. 430
  1239. 431 #ifdef USE_PACKED_MR
  1240. 432 uniform sampler2D m_MetallicRoughnessMap;
  1241. 433 #else
  1242. 434 #ifdef METALLICMAP
  1243. 435 uniform sampler2D m_MetallicMap;
  1244. 436 #endif
  1245. 437 #ifdef ROUGHNESSMAP
  1246. 438 uniform sampler2D m_RoughnessMap;
  1247. 439 #endif
  1248. 440 #endif
  1249. 441
  1250. 442 #ifdef EMISSIVE
  1251. 443 uniform vec4 m_Emissive;
  1252. 444 #endif
  1253. 445 #ifdef EMISSIVEMAP
  1254. 446 uniform sampler2D m_EmissiveMap;
  1255. 447 #endif
  1256. 448 #if defined(EMISSIVE) || defined(EMISSIVEMAP)
  1257. 449 uniform float m_EmissivePower;
  1258. 450 uniform float m_EmissiveIntensity;
  1259. 451 #endif
  1260. 452
  1261. 453 #ifdef SPECGLOSSPIPELINE
  1262. 454
  1263. 455 uniform vec4 m_Specular;
  1264. 456 uniform float m_Glossiness;
  1265. 457 #ifdef USE_PACKED_SG
  1266. 458 uniform sampler2D m_SpecularGlossinessMap;
  1267. 459 #else
  1268. 460 uniform sampler2D m_SpecularMap;
  1269. 461 uniform sampler2D m_GlossinessMap;
  1270. 462 #endif
  1271. 463 #endif
  1272. 464
  1273. 465 #ifdef PARALLAXMAP
  1274. 466 uniform sampler2D m_ParallaxMap;
  1275. 467 #endif
  1276. 468 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  1277. 469 uniform float m_ParallaxHeight;
  1278. 470 #endif
  1279. 471
  1280. 472 #ifdef LIGHTMAP
  1281. 473 uniform sampler2D m_LightMap;
  1282. 474 #endif
  1283. 475
  1284. 476 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  1285. 477 uniform sampler2D m_NormalMap;
  1286. 478 varying vec4 wTangent;
  1287. 479 #endif
  1288. 480 varying vec3 wNormal;
  1289. 481
  1290. 482 #ifdef DISCARD_ALPHA
  1291. 483 uniform float m_AlphaDiscardThreshold;
  1292. 484 #endif
  1293. 485
  1294. 486 void main(){
  1295. 487 vec2 newTexCoord;
  1296. 488 vec3 viewDir = normalize(g_CameraPosition - wPosition);
  1297. 489
  1298. 490 vec3 norm = normalize(wNormal);
  1299. 491 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  1300. 492 vec3 tan = normalize(wTangent.xyz);
  1301. 493 mat3 tbnMat = mat3(tan, wTangent.w * cross( (norm), (tan)), norm);
  1302. 494 #endif
  1303. 495
  1304. 496 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  1305. 497 vec3 vViewDir = viewDir * tbnMat;
  1306. 498 #ifdef STEEP_PARALLAX
  1307. 499 #ifdef NORMALMAP_PARALLAX
  1308. 500 //parallax map is stored in the alpha channel of the normal map
  1309. 501 newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  1310. 502 #else
  1311. 503 //parallax map is a texture
  1312. 504 newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  1313. 505 #endif
  1314. 506 #else
  1315. 507 #ifdef NORMALMAP_PARALLAX
  1316. 508 //parallax map is stored in the alpha channel of the normal map
  1317. 509 newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  1318. 510 #else
  1319. 511 //parallax map is a texture
  1320. 512 newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  1321. 513 #endif
  1322. 514 #endif
  1323. 515 #else
  1324. 516 newTexCoord = texCoord;
  1325. 517 #endif
  1326. 518
  1327. 519 #ifdef BASECOLORMAP
  1328. 520 vec4 albedo = texture2D(m_BaseColorMap, newTexCoord) * Color;
  1329. 521 #else
  1330. 522 vec4 albedo = Color;
  1331. 523 #endif
  1332. 524
  1333. 525 #ifdef USE_PACKED_MR
  1334. 526 vec2 rm = texture2D(m_MetallicRoughnessMap, newTexCoord).gb;
  1335. 527 float Roughness = rm.x * max(m_Roughness, 1e-4);
  1336. 528 float Metallic = rm.y * max(m_Metallic, 0.0);
  1337. 529 #else
  1338. 530 #ifdef ROUGHNESSMAP
  1339. 531 float Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness, 1e-4);
  1340. 532 #else
  1341. 533 float Roughness = max(m_Roughness, 1e-4);
  1342. 534 #endif
  1343. 535 #ifdef METALLICMAP
  1344. 536 float Metallic = texture2D(m_MetallicMap, newTexCoord).r * max(m_Metallic, 0.0);
  1345. 537 #else
  1346. 538 float Metallic = max(m_Metallic, 0.0);
  1347. 539 #endif
  1348. 540 #endif
  1349. 541
  1350. 542 float alpha = albedo.a;
  1351. 543
  1352. 544 #ifdef DISCARD_ALPHA
  1353. 545 if(alpha < m_AlphaDiscardThreshold){
  1354. 546 discard;
  1355. 547 }
  1356. 548 #endif
  1357. 549
  1358. 550 // ***********************
  1359. 551 // Read from textures
  1360. 552 // ***********************
  1361. 553 #if defined(NORMALMAP)
  1362. 554 vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
  1363. 555 //Note the -2.0 and -1.0. We invert the green channel of the normal map,
  1364. 556 //as it's complient with normal maps generated with blender.
  1365. 557 //see http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898
  1366. 558 //for more explanation.
  1367. 559 vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)));
  1368. 560 normal = normalize(tbnMat * normal);
  1369. 561 //normal = normalize(normal * inverse(tbnMat));
  1370. 562 #else
  1371. 563 vec3 normal = norm;
  1372. 564 #endif
  1373. 565
  1374. 566 #ifdef SPECGLOSSPIPELINE
  1375. 567
  1376. 568 #ifdef USE_PACKED_SG
  1377. 569 vec4 specularColor = texture2D(m_SpecularGlossinessMap, newTexCoord);
  1378. 570 float glossiness = specularColor.a * m_Glossiness;
  1379. 571 specularColor *= m_Specular;
  1380. 572 #else
  1381. 573 #ifdef SPECULARMAP
  1382. 574 vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
  1383. 575 #else
  1384. 576 vec4 specularColor = vec4(1.0);
  1385. 577 #endif
  1386. 578 #ifdef GLOSSINESSMAP
  1387. 579 float glossiness = texture2D(m_GlossinessMap, newTexCoord).r * m_Glossiness;
  1388. 580 #else
  1389. 581 float glossiness = m_Glossiness;
  1390. 582 #endif
  1391. 583 specularColor *= m_Specular;
  1392. 584 #endif
  1393. 585 vec4 diffuseColor = albedo;// * (1.0 - max(max(specularColor.r, specularColor.g), specularColor.b));
  1394. 586 Roughness = 1.0 - glossiness;
  1395. 587 vec3 fZero = specularColor.xyz;
  1396. 588 #else
  1397. 589 float specular = 0.5;
  1398. 590 float nonMetalSpec = 0.08 * specular;
  1399. 591 vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
  1400. 592 vec4 diffuseColor = albedo - albedo * Metallic;
  1401. 593 vec3 fZero = vec3(specular);
  1402. 594 #endif
  1403. 595
  1404. 596 gl_FragColor.rgb = vec3(0.0);
  1405. 597 vec3 ao = vec3(1.0);
  1406. 598
  1407. 599 #ifdef LIGHTMAP
  1408. 600 vec3 lightMapColor;
  1409. 601 #ifdef SEPARATE_TEXCOORD
  1410. 602 lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
  1411. 603 #else
  1412. 604 lightMapColor = texture2D(m_LightMap, texCoord).rgb;
  1413. 605 #endif
  1414. 606 #ifdef AO_MAP
  1415. 607 lightMapColor.gb = lightMapColor.rr;
  1416. 608 ao = lightMapColor;
  1417. 609 #else
  1418. 610 gl_FragColor.rgb += diffuseColor.rgb * lightMapColor;
  1419. 611 #endif
  1420. 612 specularColor.rgb *= lightMapColor;
  1421. 613 #endif
  1422. 614
  1423. 615
  1424. 616 float ndotv = max( dot( normal, viewDir ),0.0);
  1425. 617 for( int i = 0;i < NB_LIGHTS; i+=3){
  1426. 618 vec4 lightColor = g_LightData[i];
  1427. 619 vec4 lightData1 = g_LightData[i+1];
  1428. 620 vec4 lightDir;
  1429. 621 vec3 lightVec;
  1430. 622 lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec);
  1431. 623
  1432. 624 float fallOff = 1.0;
  1433. 625 #if __VERSION__ >= 110
  1434. 626 // allow use of control flow
  1435. 627 if(lightColor.w > 1.0){
  1436. 628 #endif
  1437. 629 fallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
  1438. 630 #if __VERSION__ >= 110
  1439. 631 }
  1440. 632 #endif
  1441. 633 //point light attenuation
  1442. 634 fallOff *= lightDir.w;
  1443. 635
  1444. 636 lightDir.xyz = normalize(lightDir.xyz);
  1445. 637 vec3 directDiffuse;
  1446. 638 vec3 directSpecular;
  1447. 639
  1448. 640 float hdotv = PBR_ComputeDirectLight(normal, lightDir.xyz, viewDir,
  1449. 641 lightColor.rgb, fZero, Roughness, ndotv,
  1450. 642 directDiffuse, directSpecular);
  1451. 643
  1452. 644 vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular;
  1453. 645
  1454. 646 gl_FragColor.rgb += directLighting * fallOff;
  1455. 647 }
  1456. 648
  1457. 649 #if NB_PROBES >= 1
  1458. 650 vec3 color1 = vec3(0.0);
  1459. 651 vec3 color2 = vec3(0.0);
  1460. 652 vec3 color3 = vec3(0.0);
  1461. 653 float weight1 = 1.0;
  1462. 654 float weight2 = 0.0;
  1463. 655 float weight3 = 0.0;
  1464. 656
  1465. 657 float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1);
  1466. 658 #if NB_PROBES >= 2
  1467. 659 float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2);
  1468. 660 #endif
  1469. 661 #if NB_PROBES == 3
  1470. 662 float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
  1471. 663 #endif
  1472. 664
  1473. 665 #if NB_PROBES >= 2
  1474. 666 float invNdf = max(1.0 - ndf,0.0);
  1475. 667 float invNdf2 = max(1.0 - ndf2,0.0);
  1476. 668 float sumNdf = ndf + ndf2;
  1477. 669 float sumInvNdf = invNdf + invNdf2;
  1478. 670 #if NB_PROBES == 3
  1479. 671 float invNdf3 = max(1.0 - ndf3,0.0);
  1480. 672 sumNdf += ndf3;
  1481. 673 sumInvNdf += invNdf3;
  1482. 674 weight3 = ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) * (invNdf3 / sumInvNdf);
  1483. 675 #endif
  1484. 676
  1485. 677 weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) * (invNdf / sumInvNdf);
  1486. 678 weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) * (invNdf2 / sumInvNdf);
  1487. 679
  1488. 680 float weightSum = weight1 + weight2 + weight3;
  1489. 681
  1490. 682 weight1 /= weightSum;
  1491. 683 weight2 /= weightSum;
  1492. 684 weight3 /= weightSum;
  1493. 685 #endif
  1494. 686
  1495. 687 #ifdef USE_AMBIENT_LIGHT
  1496. 688 color1.rgb *= g_AmbientLightColor.rgb;
  1497. 689 color2.rgb *= g_AmbientLightColor.rgb;
  1498. 690 color3.rgb *= g_AmbientLightColor.rgb;
  1499. 691 #endif
  1500. 692 gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);
  1501. 693
  1502. 694 #endif
  1503. 695
  1504. 696 #if defined(EMISSIVE) || defined (EMISSIVEMAP)
  1505. 697 #ifdef EMISSIVEMAP
  1506. 698 vec4 emissive = texture2D(m_EmissiveMap, newTexCoord);
  1507. 699 #else
  1508. 700 vec4 emissive = m_Emissive;
  1509. 701 #endif
  1510. 702 gl_FragColor += emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
  1511. 703 #endif
  1512. 704 gl_FragColor.a = alpha;
  1513. 705
  1514. 706 }
  1515.  
  1516. BUILD SUCCESSFUL (total time: 8 seconds)
  1517.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement