Initial commit
9
internal/asset/embed.go
Normal file
@ -0,0 +1,9 @@
|
||||
package asset
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed texture
|
||||
var FS embed.FS
|
||||
|
||||
//go:embed font/unifont-11.0.02.2.ttf
|
||||
var Unifont []byte
|
BIN
internal/asset/font/unifont-11.0.02.2.ttf
Executable file
21
internal/asset/shader.go
Normal file
@ -0,0 +1,21 @@
|
||||
package asset
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed shader/world.frag
|
||||
var WorldShaderFrag string
|
||||
|
||||
//go:embed shader/world.vert
|
||||
var WorldShaderVert string
|
||||
|
||||
//go:embed shader/world.shadowmap.frag
|
||||
var WorldShaderShadowmapFrag string
|
||||
|
||||
//go:embed shader/world.shadowmap.vert
|
||||
var WorldShaderShadowmapVert string
|
||||
|
||||
//go:embed shader/framewire.frag
|
||||
var FramewireShaderFrag string
|
||||
|
||||
//go:embed shader/framewire.vert
|
||||
var FramewireShaderVert string
|
9
internal/asset/shader/framewire.frag
Normal file
@ -0,0 +1,9 @@
|
||||
#version 330
|
||||
|
||||
in vec4 fragColor;
|
||||
|
||||
out vec4 outputColor;
|
||||
|
||||
void main() {
|
||||
outputColor = fragColor;
|
||||
}
|
16
internal/asset/shader/framewire.vert
Normal file
@ -0,0 +1,16 @@
|
||||
#version 330
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
uniform mat4 model;
|
||||
|
||||
in vec3 vert;
|
||||
in vec4 vertColor;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
fragColor = vertColor;
|
||||
gl_Position = projection * view * model * vec4(vert, 1);
|
||||
}
|
||||
|
87
internal/asset/shader/world.frag
Normal file
@ -0,0 +1,87 @@
|
||||
#version 330
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D shadowmap;
|
||||
uniform vec3 viewPos;
|
||||
uniform vec3 sun;
|
||||
uniform vec4 fogColor;
|
||||
|
||||
|
||||
in vec4 fragPos;
|
||||
in vec4 fragPosLightspace;
|
||||
in vec2 fragTexCoord;
|
||||
in vec3 fragNormal;
|
||||
|
||||
out vec4 outputColor;
|
||||
|
||||
|
||||
const float gamma = 2.2;
|
||||
|
||||
const float ambient = 0.3, specularStrength = 0.5, specularShininess = 32;
|
||||
const float fogDensity = .00003;
|
||||
|
||||
|
||||
float light;
|
||||
vec4 texpixel, color;
|
||||
void lightSun();
|
||||
float lightSunShadow();
|
||||
void lightPoint(int i);
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
texpixel = texture(tex, fragTexCoord);
|
||||
if (texpixel.a < 1e-3)
|
||||
discard;
|
||||
texpixel.rgb = pow(texpixel.rgb, vec3(gamma));
|
||||
|
||||
light = ambient;
|
||||
|
||||
lightSun();
|
||||
|
||||
color += vec4(texpixel.rgb * light, 0.0f);
|
||||
color.a = texpixel.a;
|
||||
|
||||
float z = gl_FragCoord.z / gl_FragCoord.w;
|
||||
float fog = clamp(exp(-fogDensity * z * z), 0.2, 1);
|
||||
|
||||
outputColor = mix(fogColor, color, fog);
|
||||
//outputColor.rgb = pow(outputColor.rgb, vec3(1.0/gamma));
|
||||
}
|
||||
|
||||
void lightSun() {
|
||||
/* Diffuse */
|
||||
vec3 lightDir = sun;
|
||||
float diffuse = max(dot(fragNormal, lightDir), 0.0f);
|
||||
|
||||
/* Specular */
|
||||
vec3 viewDir = normalize(viewPos - fragPos.xyz);
|
||||
vec3 reflectDir = reflect(-lightDir, fragNormal);
|
||||
float specular = specularStrength * pow(max(dot(viewDir, reflectDir), 0.0), specularShininess);
|
||||
|
||||
float shadow = lightSunShadow();
|
||||
light += diffuse * shadow;
|
||||
color += vec4(vec3(specular), 0.0f) * shadow;
|
||||
}
|
||||
|
||||
float lightSunShadow() {
|
||||
/* Shadow */
|
||||
float bias = max(0.005 * (1.0 - dot(fragNormal, sun)), 0.0005);
|
||||
vec3 projCoords = fragPosLightspace.xyz / fragPosLightspace.w;
|
||||
projCoords = projCoords*0.5 + 0.5;
|
||||
//float closestDepth = texture(shadowmap, projCoords.xy).r;
|
||||
float currentDepth = projCoords.z;
|
||||
float shadow = 0;
|
||||
|
||||
if (currentDepth > 1.0f || currentDepth < 0.0f)
|
||||
return 1.0f;
|
||||
|
||||
vec2 texelSize = 1.0 / textureSize(shadowmap, 0);
|
||||
for (int x=-1; x<=1; ++x)
|
||||
for (int y=-1; y<=1; ++y) {
|
||||
float pcfDepth = texture(shadowmap, projCoords.xy + vec2(x,y)*texelSize).r;
|
||||
shadow += currentDepth-bias < pcfDepth ? 1.0f : 0.0f;
|
||||
}
|
||||
shadow /= 9.0f;
|
||||
return shadow;
|
||||
}
|
6
internal/asset/shader/world.shadowmap.frag
Normal file
@ -0,0 +1,6 @@
|
||||
#version 330
|
||||
|
||||
void main() {
|
||||
// gl_FragDepth = gl.FragCoord.z;
|
||||
}
|
||||
|
14
internal/asset/shader/world.shadowmap.vert
Normal file
@ -0,0 +1,14 @@
|
||||
#version 330
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 lightspace;
|
||||
|
||||
layout (location = 0) in vec3 vert;
|
||||
layout (location = 1) in vec3 normal;
|
||||
layout (location = 2) in vec2 vertTexCoord;
|
||||
layout (location = 3) in float light;
|
||||
|
||||
void main() {
|
||||
gl_Position = lightspace * model * vec4(vert, 1.0);
|
||||
}
|
||||
|
28
internal/asset/shader/world.vert
Normal file
@ -0,0 +1,28 @@
|
||||
#version 330
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
uniform mat4 model;
|
||||
uniform mat4 lightspace;
|
||||
|
||||
|
||||
layout (location = 0) in vec3 vert;
|
||||
layout (location = 1) in vec3 normal;
|
||||
layout (location = 2) in vec2 vertTexCoord;
|
||||
layout (location = 3) in float light;
|
||||
|
||||
out vec4 fragPos;
|
||||
out vec4 fragPosLightspace;
|
||||
out vec2 fragTexCoord;
|
||||
out vec3 fragNormal;
|
||||
|
||||
void main() {
|
||||
|
||||
fragTexCoord = vertTexCoord;
|
||||
fragNormal = normalize(normal);
|
||||
|
||||
gl_Position = projection * view * model * vec4(vert, 1);
|
||||
fragPos = model * vec4(vert, 1);
|
||||
fragPosLightspace = lightspace * fragPos;
|
||||
}
|
||||
|
43
internal/asset/texture.go
Normal file
@ -0,0 +1,43 @@
|
||||
package asset
|
||||
|
||||
import (
|
||||
_ "image/png"
|
||||
|
||||
"log"
|
||||
|
||||
"edgaru089.ml/go/gl01/internal/util"
|
||||
)
|
||||
|
||||
// WorldTextureAtlas holds all the world block textures.
|
||||
var WorldTextureAtlas util.Atlas
|
||||
|
||||
func InitWorldTextureAtlas() {
|
||||
if WorldTextureAtlas.HasBuilt() {
|
||||
return
|
||||
}
|
||||
|
||||
files, err := FS.ReadDir("texture/world")
|
||||
if err != nil {
|
||||
panic("InitWorldTextureAtlas: embed.FS.ReadDir(\"texture/world\"): " + err.Error())
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
name := f.Name()
|
||||
|
||||
file, err := FS.Open("texture/world/" + name)
|
||||
if err != nil { // Shouldn't be error?
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = WorldTextureAtlas.AddFile(name, file)
|
||||
if err != nil {
|
||||
log.Printf("WARN: InitWorldTextureAtlas: img %s failed to decode: %s", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
WorldTextureAtlas.BuildTexture( /*false*/ )
|
||||
}
|
BIN
internal/asset/texture/world/bedrock.png
Normal file
After Width: | Height: | Size: 225 B |
BIN
internal/asset/texture/world/cobblestone.png
Normal file
After Width: | Height: | Size: 568 B |
BIN
internal/asset/texture/world/cobblestone_mossy.png
Normal file
After Width: | Height: | Size: 632 B |
BIN
internal/asset/texture/world/command_block.png
Normal file
After Width: | Height: | Size: 349 B |
BIN
internal/asset/texture/world/debug.png
Normal file
After Width: | Height: | Size: 645 B |
BIN
internal/asset/texture/world/debug_dir_x+.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
internal/asset/texture/world/debug_dir_x-.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
internal/asset/texture/world/debug_dir_y+.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
internal/asset/texture/world/debug_dir_y-.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
internal/asset/texture/world/debug_dir_z+.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
internal/asset/texture/world/debug_dir_z-.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
internal/asset/texture/world/dirt.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
internal/asset/texture/world/grass_bot.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
internal/asset/texture/world/grass_side.png
Normal file
After Width: | Height: | Size: 408 B |
BIN
internal/asset/texture/world/grass_top.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
internal/asset/texture/world/grass_top_greyscale.png
Normal file
After Width: | Height: | Size: 560 B |
BIN
internal/asset/texture/world/leaves_oak.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
internal/asset/texture/world/log_oak.png
Normal file
After Width: | Height: | Size: 528 B |
BIN
internal/asset/texture/world/log_oak_bot.png
Normal file
After Width: | Height: | Size: 478 B |
BIN
internal/asset/texture/world/log_oak_top.png
Normal file
After Width: | Height: | Size: 478 B |
BIN
internal/asset/texture/world/stone.png
Normal file
After Width: | Height: | Size: 223 B |