Commit 623cbb87 authored by Shu's avatar Shu 🍠
Browse files

World pass VK and GL Mipmap load

parent 15f5b090
......@@ -9,4 +9,5 @@ layout(location = 0) out vec4 color;
void main(){
color = texture(Texture, UV);
color = pow(color, vec4(2.2)); //TODO: Space brightness option
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ layout (location = 0) in VertexData
float Depth;
} vs;
layout(location = 0) out vec3 color;
layout(location = 0) out vec4 color;
vec3 expand(vec3 v) {
return (v - 0.5) * 2;
......@@ -124,7 +124,7 @@ vec3 getTriTexture(sampler2DArray smpl, vec2 crdx, vec2 crdy, vec2 crdz, vec3 we
void main() {
float texScale = 1. / UNIT_SIZE;
vec3 tex, texN, worldNormal, texHOS;
vec3 tex, worldNormal, texHOS;
if(TRIPLANAR) {
// Triplanar
......@@ -138,7 +138,7 @@ if(TRIPLANAR) {
vec2 UVy = vs.Position_modelspace.zx * texScale;
vec2 UVz = vs.Position_modelspace.xy * texScale;
vec3 tex = getTriTexture(TextureAtlas, UVx, UVy, UVz, blendWeights);
tex = getTriTexture(TextureAtlas, UVx, UVy, UVz, blendWeights);
if(PBR) {
// Whiteout normal blend
......@@ -150,9 +150,9 @@ if(PBR) {
texNy = vec3(texNy.xy + vs.FaceNormal_worldspace.xz, abs(texNy.z) * vs.FaceNormal_worldspace.y);
texNz = vec3(texNz.xy + vs.FaceNormal_worldspace.xy, abs(texNz.z) * vs.FaceNormal_worldspace.z);
// Swizzle tangent normals to match world orientation and triblend
vec3 worldNormal = normalize(texNx.zyx * blendWeights.x + texNy.xzy * blendWeights.y +texNz.xyz * blendWeights.z);
worldNormal = normalize(texNx.zyx * blendWeights.x + texNy.xzy * blendWeights.y +texNz.xyz * blendWeights.z);
vec3 texHOS = getTriTexture(HOSAtlas, UVx, UVy, UVz, blendWeights);
texHOS = getTriTexture(HOSAtlas, UVx, UVy, UVz, blendWeights);
}
} else {
// Cheap planar
......@@ -160,16 +160,16 @@ if(PBR) {
vec3 nrm = normalize(pow(blendWeights, vec3(80 / sqrt(UNIT_SIZE))));
vec2 UV = (vec2(vs.Position_modelspace.xy * nrm.z) + vec2(vs.Position_modelspace.yz * nrm.x) + vec2(vs.Position_modelspace.zx * nrm.y)) * texScale;
vec3 tex = getTexture(TextureAtlas, UV).rgb;
tex = getTexture(TextureAtlas, UV).rgb;
if(PBR) {
vec3 texN = expand(getTexture(NormalAtlas, UV).rgb);
// Swizzle world normals into tangent space and apply Whiteout blend
// Swizzle tangent normals to match world orientation and triblend
vec3 worldNormal = normalize(vec3(texN.xy + vs.FaceNormal_worldspace.zy, abs(texN.z) * vs.FaceNormal_worldspace.x).zyx * blendWeights.x +
worldNormal = normalize(vec3(texN.xy + vs.FaceNormal_worldspace.zy, abs(texN.z) * vs.FaceNormal_worldspace.x).zyx * blendWeights.x +
vec3(texN.xy + vs.FaceNormal_worldspace.xz, abs(texN.z) * vs.FaceNormal_worldspace.y).xzy * blendWeights.y +
vec3(texN.xy + vs.FaceNormal_worldspace.xy, abs(texN.z) * vs.FaceNormal_worldspace.z).xyz * blendWeights.z);
vec3 texHOS = getTexture(HOSAtlas, UV).rgb;
texHOS = getTexture(HOSAtlas, UV).rgb;
}
}
......@@ -213,22 +213,21 @@ if(PBR) {
// MAYBE: shadow
color =
tex =
// Ambient : simulates indirect lighting
TextureAmbientColor +
// Diffuse : "color" of the object
visibility * TextureDiffuseColor * LightColor * LightPower * cosTheta / (distance * distance) +
// Specular : reflective highlight, like a mirror
visibility * TextureSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance * distance);
} else {
color = tex;
}
if(FOG) {
float ratio = exp(vs.Depth * 0.69)-1;
color = mix(color, pow(UBO.fog.rgb, vec3(2.2)), clamp(ratio, 0, 1));
tex = mix(tex, UBO.fog.rgb, clamp(ratio, 0, 1));
}
color = pow(color, vec3(1.0 / 2.2));
if(color.r > 1 || color.g > 1 || color.b > 1) {
color = vec3(1, 0, 0); //TODO: bloom
}
//TODO: check gamma color = pow(color, vec3(1.0 / 2.2));
color = vec4(tex, 1);
/*if(color.r > 1 || color.g > 1 || color.b > 1) {
color = vec4(1, 0, 0, 1); //TODO: bloom
}*/
}
\ No newline at end of file
......@@ -33,13 +33,15 @@ layout (location = 0) out GeometryData {
} gs;
void main() {
for(int j = 0; j < 3; j++) {
gs.Textures[j] = vs_in[j].Texture;
}
for(int i = 0; i < gl_in.length(); i++) {
gl_Position = gl_in[i].gl_Position;
gs.Position_modelspace = vs_in[i].Position_modelspace;
gs.FaceNormal_modelspace = vs_in[i].FaceNormal_modelspace;
gs.Textures[i] = vs_in[i].Texture;
switch(int(mod(i,3))) {
case 0:
gs.TextureRatio = vec3(1,0,0);
......@@ -60,9 +62,6 @@ if(PBR) {
gs.EyeDirection_cameraspace = vs_in[i].EyeDirection_cameraspace;
gs.LightDirection_cameraspace = vs_in[i].LightDirection_cameraspace;
}
#ifdef SHADOW
gs.ShadowCoord = vs_in[i].ShadowCoord;
#endif
if(FOG) {
gs.Depth = vs_in[i].Depth;
}
......
......@@ -37,6 +37,12 @@ Stone_Wall_008_NORM.jpg terrain/Stone_wall.nrm.dds
Water_002_COLOR.jpg terrain/Water.dds
Water_002_HOS.jpg terrain/Water.hos.dds
Water_002_NORM.jpg terrain/Water.nrm.dds
Debug.cube.back.png sky/Debug.cube.back.dds
Debug.cube.bottom.png sky/Debug.cube.bottom.dds
Debug.cube.front.png sky/Debug.cube.front.dds
Debug.cube.left.png sky/Debug.cube.left.dds
Debug.cube.right.png sky/Debug.cube.right.dds
Debug.cube.top.png sky/Debug.cube.top.dds
Space_orange.cube.back.png sky/Space_orange.cube.back.dds
Space_orange.cube.bottom.png sky/Space_orange.cube.bottom.dds
Space_orange.cube.front.png sky/Space_orange.cube.front.dds
......
......@@ -55,7 +55,7 @@ void Client::run(server_handle* const localHandle) {
}
camera.update();
pipeline->lookFrom(camera);
pipeline->LightInvDir = glm::vec3(glm::rotate(glm::mat4(1), deltaTime * .1f, glm::vec3(1, .5, .1)) * glm::vec4(pipeline->LightInvDir, 0));
pipeline->LightInvDir = glm::vec3(glm::rotate(glm::mat4(1), deltaTime * .5f, glm::vec3(1, .5, .1)) * glm::vec4(pipeline->LightInvDir, 0));
{
const auto ray_result = world->raycast(camera.getRay() * options.voxel_density);
......@@ -101,7 +101,7 @@ void Client::run(server_handle* const localHandle) {
pipeline->reloadShaders(options.renderer.voxel);
}
if(actions && render::UI::Actions::RendererTextures) {
pipeline->reloadTextures(options.renderer.textures, options.renderer.mipMapLOD, options.renderer.anisotropy);
pipeline->reloadTextures(options.renderer.textures, options.renderer.getMipmapLodBias(), options.renderer.getAnisotropy());
}
if(actions && render::UI::Actions::World) {
//FIXME: server options world->setOptions(options.world);
......@@ -159,10 +159,13 @@ void Client::run(server_handle* const localHandle) {
};*/
//world->getEntitiesModels(draw, frustum, offset, options.voxel_density);
}
if(state.look_at.has_value()) { // Indicator
const auto model = glm::scale(glm::translate(glm::scale(glm::mat4(1), 1.f / glm::vec3(options.voxel_density)), glm::vec3(state.look_at.value().pos.second + state.look_at.value().offset - offset * glm::llvec3(options.voxel_density)) - glm::vec3(.5 + options.editor.tool.radius)), glm::vec3(1 + options.editor.tool.radius * 2));
reports.models_count++;
reports.tris_count += pipeline->drawIndicatorCube(model);
{
const auto pass = pipeline->beginIndicatorPass();
if(state.look_at.has_value()) { // Indicator
const auto model = glm::scale(glm::translate(glm::scale(glm::mat4(1), 1.f / glm::vec3(options.voxel_density)), glm::vec3(state.look_at.value().pos.second + state.look_at.value().offset - offset * glm::llvec3(options.voxel_density)) - glm::vec3(.5 + options.editor.tool.radius)), glm::vec3(1 + options.editor.tool.radius * 2));
reports.models_count++;
reports.tris_count += pass(model);
}
}
pipeline->postProcess();
render::UI::Get()->render();
......
......@@ -35,8 +35,8 @@ public:
preferVulkan = config["render"]["prefer_vulkan"].value_or(preferVulkan);
renderer.textures = config["render"]["textures"].value_or(renderer.textures);
renderer.mipMapLOD = config["render"]["texture_quality"].value_or(renderer.mipMapLOD);
renderer.anisotropy = config["render"]["texture_angular_quality"].value_or(renderer.anisotropy);
renderer.textureQuality = config["render"]["texture_quality"].value_or(renderer.textureQuality);
renderer.textureSharpness = config["render"]["texture_angular_quality"].value_or(renderer.textureSharpness);
renderer.voxel.pbr = config["render"]["pbr"].value_or(renderer.voxel.pbr);
renderer.voxel.triplanar = config["render"]["triplanar"].value_or(renderer.voxel.triplanar);
renderer.voxel.stochastic = config["render"]["stochastic"].value_or(renderer.voxel.stochastic);
......@@ -103,8 +103,8 @@ public:
config.insert_or_assign("render", toml::table({
{"prefer_vulkan", preferVulkan},
{"textures", renderer.textures},
{"texture_quality", renderer.mipMapLOD},
{"texture_angular_quality", renderer.anisotropy},
{"texture_quality", renderer.textureQuality},
{"texture_angular_quality", renderer.textureSharpness},
{"pbr", renderer.voxel.pbr},
{"triplanar", renderer.voxel.triplanar},
{"stochastic", renderer.voxel.stochastic},
......
......@@ -22,7 +22,7 @@ struct passOptions {
/// Transform texture UV
bool stochastic = false;
/// Active geometry pass
bool geometry = false;
bool geometry = true;
/// Blend voxel with mixed materials (requires geometry)
bool blend = true;
/// Depth fog
......@@ -44,14 +44,17 @@ struct renderOptions {
/// Texture pack name
std::string textures = "1024-realistic";
/// Textures quality
float mipMapLOD = -.5;
int textureQuality = 100;
/// Textures anisotropic mapping
int anisotropy = 0;
int textureSharpness = 0;
/// Depth color
glm::vec4 clear_color;
/// Parallel processing frames
/// Incease FPS but also a bit latency (Vulkan only)
int inFlightFrames = 2;
constexpr float getMipmapLodBias() const { return 1 - (textureQuality / 100.f); }
constexpr int getAnisotropy() const { return textureSharpness >= 1 ? (1 << (textureSharpness - 1)) : 0; }
};
/// Rendering plateform interface
......@@ -69,7 +72,7 @@ public:
/// Get started entity program
virtual std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> beginEntityPass() = 0;
/// Draw cube indicator
virtual size_t drawIndicatorCube(glm::mat4 model) = 0;
virtual std::function<size_t(glm::mat4)> beginIndicatorPass() = 0;
/// Apply postprocessing
virtual void postProcess() = 0;
/// Finalise frame
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment