Advertisement
dasvinni

Fragment fluid

Feb 27th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3.  
  4. layout(binding = 1) uniform sampler2D texSampler;
  5.  
  6. struct Vertex{
  7.     vec3 pos;
  8.     vec3 color;
  9.     vec2 texCoord;
  10. };
  11.  
  12. layout(binding = 2) buffer storage{
  13.     Vertex vertices[];
  14. } st;
  15.  
  16. layout(location = 0) in vec3 fragPos;
  17. layout(location = 1) in vec2 fragTexCoord;
  18. layout(location = 2) flat in int index;
  19.  
  20. layout(location = 0) out vec4 outColor;
  21.  
  22. float e = 2.718281828;
  23. float iso = 0.2;
  24. float k = 4.0;
  25.  
  26. float skalarFeld(vec3 x){
  27.     float s=0;
  28.     for(int i=0; i<16; ++i){
  29.         s = s + pow(e, -k * length(x - st.vertices[i].pos));
  30.     }
  31.     return s;
  32. }
  33.  
  34. void main() {
  35.  
  36.     for( float f=0; f <= 2.0; f=f+0.05){
  37.         float s=skalarFeld(fragPos * f);
  38.         if(s >= iso){
  39.             outColor = vec4(fragPos, 1.0); // * texture(texSampler, fragTexCoord);
  40.             break;
  41.         }else
  42.         {
  43.             outColor = vec4(1.0, 1.0, 1.0, 1.0);
  44.             outColor = vec4(s, s, s, 1.0);
  45.             break;
  46.         }
  47.     }
  48.  
  49.  
  50.     //outColor = vec4(st.vertices[index].pos, 1.0);
  51.     //outColor = vec4(fragPos, 1.0);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement