diff options
Diffstat (limited to 'advanced_lighting/6.hdr/shaders')
-rw-r--r-- | advanced_lighting/6.hdr/shaders/blinn.frag | 54 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/blinn.vert | 34 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/hdr.frag | 29 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/hdr.vert | 14 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/light.frag | 8 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/light.vert | 11 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/normals_debug.frag | 10 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/normals_debug.geom | 28 | ||||
-rw-r--r-- | advanced_lighting/6.hdr/shaders/normals_debug.vert | 16 |
9 files changed, 204 insertions, 0 deletions
diff --git a/advanced_lighting/6.hdr/shaders/blinn.frag b/advanced_lighting/6.hdr/shaders/blinn.frag new file mode 100644 index 0000000..5dca1f7 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/blinn.frag @@ -0,0 +1,54 @@ +#version 330 core + +in VS_OUT { + vec3 fpos; + vec3 fn; + vec2 texc; +} fsin; + +out vec4 fcolor; + +uniform sampler2D diftex; + +const int lmax = 30; + +uniform int lcount; +uniform vec3 lpos[lmax]; +uniform vec3 vpos; + +void main(void) +{ + vec3 l, v, n, difcolor, lcolor, ambient, halfdir, result; + float diff, spec, specf, dist, attenuation; + int i; + + n = normalize(fsin.fn); + v = normalize(vpos-fsin.fpos); + + ambient = vec3(0.001); + + difcolor = vec3(texture(diftex, fsin.texc)); + + /* lcolor = vec3(0.3, 0.0, 0.1); */ + lcolor = vec3(1.0); + + specf = 0.2; + + result = vec3(0.0); + + for (i = 0; i < lcount; i++) { + l = normalize(lpos[i]-fsin.fpos); + halfdir = normalize(l+v); + + diff = max(dot(n, l), 0.0); + + spec = pow(max(dot(n, halfdir), 0.0), 16.0)*specf; + + dist = length(lpos[i]-fsin.fpos); + attenuation = 1.0/dist; + + result += (diff+spec)*difcolor*lcolor*attenuation; + } + + fcolor = vec4(ambient+result, 1.0); +} diff --git a/advanced_lighting/6.hdr/shaders/blinn.vert b/advanced_lighting/6.hdr/shaders/blinn.vert new file mode 100644 index 0000000..f08f38e --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/blinn.vert @@ -0,0 +1,34 @@ +#version 330 core +layout(location = 0) in vec3 apos; +layout(location = 1) in vec3 anormal; +layout(location = 2) in vec2 atexc; + +out VS_OUT { + vec3 fpos; + vec3 fn; + vec2 texc; +} vsout; + +uniform mat4 proj; +uniform mat4 view; +uniform mat4 model; + +uniform bool invert_normals; + +void main(void) +{ + mat3 normtransf; + + vsout.fpos = vec3(model*vec4(apos, 1.0)); + + normtransf = mat3(transpose(inverse(model))); + + if (invert_normals) + vsout.fn = normtransf*(-anormal); + else + vsout.fn = normtransf*anormal; + + vsout.texc = atexc; + + gl_Position = proj*view*model*vec4(apos, 1.0); +} diff --git a/advanced_lighting/6.hdr/shaders/hdr.frag b/advanced_lighting/6.hdr/shaders/hdr.frag new file mode 100644 index 0000000..f12c6a8 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/hdr.frag @@ -0,0 +1,29 @@ +#version 330 core + +in VSOUT { + vec2 texc; +} vsout; + +out vec4 fcolor; + +uniform sampler2D hdrbuf; +uniform float exposure; + +void main(void) +{ + const float gamma = 2.2; + + vec3 hdrcolor, mapped; + + hdrcolor = vec3(texture(hdrbuf, vsout.texc)); + + /* NOTE(pryazha): Reinhard tone mapping */ + /* mapped = hdrcolor/(hdrcolor+vec3(1.0)); */ + + /* NOTE(pryazha): Tone mapping with exposure (i guess) */ + mapped = vec3(1.0)-exp(-hdrcolor*exposure); + + mapped = pow(mapped, vec3(1.0/gamma)); + + fcolor = vec4(mapped, 1.0); +} diff --git a/advanced_lighting/6.hdr/shaders/hdr.vert b/advanced_lighting/6.hdr/shaders/hdr.vert new file mode 100644 index 0000000..4f15c72 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/hdr.vert @@ -0,0 +1,14 @@ +#version 330 core +layout(location = 0) in vec3 apos; +layout(location = 2) in vec2 atexc; + +out VSOUT { + vec2 texc; +} vsout; + +void main(void) +{ + vsout.texc = atexc; + + gl_Position = vec4(apos, 1.0); +} diff --git a/advanced_lighting/6.hdr/shaders/light.frag b/advanced_lighting/6.hdr/shaders/light.frag new file mode 100644 index 0000000..3829c91 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/light.frag @@ -0,0 +1,8 @@ +#version 330 core + +out vec4 fcolor; + +void main(void) +{ + fcolor = vec4(1.0); +} diff --git a/advanced_lighting/6.hdr/shaders/light.vert b/advanced_lighting/6.hdr/shaders/light.vert new file mode 100644 index 0000000..a24ade5 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/light.vert @@ -0,0 +1,11 @@ +#version 330 core +layout(location = 0) in vec3 apos; + +uniform mat4 proj; +uniform mat4 view; +uniform mat4 model; + +void main(void) +{ + gl_Position = proj*view*model*vec4(apos, 1.0); +} diff --git a/advanced_lighting/6.hdr/shaders/normals_debug.frag b/advanced_lighting/6.hdr/shaders/normals_debug.frag new file mode 100644 index 0000000..32e36a7 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/normals_debug.frag @@ -0,0 +1,10 @@ +#version 330 core + +in vec3 vcolor; + +out vec4 frag_color; + +void main(void) +{ + frag_color = vec4(vcolor, 1.0); +} diff --git a/advanced_lighting/6.hdr/shaders/normals_debug.geom b/advanced_lighting/6.hdr/shaders/normals_debug.geom new file mode 100644 index 0000000..bdbc1b3 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/normals_debug.geom @@ -0,0 +1,28 @@ +#version 330 core +layout(triangles) in; +layout(line_strip, max_vertices=6) out; + +in VS_OUT { + vec4 normal; +} gs_in[]; + +out vec3 vcolor; + +uniform mat4 proj; + +void gen_normals(int index) +{ + vcolor = vec3(0.0, 1.0, 0.0); + gl_Position = proj*(gl_in[index].gl_Position); + EmitVertex(); + gl_Position = proj*(gl_in[index].gl_Position+0.5*gs_in[index].normal); + EmitVertex(); + EndPrimitive(); +} + +void main(void) +{ + gen_normals(0); + gen_normals(1); + gen_normals(2); +} diff --git a/advanced_lighting/6.hdr/shaders/normals_debug.vert b/advanced_lighting/6.hdr/shaders/normals_debug.vert new file mode 100644 index 0000000..2d3a4b5 --- /dev/null +++ b/advanced_lighting/6.hdr/shaders/normals_debug.vert @@ -0,0 +1,16 @@ +#version 330 core +layout(location = 0) in vec3 apos; +layout(location = 1) in vec3 anormal; + +out VS_OUT { + vec4 normal; +} vs_out; + +uniform mat4 view; +uniform mat4 model; + +void main(void) +{ + vs_out.normal = view*model*vec4(normalize(anormal), 0.0); + gl_Position = view*model*vec4(apos, 1.0); +} |