Commit 4066bf90 authored by Shu's avatar Shu 🍠
Browse files

Basic earth like generator

parent 5ac3a003
......@@ -18,10 +18,10 @@ in VertexData
{
vec3 Position_modelspace;
#ifdef GEOMETRY
flat uint Materials[3];
vec3 MaterialRatio;
flat uint Textures[3];
vec3 TextureRatio;
#else
flat uint Material;
flat uint Texture;
#endif
vec3 FaceNormal_modelspace;
#ifdef PBR
......@@ -41,24 +41,24 @@ vec3 expand(vec3 v) {
vec4 getTexture(sampler2DArray sample, vec2 UV) {
#ifdef GEOMETRY
#ifdef BLEND
vec4 colx = texture(sample, vec3(UV, vs.Materials[0]));
if(vs.Materials[1] == vs.Materials[0]) {
return vs.Materials[2] == vs.Materials[0] ? colx :
mix(colx, texture(sample, vec3(UV, vs.Materials[2])), vs.MaterialRatio.z);
vec4 colx = texture(sample, vec3(UV, vs.Textures[0]));
if(vs.Textures[1] == vs.Textures[0]) {
return vs.Textures[2] == vs.Textures[0] ? colx :
mix(colx, texture(sample, vec3(UV, vs.Textures[2])), vs.TextureRatio.z);
} else {
vec4 coly = texture(sample, vec3(UV, vs.Materials[1]));
return vs.Materials[2] == vs.Materials[0] ? mix(colx, coly, vs.MaterialRatio.y) : (
vs.Materials[2] == vs.Materials[1] ? mix(coly, colx, vs.MaterialRatio.x) :
colx * vs.MaterialRatio.x + coly * vs.MaterialRatio.y + texture(sample, vec3(UV, vs.Materials[2])) * vs.MaterialRatio.z);
vec4 coly = texture(sample, vec3(UV, vs.Textures[1]));
return vs.Textures[2] == vs.Textures[0] ? mix(colx, coly, vs.TextureRatio.y) : (
vs.Textures[2] == vs.Textures[1] ? mix(coly, colx, vs.TextureRatio.x) :
colx * vs.TextureRatio.x + coly * vs.TextureRatio.y + texture(sample, vec3(UV, vs.Textures[2])) * vs.TextureRatio.z);
}
#else
int mainMaterial = vs.MaterialRatio.x >= vs.MaterialRatio.y ?
(vs.MaterialRatio.x >= vs.MaterialRatio.z ? 0 : 2) :
(vs.MaterialRatio.y >= vs.MaterialRatio.z ? 1 : 2);
return texture(sample, vec3(UV, vs.Materials[mainMaterial]));
int mainTexture = vs.TextureRatio.x >= vs.TextureRatio.y ?
(vs.TextureRatio.x >= vs.TextureRatio.z ? 0 : 2) :
(vs.TextureRatio.y >= vs.TextureRatio.z ? 1 : 2);
return texture(sample, vec3(UV, vs.Textures[mainTexture]));
#endif
#else
return texture(sample, vec3(UV, vs.Material));
return texture(sample, vec3(UV, vs.Texture));
#endif
}
......@@ -119,10 +119,10 @@ void main() {
// Colors
#ifdef PBR
// Material properties
vec3 MaterialDiffuseColor = tex;
vec3 MaterialAmbientColor = vec3(.1) * MaterialDiffuseColor * texHOS.y;
vec3 MaterialSpecularColor = vec3(.8) * texHOS.z;
// Texture properties
vec3 TextureDiffuseColor = tex;
vec3 TextureAmbientColor = vec3(.1) * TextureDiffuseColor * texHOS.y;
vec3 TextureSpecularColor = vec3(.8) * texHOS.z;
vec3 Normal_cameraspace = normalize((View * vec4(worldNormal,0)).xyz);
......@@ -159,11 +159,11 @@ void main() {
color =
// Ambient : simulates indirect lighting
MaterialAmbientColor +
TextureAmbientColor +
// Diffuse : "color" of the object
visibility * MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance * distance) +
visibility * TextureDiffuseColor * LightColor * LightPower * cosTheta / (distance * distance) +
// Specular : reflective highlight, like a mirror
visibility * MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance * distance);
visibility * TextureSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance * distance);
#else
color = tex;
#endif
......
......@@ -6,7 +6,7 @@ layout (triangle_strip, max_vertices = 3) out;
in VertexData {
vec3 Position_modelspace;
flat uint Material;
flat uint Texture;
vec3 FaceNormal_modelspace;
#ifdef PBR
vec3 FaceNormal_worldspace;
......@@ -20,8 +20,8 @@ in VertexData {
out GeometryData {
vec3 Position_modelspace;
flat uint Materials[3];
vec3 MaterialRatio;
flat uint Textures[3];
vec3 TextureRatio;
vec3 FaceNormal_modelspace;
#ifdef PBR
vec3 FaceNormal_worldspace;
......@@ -41,19 +41,19 @@ void main() {
gs.FaceNormal_modelspace = vs_in[i].FaceNormal_modelspace;
gs.FaceNormal_worldspace = vs_in[i].FaceNormal_worldspace;
gs.Materials[i] = vs_in[i].Material;
gs.Textures[i] = vs_in[i].Texture;
switch(int(mod(i,3))) {
case 0:
gs.MaterialRatio = vec3(1,0,0);
gs.TextureRatio = vec3(1,0,0);
break;
case 1:
gs.MaterialRatio = vec3(0,1,0);
gs.TextureRatio = vec3(0,1,0);
break;
case 2:
gs.MaterialRatio = vec3(0,0,1);
gs.TextureRatio = vec3(0,0,1);
break;
default:
gs.MaterialRatio = vec3(0);
gs.TextureRatio = vec3(0);
break;
};
......
#version 330 core
layout(location = 0) in vec3 Position_modelspace;
layout(location = 1) in uint Material_model;
layout(location = 1) in uint Texture_model;
layout(location = 2) in vec3 Normal_modelspace;
out VertexData {
vec3 Position_modelspace;
flat uint Material;
flat uint Texture;
vec3 FaceNormal_modelspace;
#ifdef PBR
vec3 FaceNormal_worldspace;
......@@ -51,7 +51,7 @@ void main(){
vs.Depth = length(Position_cameraspace.xyz) / FogDepth;
#endif
vs.Material = Material_model;
vs.Texture = Texture_model;
vs.FaceNormal_modelspace = normalize(Normal_modelspace);
#ifdef PBR
......
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