Add files via upload
parent
56b372d524
commit
de017fcb1e
|
@ -0,0 +1,98 @@
|
|||
#version 330
|
||||
|
||||
layout(location=0) out vec4 mgl_FragColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D depthmap;
|
||||
//uniform sampler2D objectmap;
|
||||
|
||||
in vec2 texcoords_pass;
|
||||
|
||||
const vec2 dirs[]=vec2[8] (vec2(1.0f/512.0f,0.0f),vec2(-1.0f/512.0f,0.0f),vec2(0.0f,1.0f/512.0f),vec2(0.0f,-1.0f/512.0f),vec2(1.0f/512.0f,1.0f/512.0f),vec2(-1.0f/512.0f,-1.0f/512.0f)
|
||||
,vec2(-1.0f/512.0f,1.0f/512.0f),vec2(1.0f/512.0f,-1.0f/512.0f));
|
||||
|
||||
vec4 average(float radius, float s)
|
||||
{
|
||||
vec4 result=texture(tex,texcoords_pass);
|
||||
float sum=1.0f;
|
||||
for (float i=0; i < radius; i+= s) {
|
||||
for (int j=0; j < 8; j++) {
|
||||
result+=texture(tex,texcoords_pass+i*dirs[j]);
|
||||
}
|
||||
sum+=8;
|
||||
}
|
||||
return result/sum;
|
||||
}
|
||||
|
||||
/*vec4 average2(float radius, float s, vec2 tc)
|
||||
{
|
||||
vec4 start=texture(tex,tc);
|
||||
float sd=texture(depthmap,tc).x;
|
||||
vec4 result=texture(tex,tc);
|
||||
float sum=1.0f;
|
||||
for (float i=0; i < radius; i+= s) {
|
||||
for (int j=0; j < 8; j++) {
|
||||
float w=texture(objectmap, tc+i*dirs[j]).x*abs(1.0-abs(texture(depthmap, tc+i*dirs[j]).x-sd));
|
||||
result+=texture(tex,tc+i*dirs[j])*w;
|
||||
sum+=w;
|
||||
}
|
||||
}
|
||||
return result/sum;
|
||||
}*/
|
||||
|
||||
float edge(float radius, float s, vec2 tc)
|
||||
{
|
||||
float sd=texture(depthmap,tc).x;
|
||||
if (sd==1.0f) {
|
||||
return 0.0f;
|
||||
}
|
||||
float edge=1.0f;
|
||||
for (float i=0; i < radius; i+= s) {
|
||||
for (int j=0; j < 8; j++) {
|
||||
float w=abs(1-abs(texture(depthmap, tc+i*dirs[j]).x-sd));
|
||||
edge*=w;
|
||||
}
|
||||
}
|
||||
return edge;
|
||||
}
|
||||
|
||||
float edge_texture(float radius, float s, vec2 tc)
|
||||
{
|
||||
vec3 sd=texture(tex,tc).xyz;
|
||||
if (sd.x+sd.y+sd.z==0.0f) {
|
||||
return 0.0f;
|
||||
}
|
||||
float edge=1.0f;
|
||||
for (float i=0;i < radius; i+= s) {
|
||||
for (int j=0; j < 8; j++) {
|
||||
vec3 rgb=texture(tex, tc+i*dirs[j]).xyz;
|
||||
vec3 diff=round(vec3(1,1,1)-abs(rgb-sd)*vec3(4,4,4))/2.5f;
|
||||
float w=diff.x*diff.y*diff.z;
|
||||
edge*=w*w;
|
||||
}
|
||||
}
|
||||
return sqrt(edge);
|
||||
}
|
||||
|
||||
void main (void)
|
||||
{
|
||||
float depth=texture(depthmap,vec2(0.5f,0.5f)).x;
|
||||
float depth_here=texture(depthmap,texcoords_pass).x;
|
||||
float difference=abs(depth-depth_here);
|
||||
vec4 texcol=texture(tex, texcoords_pass);
|
||||
//vec2 texcolor=texture(tex, texcoords_pass);
|
||||
//vec2 temp=vec2(texcoords_pass.x,texcoords_pass.y);
|
||||
//vec2 t2=vec2(tan(texcoords_pass.x),tan(texcoords_pass.y));
|
||||
//vec2 t2=vec2(tan(asin(texcoords_pass.x)),tan(acos(texcoords_pass.y)));
|
||||
//vec2 r=refract(temp,vec2(1.0f,1.0f),1.33f*(1.0f-difference));
|
||||
//vec2 r=refract(texcoords_pass,t2,difference);
|
||||
//vec4 texture_color=average2(/*difference*20*/dot(r,texcoords_pass)*5,0.9f,r);
|
||||
//vec4 texture_color=average(difference*20,0.9f);
|
||||
float green=length(vec3(texcol.x*difference*10,texcol.y/depth_here,texcol.z*depth));
|
||||
//float edge=edge(2.0f,0.9f,texcoords_pass);
|
||||
float edge=0.0f;
|
||||
float edge_tex=max(edge,edge_texture(2.0f,0.9f,texcoords_pass));
|
||||
mgl_FragColor=clamp(vec4(depth_here,depth_here,depth_here,1.0f),0.0f,1.0f);
|
||||
//mgl_FragColor=clamp(vec4(edge_tex,edge_tex,edge_tex,1.0f),0.0f,1.0f);
|
||||
mgl_FragColor=vec4(clamp(texcol.xyz,0,1.0f), 1.0f);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#version 330
|
||||
|
||||
in vec3 attribute_Position;
|
||||
in vec2 texcoords;
|
||||
in vec3 normal;
|
||||
in vec3 transform;
|
||||
|
||||
out vec2 texcoords_pass;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
texcoords_pass=texcoords;
|
||||
gl_Position=vec4(attribute_Position,1.0f);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
#version 330
|
||||
|
||||
layout(location = 1) out vec4 mgl_FragColor;
|
||||
layout(location = 0) out float fragmentdepth;
|
||||
//layout(location=2) out vec4 mgl_object;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D bumpmap;
|
||||
uniform sampler2D diffusemap;
|
||||
uniform sampler2D specularmap;
|
||||
uniform sampler2D gaussianmap;
|
||||
uniform sampler2D shadowmap;
|
||||
uniform vec3 lightDiffuse;
|
||||
uniform vec3 lightSpecular;
|
||||
uniform vec3 lightGaussian;
|
||||
uniform vec3 fogColor;
|
||||
uniform float ambient;
|
||||
|
||||
in vec2 texcoords;
|
||||
in vec3 toEye;
|
||||
in vec3 toLight;
|
||||
in float attenuation;
|
||||
in vec3 normals;
|
||||
in vec3 shadow_position;
|
||||
in vec3 world;
|
||||
in float fog;
|
||||
|
||||
void main (void)
|
||||
{
|
||||
vec4 texture_color = texture(tex,texcoords);
|
||||
vec2 tv=vec2(sin(texcoords.x),cos(texcoords.y));
|
||||
vec2 t=vec2(tan(texcoords.x),tan(texcoords.y));
|
||||
texture_color=texture(tex,refract(tv,t,dot(toEye,normals)*1.33f));
|
||||
if (texture_color.w == 0) {
|
||||
discard;
|
||||
}
|
||||
vec3 normals_bumpmap = normalize(texture(bumpmap,texcoords).xyz);
|
||||
vec3 normals=normals_bumpmap*normals;
|
||||
float brightness = dot(normals,toLight);
|
||||
brightness=clamp(brightness,0,1);
|
||||
vec3 ReflectedVector = normalize(reflect(toLight, normals));
|
||||
float SpecularFactor = dot(toEye, ReflectedVector);
|
||||
SpecularFactor=clamp(pow(SpecularFactor,32),0, 1);
|
||||
|
||||
vec3 diffuse = clamp(vec3(1,1,1)*brightness,0,1);
|
||||
vec3 specular = clamp(vec3(1,1,1) * SpecularFactor,0,1);
|
||||
vec3 gaussian = vec3(1,1,1)*clamp(refract(ReflectedVector,toEye,0.5f),0,1);
|
||||
gaussian = clamp(cross(refract(ReflectedVector,toEye,0.5f),refract(normals,toEye,0.5f)),0,1);
|
||||
//gaussian = vec3(1,1,1)*clamp(cross(toLight,cross(toEye,normals)).y,0,1);
|
||||
diffuse*=lightDiffuse*texture(diffusemap,texcoords).xyz;
|
||||
specular*=lightSpecular*texture(specularmap,texcoords).xyz;
|
||||
gaussian*=lightGaussian*texture(gaussianmap,texcoords).xyz;
|
||||
float visibility = 1.0;
|
||||
if ( texture( shadowmap, shadow_position.xy ).x < shadow_position.z){
|
||||
visibility = 1-abs(texture( shadowmap, shadow_position.xy ).x-shadow_position.z)*3;
|
||||
}
|
||||
visibility=clamp(visibility,0,1);
|
||||
//mgl_FragColor=vec4(gaussian,1.0f);
|
||||
//mgl_FragColor=texture(shadowmap,shadow_position.xy);
|
||||
//mgl_FragColor=vec4(fog,fog,fog,1.0f);
|
||||
//mgl_FragColor=vec4(specular.x,diffuse.y,gaussian.z,texture_color.w);
|
||||
mgl_FragColor=vec4(clamp((fogColor*fog*ambient*visibility)+((1.0-fog)*texture_color.xyz*ambient+visibility*attenuation*texture_color.xyz*0.5f*(gaussian+diffuse+(1-specular))),0,1),texture_color.w);
|
||||
|
||||
float ndcDepth =
|
||||
(2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
|
||||
(gl_DepthRange.far - gl_DepthRange.near);
|
||||
float clipDepth = ndcDepth / gl_FragCoord.w;
|
||||
fragmentdepth = ((clipDepth * 0.5) + 0.5)/100.0f/* gl_FragCoord.z/gl_FragCoord.w*/;
|
||||
//mgl_object=vec4(1,1,1,1);
|
||||
//mgl_FragColor=vec3(fragmentdepth,fragmentdepth,fragmentdepth);
|
||||
//mgl_FragColor=vec4(clamp(texture_color.xyz*ambient+visibility*(texture_color.xyz*attenuation*(diffuse*lightDiffuse*texture(diffusemap,texcoords_pass).xyz+specular*lightSpecular*texture(specularmap,texcoords_pass).xyz+gaussian*lightGaussian*texture(gaussianmap,texcoords_pass).xyz)),0,1),texture_color.w)
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#version 330
|
||||
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices=6) out;
|
||||
|
||||
in vec3 world_pass[];
|
||||
in vec2 texcoords_pass[];
|
||||
in float attenuation_pass[];
|
||||
in vec3 normals_pass[];
|
||||
in vec3 shadow_position_pass[];
|
||||
in vec3 toLight_pass[];
|
||||
in vec3 toEye_pass[];
|
||||
in float fog_pass[];
|
||||
|
||||
out vec3 world;
|
||||
out float attenuation;
|
||||
out vec3 normals;
|
||||
out vec3 shadow_position;
|
||||
out vec3 toLight;
|
||||
out vec3 toEye;
|
||||
out float fog;
|
||||
out vec2 texcoords;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < gl_in.length(); i++)
|
||||
{
|
||||
texcoords=texcoords_pass[i];
|
||||
world=world_pass[i];
|
||||
attenuation=attenuation_pass[i];
|
||||
normals=normals_pass[i];
|
||||
shadow_position=shadow_position_pass[i];
|
||||
toLight=toLight_pass[i];
|
||||
toEye=toEye_pass[i];
|
||||
fog=fog_pass[i];
|
||||
gl_Position = gl_in[i].gl_Position;/*-vec4(normalize(normals_pass[i]),0)*0.5;*/
|
||||
EmitVertex();
|
||||
/*gl_Position=gl_in[i].gl_Position-vec4(normals_pass[i],0)*0.5;
|
||||
EmitVertex();*/
|
||||
/*gl_Position = gl_in[i].gl_Position;
|
||||
EmitVertex();*/
|
||||
}
|
||||
EndPrimitive();
|
||||
for (i = 0; i < gl_in.length(); i++)
|
||||
{
|
||||
texcoords=texcoords_pass[i];
|
||||
world=world_pass[i];
|
||||
attenuation=attenuation_pass[i];
|
||||
normals=normals_pass[i];
|
||||
shadow_position=shadow_position_pass[i];
|
||||
toLight=toLight_pass[i];
|
||||
toEye=toEye_pass[i];
|
||||
fog=fog_pass[i];
|
||||
gl_Position = gl_in[i].gl_Position;/*-vec4(normalize(normals_pass[i]),0)*0.5;*/
|
||||
EmitVertex();
|
||||
/*gl_Position=gl_in[i].gl_Position-vec4(normals_pass[i],0)*0.5;
|
||||
EmitVertex();*/
|
||||
/*gl_Position = gl_in[i].gl_Position;
|
||||
EmitVertex();*/
|
||||
}
|
||||
EndPrimitive();
|
||||
/*vec3 a=(gl_in[0].gl_Position.xyz+gl_in[1].gl_Position.xyz)/2;
|
||||
vec3 b=(gl_in[0].gl_Position.xyz+gl_in[2].gl_Position.xyz)/2;
|
||||
vec3 c=(gl_in[1].gl_Position.xyz+gl_in[2].gl_Position.xyz)/2;
|
||||
gl_Position = vec4((a+b+c)/3,1);
|
||||
EmitVertex();*/
|
||||
//EndPrimitive();
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#version 330
|
||||
|
||||
uniform mat4 uniform_Transformation;
|
||||
uniform mat4 uniform_Modelview;
|
||||
uniform mat4 uniform_Projection;
|
||||
uniform mat4 lightMatrix;
|
||||
uniform float lightConstant;
|
||||
uniform float lightLinear;
|
||||
uniform float lightQuadratic;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 eyePos;
|
||||
uniform float time;
|
||||
uniform float fogConstant;
|
||||
uniform float fogLinear;
|
||||
uniform float fogQuadratic;
|
||||
|
||||
in vec3 attribute_Position;
|
||||
in vec2 texcoords;
|
||||
in vec3 normal;
|
||||
in vec3 transform;
|
||||
|
||||
out vec3 world_pass;
|
||||
out vec2 texcoords_pass;
|
||||
out float attenuation_pass;
|
||||
out vec3 normals_pass;
|
||||
out vec3 shadow_position_pass;
|
||||
out vec3 toLight_pass;
|
||||
out vec3 toEye_pass;
|
||||
out float fog_pass;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 pos = uniform_Transformation * vec4(attribute_Position+transform*time,1.0f);
|
||||
world_pass=pos.xyz;
|
||||
vec4 camrel = uniform_Modelview * pos;
|
||||
texcoords_pass=texcoords;
|
||||
normals_pass=(uniform_Transformation * -vec4(normal.x,normal.y,normal.z,0)).xyz;
|
||||
toLight_pass=pos.xyz-lightPos;
|
||||
float dtl=length(toLight_pass);
|
||||
toLight_pass=normalize(toLight_pass);
|
||||
toEye_pass = eyePos-pos.xyz;
|
||||
float dte=length(toEye_pass);
|
||||
toEye_pass=normalize(toEye_pass);
|
||||
fog_pass=(fogConstant+dte*fogLinear+pow(dte,2)*fogQuadratic);
|
||||
fog_pass=dte/fog_pass;
|
||||
if (fog_pass > 1.0f) {
|
||||
fog_pass=1.0f;
|
||||
}
|
||||
fog_pass=1.0f-fog_pass;
|
||||
attenuation_pass=(lightConstant+dtl*lightLinear+pow(dtl,2)*lightQuadratic);
|
||||
attenuation_pass=dtl/attenuation_pass;
|
||||
if (attenuation_pass > 1.0f) {
|
||||
attenuation_pass=1.0f;
|
||||
}
|
||||
shadow_position_pass=(lightMatrix*pos).xyz;
|
||||
gl_Position=uniform_Projection * camrel;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#version 330
|
||||
|
||||
layout(location=0) out vec4 litColor;
|
||||
|
||||
uniform sampler2D direction_to_light;
|
||||
uniform sampler2D rendered_scene;
|
||||
uniform sampler2D normalmap;
|
||||
uniform sampler2D depthmap;
|
||||
|
||||
in vec2 texcoords_pass;
|
||||
|
||||
void main (void)
|
||||
{
|
||||
//Calculating the direction to viewer, necessary for specular lighting, depthmap used for this
|
||||
float depth=1.0f-(texture(depthmap,texcoords_pass).x);
|
||||
vec3 dir_to_viewer = vec3((texcoords_pass-0.5f)*depth,(texcoords_pass-0.5f)*depth,depth);
|
||||
vec4 color=texture(rendered_scene, texcoords_pass);
|
||||
vec3 normal=texture(normalmap, texcoords_pass);
|
||||
vec3 to_light=texture(direction_to_light, texcoords_pass);
|
||||
normal.x=(normal.x-0.5f)*2.0f;
|
||||
normal.y=(normal.y-0.5f)*2.0f;
|
||||
normal.z=(normal.z-0.5f)*2.0f;
|
||||
float diffuse=dot(normal,to_light);
|
||||
litColor=vec4(color.x * diffuse, color.y * diffuse, color.z * diffuse, color.w);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#version 330
|
||||
|
||||
in vec3 attribute_Position;
|
||||
in vec2 texcoords;
|
||||
in vec3 normal;
|
||||
in vec3 transform;
|
||||
|
||||
out vec2 texcoords_pass;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
texcoords_pass=texcoords;
|
||||
gl_Position=vec4(attribute_Position,1.0f);
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#version 330
|
||||
uniform sampler2D tex;
|
||||
in vec2 texcoords_pass;
|
||||
layout(location = 0) out float fragmentdepth;
|
||||
void main() {
|
||||
if (texture(tex, texcoords_pass).w == 0) {
|
||||
discard;
|
||||
}
|
||||
fragmentdepth = gl_FragCoord.z;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#version 330
|
||||
#ifdef GL_ES
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
#endif
|
||||
|
||||
uniform mat4 uniform_Transformation;
|
||||
uniform mat4 uniform_Modelview;
|
||||
uniform mat4 uniform_Projection;
|
||||
in vec4 attribute_Position;
|
||||
in vec2 texcoords;
|
||||
in vec3 normal;
|
||||
out vec2 texcoords_pass;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
texcoords_pass=texcoords;
|
||||
vec4 pos = uniform_Transformation * attribute_Position;
|
||||
vec4 camrel = pos*uniform_Modelview;
|
||||
gl_Position= uniform_Projection*pos;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#version 330
|
||||
|
||||
out vec4 mgl_FragColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D shadowmap;
|
||||
uniform vec3 lightDiffuse;
|
||||
uniform float ambient;
|
||||
|
||||
in vec2 texcoords_pass;
|
||||
in float attenuation;
|
||||
in vec3 normals_pass;
|
||||
in vec3 shadow_position;
|
||||
|
||||
void main (void)
|
||||
{
|
||||
vec4 texture_color = texture(tex,texcoords_pass);
|
||||
if (texture_color.w == 0) {
|
||||
discard;
|
||||
}
|
||||
float visibility = 1.0;
|
||||
if ( texture( shadowmap, shadow_position.xy ).x < shadow_position.z){
|
||||
visibility = 0.5;
|
||||
}
|
||||
mgl_FragColor=vec4(texture_color.x*(ambient+visibility*attenuation),texture_color.y*(ambient+visibility*attenuation),texture_color.z*(ambient+visibility*attenuation),texture_color.w);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#version 330
|
||||
|
||||
uniform mat4 uniform_Transformation;
|
||||
uniform mat4 uniform_Modelview;
|
||||
uniform mat4 uniform_Projection;
|
||||
uniform mat4 lightMatrix;
|
||||
uniform float lightConstant;
|
||||
uniform float lightLinear;
|
||||
uniform float lightQuadratic;
|
||||
uniform vec3 lightPos;
|
||||
|
||||
in vec4 attribute_Position;
|
||||
in vec2 texcoords;
|
||||
|
||||
out vec2 texcoords_pass;
|
||||
out float attenuation;
|
||||
out vec3 shadow_position;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 pos = uniform_Transformation * attribute_Position;
|
||||
vec4 camrel = uniform_Modelview * pos;
|
||||
texcoords_pass=texcoords;
|
||||
float dtl=length(pos.xyz-lightPos);
|
||||
attenuation=1.0f/(lightConstant+dtl*lightLinear+pow(dtl,2)*lightQuadratic);
|
||||
shadow_position=(lightMatrix*pos).xyz;
|
||||
gl_Position=uniform_Projection * camrel;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#version 330
|
||||
uniform sampler2D tex;
|
||||
in vec2 texcoords_pass;
|
||||
layout(location = 0) out float fragmentdepth;
|
||||
void main() {
|
||||
if (texture(tex, texcoords_pass).w == 0) {
|
||||
discard;
|
||||
}
|
||||
fragmentdepth = gl_FragCoord.z/gl_FragCoord.w;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#version 330
|
||||
#ifdef GL_ES
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
#endif
|
||||
|
||||
uniform mat4 uniform_Transformation;
|
||||
uniform mat4 uniform_Modelview;
|
||||
uniform mat4 uniform_Projection;
|
||||
in vec4 attribute_Position;
|
||||
in vec2 texcoords;
|
||||
in vec3 normal;
|
||||
out vec2 texcoords_pass;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
texcoords_pass=texcoords;
|
||||
vec4 pos = uniform_Transformation * attribute_Position;
|
||||
vec4 camrel = pos*uniform_Modelview;
|
||||
gl_Position= uniform_Projection*pos;
|
||||
}
|
Loading…
Reference in New Issue