]> gitweb.ps.run Git - subsurface_scattering/blob - shaders/ts_frag_irradiance.glsl
SSSSS comments
[subsurface_scattering] / shaders / ts_frag_irradiance.glsl
1 #version 330 core\r
2 \r
3 in vec3 Normal;\r
4 in vec3 FragPos;\r
5 \r
6 out vec4 FragColor;\r
7 \r
8 uniform vec3 lightPos;\r
9 uniform vec3 lightColor;\r
10 uniform vec3 objectColor;\r
11 uniform vec3 viewPos;\r
12 \r
13 vec4 blur(sampler2D tex, vec2 uv, vec2 res) {\r
14   float Pi = 6.28318530718; // Pi*2\r
15     \r
16   // GAUSSIAN BLUR SETTINGS {{{\r
17   float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)\r
18   float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)\r
19   float Size = 8.0; // BLUR SIZE (Radius)\r
20   // GAUSSIAN BLUR SETTINGS }}}\r
21   \r
22   vec2 Radius = Size/res;\r
23   \r
24   // Pixel colour\r
25   vec4 Color = texture(tex, uv);\r
26   \r
27   // Blur calculations\r
28   for( float d=0.0; d<Pi; d+=Pi/Directions) {\r
29     for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality) {\r
30       Color += texture( tex, uv+vec2(cos(d),sin(d))*Radius*i);          \r
31     }\r
32   }\r
33   \r
34   // Output to screen\r
35   Color /= Quality * Directions - 15.0;\r
36   return Color;\r
37 }\r
38 \r
39 void main()\r
40 {\r
41   vec3 norm = normalize(Normal);\r
42   vec3 lightDir = normalize(lightPos - FragPos);\r
43 \r
44   float diff = max(dot(norm, lightDir), 0.0);\r
45   vec3 diffuse = diff * lightColor;\r
46 \r
47   float ambientStrength = 0.1;\r
48   vec3 ambient = ambientStrength * lightColor;\r
49 \r
50   float specularStrength = 0.5;\r
51   vec3 viewDir = normalize(viewPos - FragPos);\r
52   vec3 reflectDir = reflect(-lightDir, norm);\r
53   float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);\r
54   vec3 specular = specularStrength * spec * lightColor;\r
55 \r
56   vec3 result = (ambient + diffuse) * objectColor;\r
57 \r
58   result = vec3(length(FragPos - lightPos));\r
59     \r
60   FragColor = vec4(result, 1.0f);\r
61 }\r