fragment.fs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #version 430
  2. layout (binding = 0) uniform sampler3D noiseSamp;
  3. layout (binding = 1) uniform sampler2D textureSamp;
  4. layout (binding = 2) uniform sampler2D bumpSamp;
  5. layout (binding = 3) uniform sampler2D normalSamp;
  6. uniform float height;
  7. in vec3 varPositionG;
  8. in vec2 varTextureG;
  9. in vec3 tangentLightPosG;
  10. in vec3 tangentViewPosG;
  11. in vec3 tangentFragPosG;
  12. uniform vec3 viewPos;
  13. out vec4 color;
  14. const vec3 light = vec3(-0.746, -0.373, -0.224);
  15. uniform float heightScale;
  16. vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir) {
  17. float height = texture(bumpSamp, texCoords, 0.0).r;
  18. vec2 p = viewDir.xy / viewDir.z * (height * heightScale);
  19. return texCoords - p;
  20. }
  21. void main(void) {
  22. vec2 tex = varTextureG + vec2(0.0, height);
  23. //float depth = texture(textureSamp, tex).x;
  24. //vec3 dir = (camPosition - varPositionG) * depth * 0.05;
  25. //vec3 f = texture(textureSamp, tex).xyz;
  26. //float l = max(dot(light, varNormalG), 0.0) * 0.7 + 0.3;
  27. //color = vec4(f, 1.0);
  28. // offset texture coordinates with Parallax Mapping
  29. vec3 viewDir = normalize(tangentViewPosG - tangentFragPosG);
  30. vec2 texCoords = ParallaxMapping(tex.xy, viewDir);
  31. // then sample textures with new texture coords
  32. //vec3 diffuse = texture(diffuseMap, texCoords);
  33. vec3 normal = texture(normalSamp, texCoords).xyz;
  34. normal = normalize(normal * 2.0 - 1.0);
  35. float l = max(dot(-light, normal), 0.0) * 0.7 + 0.3;
  36. color = vec4(texture(textureSamp, texCoords).xyz * l, 1.0);
  37. }