diff --git a/internal/asset/shader/world/ssao.frag b/internal/asset/shader/world/ssao.frag index ad74c1f..9d03032 100644 --- a/internal/asset/shader/world/ssao.frag +++ b/internal/asset/shader/world/ssao.frag @@ -47,6 +47,11 @@ void loadGBuffer() { gl_FragDepth = fragGPos.w * 0.5 + 0.5; } +vec3 viewTransform(vec3 from) { + vec4 temp = view * vec4(from, 1); + return temp.xyz / temp.w; +} + void main() { @@ -54,16 +59,16 @@ void main() { vec4 randval = texture(rand, gl_FragCoord.xy / randSize); + //vec3 fragNormalView = viewTransform(fragNormal); + vec3 fragPosView = viewTransform(fragPos); + vec3 tangent = normalize(randval.xyz - fragNormal*dot(randval.xyz, fragNormal)); vec3 bitangent = cross(fragNormal, tangent); - mat3 TBN = mat3(tangent, bitangent, fragNormal); + mat3 TBN = mat3(view) * mat3(tangent, bitangent, fragNormal) * radius; float occlusion = 0; for (int i = 0; i < SSAO_SAMPLE_COUNT; i++) { - vec3 samplePos = TBN * samples[i]; - samplePos = fragPos + samplePos * radius; - - vec4 viewpos = view * vec4(samplePos, 1.0); + vec4 viewpos = vec4(fragPosView + TBN * samples[i], 1.0f); vec4 ndcpos = projection * viewpos; ndcpos.xyz /= ndcpos.w; diff --git a/internal/asset/shader/world/water.frag b/internal/asset/shader/world/water.frag index b2f666c..26fb903 100644 --- a/internal/asset/shader/world/water.frag +++ b/internal/asset/shader/world/water.frag @@ -24,11 +24,13 @@ out vec4 outputColor; const float gamma = 2.2; -const float ambient = 0.3, specularStrength = 1.6, specularShininess = 128; +const float ambient = 0.3, specularStrength = 1.6, specularShininess = 256; const float fogDensity = .00003; float sunalpha = 0; +vec3 suncolor = vec3(0); + float light; vec3 color = vec3(0); void lightSun(); @@ -52,7 +54,8 @@ void main() { float waterDepth = (fragPosView.z-texture(gPos, gl_FragCoord.xy/screenSize).a); float waterFactor = pow(alpha, waterDepth); - outputColor = vec4(color*waterFactor, min(1-waterFactor + sunalpha, 1)); + float waterAlpha = min(1-waterFactor + sunalpha, 1); + outputColor = vec4(color*waterFactor*waterAlpha + suncolor, waterAlpha); } void lightSun() { @@ -67,7 +70,7 @@ void lightSun() { float shadow = lightSunShadow(); light += diffuse * shadow; - color += vec3(specular) * shadow; + suncolor += vec3(specular) * shadow; if (specular*shadow > 1.0f) sunalpha += specular*shadow - 1.0f; diff --git a/internal/game/render.go b/internal/game/render.go index 37c87ae..298777a 100644 --- a/internal/game/render.go +++ b/internal/game/render.go @@ -443,7 +443,7 @@ func (g *Game) Render(win *glfw.Window) { gl.DepthFunc(gl.LESS) gl.Enable(gl.CULL_FACE) gl.Enable(gl.BLEND) - gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) + gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) gl.BlendEquation(gl.FUNC_ADD) g.render.water.shader.UseProgram() g.render.water.shader.BindTextures()