fix uninitialized shader variable

This commit is contained in:
Edgaru089 2022-02-21 14:01:09 +08:00
parent 4a9afb4246
commit 203b77c32f
4 changed files with 19 additions and 15 deletions

View File

@ -29,7 +29,7 @@ const float fogDensity = .00003;
float light; float light;
vec4 texpixel, color; vec3 color = vec3(0);
void lightSun(); void lightSun();
float lightSunShadow(); float lightSunShadow();
void lightPoint(int i); void lightPoint(int i);
@ -60,14 +60,13 @@ void main() {
lightSun(); lightSun();
color += vec4(fragColor.rgb * light, 0.0f); color += fragColor.rgb * light;
color.a = fragColor.a;
//float z = gl_FragCoord.z / gl_FragCoord.w; //float z = gl_FragCoord.z / gl_FragCoord.w;
//float fog = clamp(exp(-fogDensity * z * z), 0.2, 1); //float fog = clamp(exp(-fogDensity * z * z), 0.2, 1);
//outputColor = mix(fogColor, color, fog); //outputColor = mix(fogColor, color, fog);
outputColor = color; outputColor = vec4(color, 1);
} }
void lightSun() { void lightSun() {
@ -82,7 +81,7 @@ void lightSun() {
float shadow = lightSunShadow(); float shadow = lightSunShadow();
light += diffuse * shadow; light += diffuse * shadow;
color += vec4(vec3(specular), 0.0f) * shadow; color += vec3(specular) * shadow;
} }
float lightSunShadow() { float lightSunShadow() {

View File

@ -7,9 +7,9 @@ in vec2 fragPosScreen;
out vec4 outputColor; out vec4 outputColor;
void main() { void main() {
vec4 texColor = texture(tex, fragPosScreen); vec4 texColor = texture(tex, fragPosScreen);
if (texColor.a < 1e-4) if (texColor.a < 1e-4)
discard; discard;
outputColor = vec4(pow(texColor.rgb / exposure, vec3(1.0/gamma)), 1.0f); outputColor = vec4(pow(texColor.rgb * exposure, vec3(1.0/gamma)), 1.0f);
} }

View File

@ -26,7 +26,7 @@ const float fogDensity = .00003;
float finalpha; float finalpha;
float light; float light;
vec4 texpixel, color; vec3 color = vec3(0);
void lightSun(); void lightSun();
float lightSunShadow(); float lightSunShadow();
void lightPoint(int i); void lightPoint(int i);
@ -41,14 +41,12 @@ void main() {
lightSun(); lightSun();
color += vec4(fragColor.rgb * light, 0.0f); color += fragColor.rgb * light;
color.a = fragColor.a;
color.rgb = color.rgb;
float z = gl_FragCoord.z / gl_FragCoord.w; //float z = gl_FragCoord.z / gl_FragCoord.w;
float fog = clamp(exp(-fogDensity * z * z), 0.2, 1); //float fog = clamp(exp(-fogDensity * z * z), 0.2, 1);
outputColor = mix(fogColor, color, fog) * finalpha; outputColor = vec4(color, 1) * finalpha;
} }
void lightSun() { void lightSun() {
@ -63,7 +61,7 @@ void lightSun() {
float shadow = lightSunShadow(); float shadow = lightSunShadow();
light += diffuse * shadow; light += diffuse * shadow;
color += vec4(vec3(specular), 0.0f) * shadow; color += vec3(specular) * shadow;
if (specular*shadow > 1.0f) { if (specular*shadow > 1.0f) {
finalpha = min(finalpha + specular - 1.0f, 1.0f); finalpha = min(finalpha + specular - 1.0f, 1.0f);

View File

@ -10,6 +10,7 @@ import (
"edgaru089.ml/go/gl01/internal/igwrap" "edgaru089.ml/go/gl01/internal/igwrap"
"edgaru089.ml/go/gl01/internal/igwrap/backend" "edgaru089.ml/go/gl01/internal/igwrap/backend"
"edgaru089.ml/go/gl01/internal/io" "edgaru089.ml/go/gl01/internal/io"
"edgaru089.ml/go/gl01/internal/util"
"edgaru089.ml/go/gl01/internal/util/itype" "edgaru089.ml/go/gl01/internal/util/itype"
"edgaru089.ml/go/gl01/internal/world" "edgaru089.ml/go/gl01/internal/world"
"github.com/go-gl/glfw/v3.3/glfw" "github.com/go-gl/glfw/v3.3/glfw"
@ -22,6 +23,8 @@ type guiState struct {
lastframeCgoCalls int64 lastframeCgoCalls int64
lastCountSec *util.Clock
loadChunkFile string loadChunkFile string
loadChunkID [2]int32 loadChunkID [2]int32
@ -56,6 +59,10 @@ func (g *Game) imgui() {
io.Diagnostics.CgoCalls = runtime.NumCgoCall() - g.gui.lastframeCgoCalls io.Diagnostics.CgoCalls = runtime.NumCgoCall() - g.gui.lastframeCgoCalls
g.gui.lastframeCgoCalls = runtime.NumCgoCall() g.gui.lastframeCgoCalls = runtime.NumCgoCall()
/*if g.gui.lastCountSec.Elapsed() >= time.Second {
g.gui.lastCountSec.Restart()
}*/
if io.ShowDebugInfo { if io.ShowDebugInfo {
imgui.SetNextWindowPosV(imgui.Vec2{}, imgui.ConditionAlways, imgui.Vec2{}) imgui.SetNextWindowPosV(imgui.Vec2{}, imgui.ConditionAlways, imgui.Vec2{})
imgui.SetNextWindowSize(imgui.Vec2{X: float32(io.DisplaySize[0]), Y: float32(io.DisplaySize[1])}) imgui.SetNextWindowSize(imgui.Vec2{X: float32(io.DisplaySize[0]), Y: float32(io.DisplaySize[1])})