further tweak water & ssao shaders

This commit is contained in:
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;