further tweak water & ssao shaders

This commit is contained in:
Edgaru089 2022-02-26 14:05:55 +08:00
parent a71acc22a0
commit 7d7778f53d
3 changed files with 17 additions and 9 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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()