Advertisement
Guest User

Untitled

a guest
Oct 17th, 2014
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. precision highp float;
  2.  
  3. // Compiler should remove unneeded stuff
  4. uniform vec3 view_position;
  5.  
  6. uniform vec3 light_globalAmbient;
  7.  
  8. varying vec3 vPositionW;
  9. varying vec3 vNormalW;
  10. varying vec3 vTangentW;
  11. varying vec3 vBinormalW;
  12. varying vec2 vUv0;
  13. varying vec2 vUv1;
  14. varying vec4 vVertexColor;
  15. varying vec3 vNormalV;
  16.  
  17. struct psInternalData {
  18. vec3 albedo;
  19. vec3 specularity;
  20. float glossiness;
  21. vec3 emission;
  22. vec3 normalW;
  23. mat3 TBN;
  24. vec3 viewDirW;
  25. vec3 reflDirW;
  26. vec3 diffuseLight;
  27. vec3 specularLight;
  28. float alpha;
  29. vec3 lightDirNormW;
  30. vec3 lightDirW;
  31. float atten;
  32. vec3 shadowCoord;
  33. vec2 uvOffset;
  34. };
  35.  
  36. void getViewDir(inout psInternalData data) {
  37. data.viewDirW = normalize(view_position - vPositionW);
  38. }
  39.  
  40. void getReflDir(inout psInternalData data) {
  41. data.reflDirW = normalize(-reflect(data.viewDirW, data.normalW));
  42. }
  43.  
  44. void addAmbientConstant(inout psInternalData data) {
  45. data.diffuseLight += light_globalAmbient;
  46. }
  47.  
  48. void getLightDirPoint(inout psInternalData data, vec3 lightPosW) {
  49. data.lightDirW = vPositionW - lightPosW;
  50. data.lightDirNormW = normalize(data.lightDirW);
  51. }
  52.  
  53. float getFalloffLinear(inout psInternalData data, float lightRadius) {
  54. float d = length(data.lightDirW);
  55. return max(((lightRadius - d) / lightRadius), 0.0);
  56. }
  57.  
  58. float getFalloffInvSquared(inout psInternalData data) {
  59. float sqrDist = dot(data.lightDirW, data.lightDirW);
  60. return 1.0 / sqrDist;
  61. }
  62.  
  63. float getSpotEffect(inout psInternalData data, vec3 lightSpotDirW, float lightInnerConeAngle, float lightOuterConeAngle) {
  64. float cosAngle = dot(data.lightDirNormW, lightSpotDirW);
  65. return smoothstep(lightOuterConeAngle, lightInnerConeAngle, cosAngle);
  66. }
  67.  
  68. uniform vec3 light0_color;
  69. uniform vec3 light0_direction;
  70. uniform vec3 fog_color;
  71. uniform float fog_start;
  72. uniform float fog_end;
  73.  
  74.  
  75. void getNormal(inout psInternalData data) {
  76. data.normalW = normalize(vNormalW);
  77. }
  78.  
  79. vec4 texture2DAlbedo(sampler2D tex, vec2 uv) {
  80. return texture2D(tex, uv);
  81. }
  82.  
  83. vec3 gammaCorrectOutput(vec3 color) {
  84. return color;
  85. }
  86.  
  87. uniform sampler2D texture_diffuseMap;
  88. void getAlbedo(inout psInternalData data) {
  89. vec4 tex = texture2DAlbedo(texture_diffuseMap, vUv0);
  90. data.albedo = tex.rgb;
  91. }
  92.  
  93. uniform float material_shininess;
  94. void getGlossiness(inout psInternalData data) {
  95. // Hack: On Mac OS X, calling pow with zero for the exponent generates hideous artifacts so bias up a little
  96. data.glossiness = material_shininess + 0.0001;
  97. }
  98.  
  99. uniform float material_opacity;
  100. void getOpacity(inout psInternalData data) {
  101. data.alpha = material_opacity;
  102. }
  103.  
  104. uniform vec3 material_emissive;
  105. vec3 getEmission(inout psInternalData data) {
  106. return material_emissive;
  107. }
  108.  
  109. float getLightDiffuse(inout psInternalData data) {
  110. return max(dot(data.normalW, -data.lightDirNormW), 0.0);
  111. }
  112.  
  113. vec3 combineColor(inout psInternalData data) {
  114. return data.albedo * data.diffuseLight;
  115. }
  116.  
  117.  
  118. void main(void) {
  119. psInternalData data;
  120. data.diffuseLight = vec3(0);
  121. data.specularLight = vec3(0);
  122.  
  123. getNormal(data);
  124. getAlbedo(data);
  125. getOpacity(data);
  126. addAmbientConstant(data);
  127.  
  128. data.lightDirNormW = light0_direction;
  129. data.atten = getLightDiffuse(data);
  130. data.diffuseLight += data.atten * light0_color;
  131.  
  132.  
  133. gl_FragColor.rgb = combineColor(data);
  134. gl_FragColor.rgb += getEmission(data);
  135. gl_FragColor.rgb = gammaCorrectOutput(gl_FragColor.rgb);
  136. gl_FragColor.a = data.alpha;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement