From eb4303756eb34eff1e54454ce2fc4cfc343262a6 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Wed, 24 Jun 2015 15:24:13 +0200 Subject: [PATCH] small jump fix replaced Fragmentcolor with gl_FragColor (shader) --- CGUE2015_Weave.sln | 1 + Weave/Scene/Level.cpp | 11 ++++---- Weave/Scene/SceneObject.cpp | 4 +-- shader/basicTexture_FS.hlsl | 4 +-- shader/basic_FS.hlsl | 4 +-- shader/blur_FS.hlsl | 47 ++++++++++++++++++++++++++++++++++ shader/lightingTexture_FS.hlsl | 10 +++----- shader/skyplane_FS.hlsl | 3 +-- shader/skyplane_color_FS.hlsl | 3 +-- 9 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 shader/blur_FS.hlsl diff --git a/CGUE2015_Weave.sln b/CGUE2015_Weave.sln index 7a36625..8d0b4d6 100644 --- a/CGUE2015_Weave.sln +++ b/CGUE2015_Weave.sln @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shader", "shader", "{75179E shader\basic_VS.hlsl = shader\basic_VS.hlsl shader\basicTexture_FS.hlsl = shader\basicTexture_FS.hlsl shader\basicTexture_VS.hlsl = shader\basicTexture_VS.hlsl + shader\blur_FS.hlsl = shader\blur_FS.hlsl shader\lightingTexture_FS.hlsl = shader\lightingTexture_FS.hlsl shader\perspective_VS.hlsl = shader\perspective_VS.hlsl shader\skybox_VS.hlsl = shader\skybox_VS.hlsl diff --git a/Weave/Scene/Level.cpp b/Weave/Scene/Level.cpp index f565eec..f9ae3ba 100644 --- a/Weave/Scene/Level.cpp +++ b/Weave/Scene/Level.cpp @@ -52,13 +52,14 @@ void Level::collides(SceneObject* _other, btPersistentManifold* _contactManifold //Height - if (_other->yFloorDist < 0 && _other->ySpeed < 0) - { - _other->move(-pdist * vec3(0.f, normal[1], 0.f)); - } - if (normal[1] >= .3f && _other->ySpeed < 0) + + if (normal[1] >= .3f && _other->ySpeed <= 0) { + if (_other->yFloorDist < 0) + { + _other->move(-pdist * vec3(0.f, normal[1], 0.f)); + } _other->ySpeed = 0; } diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index 2d36451..453a410 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -156,10 +156,10 @@ void SceneObject::update(float deltaT) if (yFloorDist>0 || ySpeed!=0) { if (ySpeed*deltaT < yFloorDist || ySpeed>0) - modelMat = translate(vec3(0.f, ySpeed*deltaT, 0.f))*modelMat; + move(vec3(0.f, ySpeed*deltaT, 0.f)); else { - modelMat = translate(vec3(0.f, yFloorDist, 0.f))*modelMat; + move(vec3(0.f, yFloorDist, 0.f)); ySpeed = 0; //set to FloorSpeed? } ySpeed -= deltaT*YFALL_SPEED; diff --git a/shader/basicTexture_FS.hlsl b/shader/basicTexture_FS.hlsl index aae33bc..132e13f 100644 --- a/shader/basicTexture_FS.hlsl +++ b/shader/basicTexture_FS.hlsl @@ -3,11 +3,9 @@ //in worldNormal; in vec2 fUVs; -out vec4 FragmentColor; - uniform sampler2D uColorTexture; void main() { - FragmentColor = texture(uColorTexture, fUVs); + gl_FragColor = texture(uColorTexture, fUVs); } \ No newline at end of file diff --git a/shader/basic_FS.hlsl b/shader/basic_FS.hlsl index a041461..c2b701a 100644 --- a/shader/basic_FS.hlsl +++ b/shader/basic_FS.hlsl @@ -1,9 +1,7 @@ //Fragment Shader #version 330 -out vec4 FragmentColor; - uniform vec4 uFragmentColor = vec4(0.6, 0, 0, 0.6); void main(){ - FragmentColor = uFragmentColor; + gl_FragColor = uFragmentColor; } diff --git a/shader/blur_FS.hlsl b/shader/blur_FS.hlsl new file mode 100644 index 0000000..fd99996 --- /dev/null +++ b/shader/blur_FS.hlsl @@ -0,0 +1,47 @@ +//Fragment Shader +#version 330 +//"in" attributes from our vertex shader +varying vec4 vColor; +varying vec2 fUVs; + +//declare uniforms +uniform sampler2D u_texture; +uniform float resolution; +uniform float radius; +uniform vec2 dir; + +void main() { + //this will be our RGBA sum + vec4 sum = vec4(0.0); + + //our original texcoord for this fragment + vec2 tc = fUVs; + + //the amount to blur, i.e. how far off center to sample from + //1.0 -> blur by one pixel + //2.0 -> blur by two pixels, etc. + float blur = radius / resolution; + + //the direction of our blur + //(1.0, 0.0) -> x-axis blur + //(0.0, 1.0) -> y-axis blur + float hstep = dir.x; + float vstep = dir.y; + + //apply blurring, using a 9-tap filter with predefined gaussian weights + + sum += texture2D(u_texture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162; + sum += texture2D(u_texture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541; + sum += texture2D(u_texture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216; + sum += texture2D(u_texture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946; + + sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.2270270270; + + sum += texture2D(u_texture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946; + sum += texture2D(u_texture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216; + sum += texture2D(u_texture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541; + sum += texture2D(u_texture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162; + + //discard alpha for our simple demo, multiply by vertex color and return + gl_FragColor = vColor * vec4(sum.rgb, 1.0); +} \ No newline at end of file diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index 74ce55c..501ee92 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -5,8 +5,6 @@ in vec2 fUVs; in vec3 PointLightPosition1, DirectionalLightDirection1; -out vec4 FragmentColor; - uniform sampler2D uColorTexture; uniform vec4 material; //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3) @@ -37,15 +35,15 @@ void main() float squaredist1 = worldPointLightDir1.x * worldPointLightDir1.x + worldPointLightDir1.y * worldPointLightDir1.y + worldPointLightDir1.z * worldPointLightDir1.z; - FragmentColor = vec4(uvColor.rgb * (AmbientLightColor * material[0] + gl_FragColor = vec4(uvColor.rgb * (AmbientLightColor * material[0] + PointLightColor1 * material[1] * (cosThetaPoint1 + pow(SpecularCosPoint1, specularConst)) / squaredist1 + DirectionalLightColor1 * material[2] * (cosThetaDirection1 + pow(SpecularCosDirection1, specularConst)) ), uvColor.a); - //FragmentColor = vec4((normalize(worldNormal)+1)/2, 1.0f); - //FragmentColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f); + //gl_FragColor = vec4((normalize(worldNormal)+1)/2, 1.0f); + //gl_FragColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f); //vec3 uvColor = texture(uColorTexture, fUVs).rgb; - //FragmentColor = vec4(uvColor, 1.0); + //gl_FragColor = vec4(uvColor, 1.0); } diff --git a/shader/skyplane_FS.hlsl b/shader/skyplane_FS.hlsl index 1e1c0cc..1054192 100644 --- a/shader/skyplane_FS.hlsl +++ b/shader/skyplane_FS.hlsl @@ -3,8 +3,7 @@ uniform samplerCube uColorTexture; smooth in vec3 eyeDirection; -out vec4 FragmentColor; void main(){ - FragmentColor = texture(uColorTexture, eyeDirection); + gl_FragColor = texture(uColorTexture, eyeDirection); } diff --git a/shader/skyplane_color_FS.hlsl b/shader/skyplane_color_FS.hlsl index 1724745..cf53dee 100644 --- a/shader/skyplane_color_FS.hlsl +++ b/shader/skyplane_color_FS.hlsl @@ -2,8 +2,7 @@ #version 330 smooth in vec3 eyeDirection; -out vec4 FragmentColor; void main(){ - FragmentColor = vec4((eyeDirection+vec3(2.f))/4, 0.5); + gl_FragColor = vec4((eyeDirection+vec3(2.f))/4, 0.5); } -- 2.47.3