Skip to content

Instantly share code, notes, and snippets.

@feliwir
Created June 23, 2016 08:36
Show Gist options
  • Save feliwir/303d76b491c2b1ad7e0495108f55127a to your computer and use it in GitHub Desktop.
Save feliwir/303d76b491c2b1ad7e0495108f55127a to your computer and use it in GitHub Desktop.
#version 400 core
in vec3 position;
in vec2 uv;
in vec3 normal;
in vec3 material;
uniform vec3 cameraPos;
uniform vec3 lightDir;
uniform sampler2DArray albedoTex;
uniform sampler2DArray normalTex;
uniform sampler2DArray specularTex;
uniform sampler2DArray ambientTex;
out vec4 color;
void main()
{
vec3 albedo = texture(albedoTex, vec3(uv, material[0])).rgb;
float ambient = texture(ambientTex, vec3(uv, material[0])).r;
float spec = texture(specularTex, vec3(uv, material[0])).r;
vec3 texNormal = texture(normalTex, vec3(uv, material[0])).rgb;
//texture blending
albedo = mix(albedo, texture(albedoTex, vec3(uv, material[1])).rgb, material[2]);
ambient = mix(ambient,texture(ambientTex, vec3(uv, material[1])).r, material[2]);
spec = mix(spec, texture(specularTex, vec3(uv, material[1])).r , material[2]);
texNormal = mix(texNormal, texture(normalTex, vec3(uv, material[1])).rgb, material[2]);
texNormal = normalize(texNormal*2.0-1.0);
vec3 viewDir = normalize(cameraPos - position);
vec3 halfwayDir = normalize(lightDir + viewDir);
spec = pow(max(dot(texNormal, halfwayDir), 0.0), spec);
color = vec4(ambient*albedo+spec,1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment