X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=gl_shaders%2Fdefault.f.glsl;h=fe78fbc7e030bc69baa74c3f3f51032effc5fe54;hb=05d269a194496bcef85da78652b947f5bf1c9bcf;hp=17d4353eb241868cbe85464b0ca02e7e044171e5;hpb=f1c3197c3e035f4be0e10ff6a8d0cf0339824177;p=demo diff --git a/gl_shaders/default.f.glsl b/gl_shaders/default.f.glsl index 17d4353..fe78fbc 100644 --- a/gl_shaders/default.f.glsl +++ b/gl_shaders/default.f.glsl @@ -1,41 +1,39 @@ #version 450 -uniform sampler2D tex; +#define SHADING_UNIFORMS 1 -uniform vec4 diffuse; -uniform vec4 specular; -uniform float shininess; +layout(binding = 0) uniform sampler2D tex; +layout(binding = 1) uniform samplerCube dstex; -varying vec3 pos; -varying vec3 normal; -varying vec3 ldir; -varying vec2 tex_coord; +layout(std140, binding = SHADING_UNIFORMS) uniform fu { + vec4 diffuse; + vec4 specular; + float shininess; + float fog_density; +} s; -const float fog_density = 0.005; -const vec4 sky_color = vec4(0.35, 0.5, 0.65, 1.0); +const vec3 sky_color = vec3(0.35, 0.5, 0.65); +// const float fog_density = 0.005; -out vec4 color; +/* varyings */ +layout(location = 4) in vec3 pos; +layout(location = 5) in vec2 tex_coord; +layout(location = 6) in vec3 world_normal; + +layout(location = 0) out vec4 color; void main() { - vec3 p = normalize(pos); // view space dir - vec3 n = normalize(normal); - vec3 l = normalize(ldir); - - vec3 r = normalize(-reflect(l, n)); - vec3 vdir = normalize(-p); - - float cdiff = max(dot(l, n), 0.0); - float cspec = pow(max(dot(r, vdir), 0.0), shininess); + vec4 itexel = textureCube(dstex, normalize(world_normal)); float dist = -pos.z; - float fog = clamp(exp(-fog_density * dist), 0.0, 1.0); + float fog = clamp(exp(-s.fog_density * dist), 0.0, 1.0); vec4 texel = texture2D(tex, tex_coord); - vec4 object_color; - object_color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec; - object_color.w = 1.0; + // vec3 object_color = (diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec) * itexel.xyz; + vec3 object_color = s.diffuse.xyz * texel.xyz * itexel.xyz; - color = mix(sky_color, object_color, fog); + color.xyz = mix(sky_color, object_color, fog); + color.w = 1.0; }