Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 450
- #define PI 3.14159265359
- layout(binding = 0) uniform UBO{
- mat4 vM;
- mat4 cM;
- mat4 pM;
- vec4 lP;
- float time;
- uvec2 res;
- float varA;
- } ubo;
- layout(binding = 1) uniform sampler2DArray tex_samplr;
- layout(location = 0) in vec2 frag_uvco;
- layout(location = 1) in vec3 frag_norm;
- layout(location = 2) in vec3 frag_wpos;
- layout(location = 3) in vec3 frag_light_dir;
- layout(location = 4) in mat3 frag_TBN;
- layout(location = 0) out vec4 out_frag;
- uvec2 res = ubo.res;
- float time = ubo.time;
- vec3 specular(){
- vec3 diffuse_light = vec3(1.);
- vec3 specular_light = vec3(.0);
- vec3 tex_color = texture(tex_samplr,vec3(frag_uvco * 10,0)).rgb;
- vec3 tex_norm = texture(tex_samplr,vec3(frag_uvco * 10,1)).rgb;
- tex_norm = normalize(tex_norm * 2.0 - 1.0);
- tex_norm = normalize(frag_TBN * tex_norm);
- vec3 surf_norm = /*normalize(frag_norm) + */normalize(tex_norm);
- // return surf_norm;
- vec3 cam_wpos = ubo.cM[3].xyz;
- vec3 view_dir = normalize(cam_wpos - frag_wpos);
- vec3 light_dir = frag_TBN * frag_light_dir; // Direction to light
- float fading = 1 / dot(light_dir, light_dir); // Attenuation
- light_dir = normalize(light_dir);
- float cos_ang_incid = max(dot(surf_norm, light_dir), 0);
- vec3 intensity = vec3(1.) * fading;
- diffuse_light += intensity * cos_ang_incid * (ubo.varA / 10);
- vec3 half_ang = normalize(light_dir + view_dir);
- float blinn_term = dot (surf_norm, half_ang);
- blinn_term = clamp (blinn_term, 0, 1);
- blinn_term = pow (blinn_term,192);
- specular_light += intensity * blinn_term;
- specular_light *= ubo.varA / 50;
- vec3 ambient = .25 * tex_color;
- return ambient * diffuse_light + specular_light;
- }
- void main(){
- out_frag.rgb = specular();
- }
Advertisement
Add Comment
Please, Sign In to add comment