further tweak water & ssao shaders
This commit is contained in:
parent
a71acc22a0
commit
7d7778f53d
@ -47,6 +47,11 @@ void loadGBuffer() {
|
|||||||
gl_FragDepth = fragGPos.w * 0.5 + 0.5;
|
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() {
|
void main() {
|
||||||
|
|
||||||
@ -54,16 +59,16 @@ void main() {
|
|||||||
|
|
||||||
vec4 randval = texture(rand, gl_FragCoord.xy / randSize);
|
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 tangent = normalize(randval.xyz - fragNormal*dot(randval.xyz, fragNormal));
|
||||||
vec3 bitangent = cross(fragNormal, tangent);
|
vec3 bitangent = cross(fragNormal, tangent);
|
||||||
mat3 TBN = mat3(tangent, bitangent, fragNormal);
|
mat3 TBN = mat3(view) * mat3(tangent, bitangent, fragNormal) * radius;
|
||||||
|
|
||||||
float occlusion = 0;
|
float occlusion = 0;
|
||||||
for (int i = 0; i < SSAO_SAMPLE_COUNT; i++) {
|
for (int i = 0; i < SSAO_SAMPLE_COUNT; i++) {
|
||||||
vec3 samplePos = TBN * samples[i];
|
vec4 viewpos = vec4(fragPosView + TBN * samples[i], 1.0f);
|
||||||
samplePos = fragPos + samplePos * radius;
|
|
||||||
|
|
||||||
vec4 viewpos = view * vec4(samplePos, 1.0);
|
|
||||||
|
|
||||||
vec4 ndcpos = projection * viewpos;
|
vec4 ndcpos = projection * viewpos;
|
||||||
ndcpos.xyz /= ndcpos.w;
|
ndcpos.xyz /= ndcpos.w;
|
||||||
|
@ -24,11 +24,13 @@ out vec4 outputColor;
|
|||||||
|
|
||||||
const float gamma = 2.2;
|
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;
|
const float fogDensity = .00003;
|
||||||
|
|
||||||
|
|
||||||
float sunalpha = 0;
|
float sunalpha = 0;
|
||||||
|
vec3 suncolor = vec3(0);
|
||||||
|
|
||||||
float light;
|
float light;
|
||||||
vec3 color = vec3(0);
|
vec3 color = vec3(0);
|
||||||
void lightSun();
|
void lightSun();
|
||||||
@ -52,7 +54,8 @@ void main() {
|
|||||||
float waterDepth = (fragPosView.z-texture(gPos, gl_FragCoord.xy/screenSize).a);
|
float waterDepth = (fragPosView.z-texture(gPos, gl_FragCoord.xy/screenSize).a);
|
||||||
|
|
||||||
float waterFactor = pow(alpha, waterDepth);
|
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() {
|
void lightSun() {
|
||||||
@ -67,7 +70,7 @@ void lightSun() {
|
|||||||
|
|
||||||
float shadow = lightSunShadow();
|
float shadow = lightSunShadow();
|
||||||
light += diffuse * shadow;
|
light += diffuse * shadow;
|
||||||
color += vec3(specular) * shadow;
|
suncolor += vec3(specular) * shadow;
|
||||||
|
|
||||||
if (specular*shadow > 1.0f)
|
if (specular*shadow > 1.0f)
|
||||||
sunalpha += specular*shadow - 1.0f;
|
sunalpha += specular*shadow - 1.0f;
|
||||||
|
@ -443,7 +443,7 @@ func (g *Game) Render(win *glfw.Window) {
|
|||||||
gl.DepthFunc(gl.LESS)
|
gl.DepthFunc(gl.LESS)
|
||||||
gl.Enable(gl.CULL_FACE)
|
gl.Enable(gl.CULL_FACE)
|
||||||
gl.Enable(gl.BLEND)
|
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)
|
gl.BlendEquation(gl.FUNC_ADD)
|
||||||
g.render.water.shader.UseProgram()
|
g.render.water.shader.UseProgram()
|
||||||
g.render.water.shader.BindTextures()
|
g.render.water.shader.BindTextures()
|
||||||
|
Loading…
Reference in New Issue
Block a user