Advertisement
Guest User

Untitled

a guest
Mar 16th, 2022
28
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None
  1. mat3 GetTBN();
  2.  
  3. int tex_heightmap=0;
  4.  
  5. Material material;
  6.  
  7. void SetupMaterial(inout Material material)
  8. {
  9. mat3 tbn = GetTBN();
  10.  
  11. vec2 texCoord = vTexCoord.st;
  12.  
  13. const float pi = 3.14159265358979323846;
  14. vec2 offset = vec2(0.0,0.0);
  15.  
  16. offset.y = 0.5 + sin(pi * 1.0 * (texCoord.y + (timer * 0.2) * 0.61 + 900.0/8192.0)) + sin(pi * 2.0 * (texCoord.x * 1.0 + (timer * 0.2) * 0.36 + 300.0/8192.0)) + (timer*0.25);
  17. offset.x = 0.5 + sin(pi * 1.0 * (texCoord.y + (timer * 0.2) * 0.49 + 700.0/8192.0)) + sin(pi * 2.0 * (texCoord.x * 1.0 + (timer * 0.2) * 0.49 + 1200.0/8192.0)) + (timer*0.25);
  18.  
  19. texCoord += offset * 0.025;
  20.  
  21. material.Base = getTexel(texCoord);
  22.  
  23. vec4 addEnv = texture(tex_envmap, (normalize(uCameraPos.xyz - pixelpos.xyz).xy) + (texCoord.xy * 0.1) + (0.05 * (1.0 + (0.5 * (sin(timer * 0.05)))) + (1.0 + (0.5 * (cos(timer * 0.05))))));
  24.  
  25. material.Base = (material.Base*0.7) + (addEnv*0.35);
  26.  
  27. }
  28.  
  29. mat3 GetTBN()
  30. {
  31. vec3 n = normalize(vWorldNormal.xyz);
  32. vec3 p = pixelpos.xyz;
  33. vec2 uv = vTexCoord.st;
  34.  
  35. // get edge vectors of the pixel triangle
  36. vec3 dp1 = dFdx(p);
  37. vec3 dp2 = dFdy(p);
  38. vec2 duv1 = dFdx(uv);
  39. vec2 duv2 = dFdy(uv);
  40.  
  41. // solve the linear system
  42. vec3 dp2perp = cross(n, dp2); // cross(dp2, n);
  43. vec3 dp1perp = cross(dp1, n); // cross(n, dp1);
  44. vec3 t = dp2perp * duv1.x + dp1perp * duv2.x;
  45. vec3 b = dp2perp * duv1.y + dp1perp * duv2.y;
  46.  
  47. // construct a scale-invariant frame
  48. float invmax = inversesqrt(max(dot(t,t), dot(b,b)));
  49. return mat3(t * invmax, b * invmax, n);
  50. }
Advertisement
RAW Paste Data Copied
Advertisement