Sync laptop and desktop
This commit is contained in:
parent
4966258935
commit
b162bdd8d2
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,3 +11,7 @@
|
|||||||
|
|
||||||
/Telephone-*.jar
|
/Telephone-*.jar
|
||||||
/hs_err_pid*
|
/hs_err_pid*
|
||||||
|
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
@ -8,8 +8,8 @@
|
|||||||
"graphicsFOV" : 90.0,
|
"graphicsFOV" : 90.0,
|
||||||
|
|
||||||
|
|
||||||
"graphicsPerformanceLODChunkRadius" : 2,
|
"graphicsPerformanceLODChunkRadius" : 3,
|
||||||
"graphicsPerformanceEnableVSync" : true,
|
"graphicsPerformanceEnableVSync" : false,
|
||||||
"graphicsPerformanceDrawShadows" : true,
|
"graphicsPerformanceDrawShadows" : true,
|
||||||
|
|
||||||
"graphicsDebugDrawCollisionSpheres" : false,
|
"graphicsDebugDrawCollisionSpheres" : false,
|
||||||
|
|||||||
@ -88,8 +88,8 @@
|
|||||||
"movementSystems" : [
|
"movementSystems" : [
|
||||||
{
|
{
|
||||||
"type" : "GROUND",
|
"type" : "GROUND",
|
||||||
"acceleration" : 0.001,
|
"acceleration" : 0.05,
|
||||||
"maxVelocity" : 0.025
|
"maxVelocity" : 0.25
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"physicsObject" : {
|
"physicsObject" : {
|
||||||
|
|||||||
237
assets/Shaders/terrain/terrain.fs
Normal file
237
assets/Shaders/terrain/terrain.fs
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#version 410 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
sampler2D diffuse;
|
||||||
|
sampler2D specular;
|
||||||
|
float shininess;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DirLight {
|
||||||
|
vec3 direction;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PointLight {
|
||||||
|
vec3 position;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SpotLight {
|
||||||
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
float cutOff;
|
||||||
|
float outerCutOff;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NR_POINT_LIGHTS 10
|
||||||
|
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
in vec2 TexCoord;
|
||||||
|
in vec4 FragPosLightSpace;
|
||||||
|
in vec4 groundTexIndices;
|
||||||
|
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
uniform DirLight dirLight;
|
||||||
|
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||||
|
uniform SpotLight spotLight;
|
||||||
|
uniform Material material;
|
||||||
|
|
||||||
|
//texture stuff
|
||||||
|
// uniform sampler2D ourTexture;
|
||||||
|
uniform int hasTransparency;
|
||||||
|
// uniform sampler2D specularTexture;
|
||||||
|
|
||||||
|
//light depth map
|
||||||
|
uniform sampler2D shadowMap;
|
||||||
|
|
||||||
|
//textures
|
||||||
|
//
|
||||||
|
// Goal is to have a texture for the current chunk and one for each nearnby chunk
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
uniform sampler2D groundTextures1;
|
||||||
|
uniform sampler2D groundTextures2;
|
||||||
|
uniform sampler2D groundTextures3;
|
||||||
|
uniform sampler2D groundTextures4;
|
||||||
|
uniform sampler2D groundTextures5;
|
||||||
|
uniform sampler2D groundTextures[10];
|
||||||
|
|
||||||
|
// function prototypes
|
||||||
|
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir, vec3 texColor);
|
||||||
|
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||||
|
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||||
|
float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal);
|
||||||
|
vec3 blendedTextureColor(vec2 texPos, vec4 tex1, vec4 tex2, vec4 tex3, vec4 tex4);
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
if(hasTransparency == 1){
|
||||||
|
if(texture(material.diffuse, TexCoord).a < 0.1){
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vec3 norm = normalize(Normal);
|
||||||
|
vec3 viewDir = normalize(viewPos - FragPos);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// sampler2DArray text = groundTextures;
|
||||||
|
// sampler2D test = groundTextures1;
|
||||||
|
vec4 texColor1 = texture(groundTextures[int(groundTexIndices.x * 2)], TexCoord);
|
||||||
|
vec4 texColor2 = texture(groundTextures[int(groundTexIndices.y * 2)], TexCoord);
|
||||||
|
vec4 texColor3 = texture(groundTextures[int(groundTexIndices.z * 2)], TexCoord);
|
||||||
|
vec4 texColor4 = texture(groundTextures[int(groundTexIndices.w * 2)], TexCoord);
|
||||||
|
vec3 finalTexColor = blendedTextureColor(TexCoord, texColor1, texColor2, texColor3, texColor4);
|
||||||
|
// vec4 tex2 = texture(groundTextures[int(groundTexIndices.y)], TexCoord);
|
||||||
|
// vec4 tex3 = texture2D(groundTextures[int(groundTexIndex.z * 2)], texPos);
|
||||||
|
// vec4 tex4 = texture2D(groundTextures[int(groundTexIndex.w * 2)], texPos);
|
||||||
|
|
||||||
|
//get texture color
|
||||||
|
// vec3 texColor = vec3(0,0,1);//blendedTextureColor(texPos, groundTexIndices);
|
||||||
|
|
||||||
|
|
||||||
|
vec3 result = CalcDirLight(dirLight, norm, viewDir, finalTexColor);
|
||||||
|
//for(int i = 0; i < NR_POINT_LIGHTS; i++){
|
||||||
|
// result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||||
|
//}
|
||||||
|
//result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
|
||||||
|
|
||||||
|
FragColor = vec4(result, texture(material.diffuse, TexCoord).a);//texture(ourTexture, TexCoord);//vec4(result, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculates the color when using a directional light.
|
||||||
|
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir, vec3 texColor){
|
||||||
|
vec3 lightDir = normalize(-light.direction);
|
||||||
|
// diffuse shading
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
// specular shading
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
|
// combine results
|
||||||
|
// vec3 texColor = texture(material.diffuse, TexCoord).rgb;
|
||||||
|
vec3 ambient = light.ambient;
|
||||||
|
vec3 diffuse = light.diffuse * diff;
|
||||||
|
//vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoord).rgb);
|
||||||
|
|
||||||
|
|
||||||
|
float shadow = ShadowCalculation(FragPosLightSpace, lightDir, normal);
|
||||||
|
|
||||||
|
return ( ambient + (1.0-shadow) * diffuse ) * texColor;// + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// calculates the color when using a point light.
|
||||||
|
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir){
|
||||||
|
vec3 lightDir = normalize(light.position - fragPos);
|
||||||
|
// diffuse shading
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
// specular shading
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
|
// attenuation
|
||||||
|
float distance = length(light.position - fragPos);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||||
|
// combine results
|
||||||
|
vec3 ambient = light.ambient * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||||
|
vec3 diffuse = light.diffuse * diff * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||||
|
vec3 specular = light.specular * spec * vec4(texture(material.specular, TexCoord)).xyz;
|
||||||
|
ambient *= attenuation;
|
||||||
|
diffuse *= attenuation;
|
||||||
|
specular *= attenuation;
|
||||||
|
return (ambient + diffuse + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculates the color when using a spot light.
|
||||||
|
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||||
|
{
|
||||||
|
vec3 lightDir = normalize(light.position - fragPos);
|
||||||
|
// diffuse shading
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
// specular shading
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
|
// attenuation
|
||||||
|
float distance = length(light.position - fragPos);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||||
|
// spotlight intensity
|
||||||
|
float theta = dot(lightDir, normalize(-light.direction));
|
||||||
|
float epsilon = light.cutOff - light.outerCutOff;
|
||||||
|
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);
|
||||||
|
// combine results
|
||||||
|
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoord));
|
||||||
|
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoord));
|
||||||
|
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoord));
|
||||||
|
ambient *= attenuation * intensity;
|
||||||
|
diffuse *= attenuation * intensity;
|
||||||
|
specular *= attenuation * intensity;
|
||||||
|
return (ambient + diffuse + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal){
|
||||||
|
|
||||||
|
// perform perspective divide
|
||||||
|
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||||
|
|
||||||
|
//transform to NDC
|
||||||
|
projCoords = projCoords * 0.5 + 0.5;
|
||||||
|
|
||||||
|
//get closest depth from light's POV
|
||||||
|
float closestDepth = texture(shadowMap, projCoords.xy).r;
|
||||||
|
|
||||||
|
//get depth of current fragment
|
||||||
|
float currentDepth = projCoords.z;
|
||||||
|
|
||||||
|
//calculate bias
|
||||||
|
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
|
||||||
|
|
||||||
|
//calculate shadow value
|
||||||
|
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
||||||
|
|
||||||
|
if(projCoords.z > 1.0){
|
||||||
|
shadow = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// shadow = currentDepth;
|
||||||
|
|
||||||
|
return shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vec3 blendedTextureColor(vec2 texPos, vec4 tex1, vec4 tex2, vec4 tex3, vec4 tex4){
|
||||||
|
// int texIndex1 = int(groundTexIndex.x * 2);
|
||||||
|
// int texIndex2 = int(groundTexIndex.y * 2);
|
||||||
|
// int texIndex3 = int(groundTexIndex.z * 2);
|
||||||
|
// int texIndex4 = int(groundTexIndex.w * 2);
|
||||||
|
// vec4 tex1 = texture2D(groundTextures[int(groundTexIndex.x * 2)], texPos);
|
||||||
|
// vec4 tex2 = texture2D(groundTextures[int(groundTexIndex.y * 2)], texPos);
|
||||||
|
// vec4 tex3 = texture2D(groundTextures[int(groundTexIndex.z * 2)], texPos);
|
||||||
|
// vec4 tex4 = texture2D(groundTextures[int(groundTexIndex.w * 2)], texPos);
|
||||||
|
// float percentTex1 = (texPos.x - 1) * (texPos.y - 1);
|
||||||
|
// float percentTex2 = (texPos.x - 0) * (texPos.y - 1);
|
||||||
|
// float percentTex3 = (texPos.x - 1) * (texPos.y - 0);
|
||||||
|
// float percentTex4 = (texPos.x - 0) * (texPos.y - 0);
|
||||||
|
return vec3(0,0,0);//mix(mix(tex1,tex2,texPos.x),mix(tex3,tex4,texPos.x),texPos.y).rgb;
|
||||||
|
}
|
||||||
220
assets/Shaders/terrain/terrain.fs.bak
Normal file
220
assets/Shaders/terrain/terrain.fs.bak
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
sampler2D diffuse;
|
||||||
|
sampler2D specular;
|
||||||
|
float shininess;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DirLight {
|
||||||
|
vec3 direction;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PointLight {
|
||||||
|
vec3 position;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SpotLight {
|
||||||
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
float cutOff;
|
||||||
|
float outerCutOff;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NR_POINT_LIGHTS 10
|
||||||
|
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
in vec2 TexCoord;
|
||||||
|
in vec4 FragPosLightSpace;
|
||||||
|
in ivec4 groundTexIndices;
|
||||||
|
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
uniform DirLight dirLight;
|
||||||
|
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||||
|
uniform SpotLight spotLight;
|
||||||
|
uniform Material material;
|
||||||
|
|
||||||
|
//texture stuff
|
||||||
|
// uniform sampler2D ourTexture;
|
||||||
|
uniform int hasTransparency;
|
||||||
|
// uniform sampler2D specularTexture;
|
||||||
|
|
||||||
|
//light depth map
|
||||||
|
uniform sampler2D shadowMap;
|
||||||
|
|
||||||
|
//textures
|
||||||
|
//
|
||||||
|
// Goal is to have a texture for the current chunk and one for each nearnby chunk
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// uniform sampler2D groundTextures[10];
|
||||||
|
|
||||||
|
|
||||||
|
// function prototypes
|
||||||
|
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir);
|
||||||
|
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||||
|
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||||
|
float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal);
|
||||||
|
vec3 blendedTextureColor(vec2 texPos, ivec4 groundTexIndex);
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
if(hasTransparency == 1){
|
||||||
|
if(texture(material.diffuse, TexCoord).a < 0.1){
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vec3 norm = normalize(Normal);
|
||||||
|
vec3 viewDir = normalize(viewPos - FragPos);
|
||||||
|
|
||||||
|
//get texture color
|
||||||
|
vec3 texColor = vec3(0,0,1);//blendedTextureColor(texPos, groundTexIndices);
|
||||||
|
|
||||||
|
|
||||||
|
vec3 result = CalcDirLight(dirLight, norm, viewDir);
|
||||||
|
//for(int i = 0; i < NR_POINT_LIGHTS; i++){
|
||||||
|
// result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||||
|
//}
|
||||||
|
//result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
|
||||||
|
|
||||||
|
FragColor = vec4(result, texture(material.diffuse, TexCoord).a);
|
||||||
|
// FragColor = vec4(result, 1);//texture(ourTexture, TexCoord);//vec4(result, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculates the color when using a directional light.
|
||||||
|
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir, vec3 texColor){
|
||||||
|
// //get texture color
|
||||||
|
// vec3 texColor = vec3(1,0,0);//blendedTextureColor(texPos, groundTexIndices);
|
||||||
|
//get light direction
|
||||||
|
vec3 lightDir = normalize(-light.direction);
|
||||||
|
// diffuse shading
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
// specular shading
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
|
// combine results
|
||||||
|
// vec3 texColor = texture(material.diffuse, TexCoord).rgb;
|
||||||
|
vec3 ambient = light.ambient;
|
||||||
|
vec3 diffuse = light.diffuse * diff;
|
||||||
|
//vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoord).rgb);
|
||||||
|
|
||||||
|
|
||||||
|
float shadow = ShadowCalculation(FragPosLightSpace, lightDir, normal);
|
||||||
|
|
||||||
|
return ( ambient + (1.0-shadow) * diffuse ) * texColor;// + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// calculates the color when using a point light.
|
||||||
|
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir){
|
||||||
|
vec3 lightDir = normalize(light.position - fragPos);
|
||||||
|
// diffuse shading
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
// specular shading
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
|
// attenuation
|
||||||
|
float distance = length(light.position - fragPos);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||||
|
// combine results
|
||||||
|
vec3 ambient = light.ambient * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||||
|
vec3 diffuse = light.diffuse * diff * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||||
|
vec3 specular = light.specular * spec * vec4(texture(material.specular, TexCoord)).xyz;
|
||||||
|
ambient *= attenuation;
|
||||||
|
diffuse *= attenuation;
|
||||||
|
specular *= attenuation;
|
||||||
|
return (ambient + diffuse + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculates the color when using a spot light.
|
||||||
|
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||||
|
{
|
||||||
|
vec3 lightDir = normalize(light.position - fragPos);
|
||||||
|
// diffuse shading
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
// specular shading
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
|
// attenuation
|
||||||
|
float distance = length(light.position - fragPos);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||||
|
// spotlight intensity
|
||||||
|
float theta = dot(lightDir, normalize(-light.direction));
|
||||||
|
float epsilon = light.cutOff - light.outerCutOff;
|
||||||
|
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);
|
||||||
|
// combine results
|
||||||
|
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoord));
|
||||||
|
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoord));
|
||||||
|
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoord));
|
||||||
|
ambient *= attenuation * intensity;
|
||||||
|
diffuse *= attenuation * intensity;
|
||||||
|
specular *= attenuation * intensity;
|
||||||
|
return (ambient + diffuse + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal){
|
||||||
|
|
||||||
|
// perform perspective divide
|
||||||
|
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||||
|
|
||||||
|
//transform to NDC
|
||||||
|
projCoords = projCoords * 0.5 + 0.5;
|
||||||
|
|
||||||
|
//get closest depth from light's POV
|
||||||
|
float closestDepth = texture(shadowMap, projCoords.xy).r;
|
||||||
|
|
||||||
|
//get depth of current fragment
|
||||||
|
float currentDepth = projCoords.z;
|
||||||
|
|
||||||
|
//calculate bias
|
||||||
|
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
|
||||||
|
|
||||||
|
//calculate shadow value
|
||||||
|
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
||||||
|
|
||||||
|
if(projCoords.z > 1.0){
|
||||||
|
shadow = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// shadow = currentDepth;
|
||||||
|
|
||||||
|
return shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// vec3 blendedTextureColor(vec2 texPos, ivec4 groundTexIndex){
|
||||||
|
// vec4 tex1 = texture2D(groundTextures[groundTexIndex.x * 2], texPos);
|
||||||
|
// vec4 tex2 = texture2D(groundTextures[groundTexIndex.y * 2], texPos);
|
||||||
|
// vec4 tex3 = texture2D(groundTextures[groundTexIndex.z * 2], texPos);
|
||||||
|
// vec4 tex4 = texture2D(groundTextures[groundTexIndex.w * 2], texPos);
|
||||||
|
// // float percentTex1 = (texPos.x - 1) * (texPos.y - 1);
|
||||||
|
// // float percentTex2 = (texPos.x - 0) * (texPos.y - 1);
|
||||||
|
// // float percentTex3 = (texPos.x - 1) * (texPos.y - 0);
|
||||||
|
// // float percentTex4 = (texPos.x - 0) * (texPos.y - 0);
|
||||||
|
// return mix(mix(tex1,tex2,texPos.x),mix(tex3,tex4,texPos.x),texPos.y).rgb;
|
||||||
|
// }
|
||||||
52
assets/Shaders/terrain/terrain.vs
Normal file
52
assets/Shaders/terrain/terrain.vs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
//Vertex Shader
|
||||||
|
#version 410 core
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//input buffers
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aNormal;
|
||||||
|
layout (location = 4) in vec2 aTex;
|
||||||
|
layout (location = 5) in ivec4 aGroundTexIndices;
|
||||||
|
|
||||||
|
|
||||||
|
//coordinate space transformation matrices
|
||||||
|
uniform mat4 transform;
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
uniform mat4 lightSpaceMatrix;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//output buffers
|
||||||
|
out vec3 Normal;
|
||||||
|
out vec3 FragPos;
|
||||||
|
out vec2 TexCoord;
|
||||||
|
out vec4 FragPosLightSpace;
|
||||||
|
out vec4 groundTexIndices;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
//normalize posiiton and normal
|
||||||
|
vec4 FinalVertex = vec4(aPos, 1.0);
|
||||||
|
vec4 FinalNormal = vec4(aNormal, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//push frag, normal, and texture positions to fragment shader
|
||||||
|
FragPos = vec3(model * FinalVertex);
|
||||||
|
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||||
|
TexCoord = aTex;
|
||||||
|
|
||||||
|
//push texure indices to fragment shader
|
||||||
|
groundTexIndices = groundTexIndices;
|
||||||
|
|
||||||
|
//shadow map stuff
|
||||||
|
FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//set final position with opengl space
|
||||||
|
gl_Position = projection * view * model * FinalVertex;
|
||||||
|
}
|
||||||
@ -38,6 +38,7 @@ public class CollisionObjUtils {
|
|||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
||||||
|
|
||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
@ -63,6 +64,7 @@ public class CollisionObjUtils {
|
|||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
||||||
|
|
||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
@ -87,6 +89,7 @@ public class CollisionObjUtils {
|
|||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
||||||
|
|
||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
|
|||||||
@ -32,6 +32,7 @@ public class HitboxUtils {
|
|||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
||||||
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
||||||
Globals.hitboxManager.registerHitbox(rVal);
|
Globals.hitboxManager.registerHitbox(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
@ -47,6 +48,7 @@ public class HitboxUtils {
|
|||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
||||||
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
||||||
Globals.hitboxManager.registerHitbox(rVal);
|
Globals.hitboxManager.registerHitbox(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package electrosphere.game.server.culture.religion;
|
package electrosphere.game.server.culture.religion;
|
||||||
|
|
||||||
|
import electrosphere.game.server.character.diety.Diety;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Religion {
|
public class Religion {
|
||||||
|
List<Diety> dietyList;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
package electrosphere.game.server.culture.religion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author satellite
|
||||||
|
*/
|
||||||
|
public class Story {
|
||||||
|
static enum StoryType {
|
||||||
|
FABLE, //a story including animals/things that explains a moral
|
||||||
|
MYTH, //an explanation for some fact
|
||||||
|
PARABLE, //a story strictly starring humans that explains a moral
|
||||||
|
}
|
||||||
|
|
||||||
|
StoryType type;
|
||||||
|
}
|
||||||
@ -172,6 +172,7 @@ public class Globals {
|
|||||||
public static TextureMap textureMapDefault;
|
public static TextureMap textureMapDefault;
|
||||||
|
|
||||||
public static ShaderProgram defaultMeshShader;
|
public static ShaderProgram defaultMeshShader;
|
||||||
|
public static ShaderProgram terrainShaderProgram;
|
||||||
|
|
||||||
public static Menu currentMenu;
|
public static Menu currentMenu;
|
||||||
|
|
||||||
@ -320,6 +321,8 @@ public class Globals {
|
|||||||
loadingBox = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true);
|
loadingBox = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true);
|
||||||
//init default shaderProgram
|
//init default shaderProgram
|
||||||
defaultMeshShader = ShaderProgram.smart_assemble_shader(false,true);
|
defaultMeshShader = ShaderProgram.smart_assemble_shader(false,true);
|
||||||
|
//init terrain shader program
|
||||||
|
terrainShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/terrain/terrain.vs", "/Shaders/terrain/terrain.fs");
|
||||||
//init skybox
|
//init skybox
|
||||||
assetManager.registerModelToSpecificString(RenderUtils.createSkyboxModel(null), AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
|
assetManager.registerModelToSpecificString(RenderUtils.createSkyboxModel(null), AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
|
||||||
//init models
|
//init models
|
||||||
|
|||||||
@ -115,7 +115,7 @@ public class Main {
|
|||||||
Globals.initGlobals();
|
Globals.initGlobals();
|
||||||
|
|
||||||
//debug: create terrain/world viewer
|
//debug: create terrain/world viewer
|
||||||
// TerrainViewer.runViewer();
|
TerrainViewer.runViewer();
|
||||||
|
|
||||||
//create the drawing context
|
//create the drawing context
|
||||||
Globals.renderingEngine = new RenderingEngine();
|
Globals.renderingEngine = new RenderingEngine();
|
||||||
|
|||||||
@ -4,11 +4,13 @@ import electrosphere.entity.CameraEntityUtils;
|
|||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.main.Main;
|
import electrosphere.main.Main;
|
||||||
import electrosphere.renderer.light.LightBuffer;
|
import electrosphere.renderer.light.LightBuffer;
|
||||||
|
import electrosphere.renderer.texture.Texture;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
@ -71,6 +73,10 @@ public class Mesh {
|
|||||||
boolean hasBones = true;
|
boolean hasBones = true;
|
||||||
public boolean hasTextureCoords = true;
|
public boolean hasTextureCoords = true;
|
||||||
|
|
||||||
|
public List<Texture> textureList;
|
||||||
|
public boolean useTextureList;
|
||||||
|
public String textureListArrayUniformName;
|
||||||
|
|
||||||
public float vertexMinX;
|
public float vertexMinX;
|
||||||
public float vertexMaxX;
|
public float vertexMaxX;
|
||||||
public float vertexMinY;
|
public float vertexMinY;
|
||||||
@ -572,7 +578,7 @@ public class Mesh {
|
|||||||
glEnableVertexAttribArray(4);
|
glEnableVertexAttribArray(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bufferCustomAttribArray(FloatBuffer buffer, int bufferDimension, int attribIndex){
|
public void bufferCustomFloatAttribArray(FloatBuffer buffer, int bufferDimension, int attribIndex){
|
||||||
int customBuffer = glGenBuffers();
|
int customBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
||||||
@ -580,6 +586,20 @@ public class Mesh {
|
|||||||
glEnableVertexAttribArray(attribIndex);
|
glEnableVertexAttribArray(attribIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void bufferCustomIntAttribArray(IntBuffer buffer, int bufferDimension, int attribIndex){
|
||||||
|
int customBuffer = glGenBuffers();
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
||||||
|
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
||||||
|
glVertexAttribPointer(attribIndex, bufferDimension, GL_INT, false, 0, 0);
|
||||||
|
glEnableVertexAttribArray(attribIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextureList(List<Texture> textureList, String uniformName){
|
||||||
|
this.textureList = textureList;
|
||||||
|
useTextureList = true;
|
||||||
|
textureListArrayUniformName = uniformName;
|
||||||
|
}
|
||||||
|
|
||||||
public void set_material(Material input){
|
public void set_material(Material input){
|
||||||
this.material = input;
|
this.material = input;
|
||||||
}
|
}
|
||||||
@ -724,7 +744,7 @@ public class Mesh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(useMaterial){
|
if(useMaterial && !useTextureList){
|
||||||
if(material == null){
|
if(material == null){
|
||||||
Globals.materialDefault.apply_material(0,1);
|
Globals.materialDefault.apply_material(0,1);
|
||||||
GL20.glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "hasTransparency"), 0);
|
GL20.glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "hasTransparency"), 0);
|
||||||
@ -738,6 +758,12 @@ public class Mesh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(useTextureList){
|
||||||
|
for(Texture texture : textureList){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glBindVertexArray(vertexArrayObject);
|
glBindVertexArray(vertexArrayObject);
|
||||||
|
|||||||
@ -16,153 +16,153 @@ import static org.lwjgl.opengl.GL30.glGenVertexArrays;
|
|||||||
* @author satellite
|
* @author satellite
|
||||||
*/
|
*/
|
||||||
public class ModelUtils {
|
public class ModelUtils {
|
||||||
public static Model createTerrainModel(float[][] heightfield, int stride){
|
// public static Model createTerrainModel(float[][] heightfield, int stride){
|
||||||
Model rVal = new Model();
|
// Model rVal = new Model();
|
||||||
rVal.meshes = new ArrayList();
|
// rVal.meshes = new ArrayList();
|
||||||
Mesh m = new Mesh();
|
// Mesh m = new Mesh();
|
||||||
int width = heightfield.length;
|
// int width = heightfield.length;
|
||||||
int height = heightfield[0].length;
|
// int height = heightfield[0].length;
|
||||||
|
//
|
||||||
int actualWidth = (int)Math.ceil(1.0 * width / stride);
|
// int actualWidth = (int)Math.ceil(1.0 * width / stride);
|
||||||
int actualHeight = (int)Math.ceil(1.0 * height / stride);
|
// int actualHeight = (int)Math.ceil(1.0 * height / stride);
|
||||||
|
//
|
||||||
// System.out.println(actualWidth + " " + actualHeight);
|
//// System.out.println(actualWidth + " " + actualHeight);
|
||||||
|
//
|
||||||
// System.out.println((actualWidth - 1) * (actualHeight - 1));
|
//// System.out.println((actualWidth - 1) * (actualHeight - 1));
|
||||||
|
//
|
||||||
FloatBuffer vertices = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 3);
|
// FloatBuffer vertices = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 3);
|
||||||
FloatBuffer normals = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 3);
|
// FloatBuffer normals = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 3);
|
||||||
IntBuffer faces = BufferUtils.createIntBuffer((actualWidth - 1) * (actualHeight - 1) * 2 * 3);
|
// IntBuffer faces = BufferUtils.createIntBuffer((actualWidth - 1) * (actualHeight - 1) * 2 * 3);
|
||||||
FloatBuffer texture_coords = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 2);
|
// FloatBuffer texture_coords = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 2);
|
||||||
for(int x = 0; x < width; x = x + stride){
|
// for(int x = 0; x < width; x = x + stride){
|
||||||
for(int y = 0; y < height; y = y + stride){
|
// for(int y = 0; y < height; y = y + stride){
|
||||||
//deal with vertex
|
// //deal with vertex
|
||||||
vertices.put(x);
|
// vertices.put(x);
|
||||||
vertices.put(heightfield[x][y]);
|
// vertices.put(heightfield[x][y]);
|
||||||
vertices.put(y);
|
// vertices.put(y);
|
||||||
//deal with normal
|
// //deal with normal
|
||||||
if(x / stride < actualWidth - 1){
|
// if(x / stride < actualWidth - 1){
|
||||||
if(y / stride < actualHeight - 1){
|
// if(y / stride < actualHeight - 1){
|
||||||
float hL;
|
// float hL;
|
||||||
if(x > 0){
|
// if(x > 0){
|
||||||
hL = heightfield[x-1][y];
|
// hL = heightfield[x-1][y];
|
||||||
} else {
|
// } else {
|
||||||
hL = heightfield[x][y];
|
// hL = heightfield[x][y];
|
||||||
}
|
// }
|
||||||
float hR = heightfield[x+1][y];
|
// float hR = heightfield[x+1][y];
|
||||||
float hD = heightfield[x][y+1];
|
// float hD = heightfield[x][y+1];
|
||||||
float hU;
|
// float hU;
|
||||||
if(y > 0){
|
// if(y > 0){
|
||||||
hU = heightfield[x][y-1];
|
// hU = heightfield[x][y-1];
|
||||||
} else {
|
// } else {
|
||||||
hU = heightfield[x][y];
|
// hU = heightfield[x][y];
|
||||||
}
|
// }
|
||||||
Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
// Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
||||||
Normal.normalize();
|
// Normal.normalize();
|
||||||
normals.put(Normal.x);
|
// normals.put(Normal.x);
|
||||||
normals.put(Normal.y);
|
// normals.put(Normal.y);
|
||||||
normals.put(Normal.z);
|
// normals.put(Normal.z);
|
||||||
} else {
|
// } else {
|
||||||
float hL;
|
// float hL;
|
||||||
if(x > 0){
|
// if(x > 0){
|
||||||
hL = heightfield[x-1][y];
|
// hL = heightfield[x-1][y];
|
||||||
} else {
|
// } else {
|
||||||
hL = heightfield[x][y];
|
// hL = heightfield[x][y];
|
||||||
}
|
// }
|
||||||
float hR = heightfield[x+1][y];
|
// float hR = heightfield[x+1][y];
|
||||||
float hD = heightfield[x][y];
|
// float hD = heightfield[x][y];
|
||||||
float hU = heightfield[x][y-1];
|
// float hU = heightfield[x][y-1];
|
||||||
Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
// Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
||||||
Normal.normalize();
|
// Normal.normalize();
|
||||||
normals.put(Normal.x);
|
// normals.put(Normal.x);
|
||||||
normals.put(Normal.y);
|
// normals.put(Normal.y);
|
||||||
normals.put(Normal.z);
|
// normals.put(Normal.z);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if(y / stride < actualHeight - 1){
|
// if(y / stride < actualHeight - 1){
|
||||||
float hL = heightfield[x-1][y];
|
// float hL = heightfield[x-1][y];
|
||||||
float hR = heightfield[x][y];
|
// float hR = heightfield[x][y];
|
||||||
float hD = heightfield[x][y+1];
|
// float hD = heightfield[x][y+1];
|
||||||
float hU;
|
// float hU;
|
||||||
if(y > 0){
|
// if(y > 0){
|
||||||
hU = heightfield[x][y-1];
|
// hU = heightfield[x][y-1];
|
||||||
} else {
|
// } else {
|
||||||
hU = heightfield[x][y];
|
// hU = heightfield[x][y];
|
||||||
}
|
// }
|
||||||
Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
// Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
||||||
Normal.normalize();
|
// Normal.normalize();
|
||||||
normals.put(Normal.x);
|
// normals.put(Normal.x);
|
||||||
normals.put(Normal.y);
|
// normals.put(Normal.y);
|
||||||
normals.put(Normal.z);
|
// normals.put(Normal.z);
|
||||||
} else {
|
// } else {
|
||||||
float hL = heightfield[x-1][y];
|
// float hL = heightfield[x-1][y];
|
||||||
float hR = heightfield[x][y];
|
// float hR = heightfield[x][y];
|
||||||
float hD = heightfield[x][y];
|
// float hD = heightfield[x][y];
|
||||||
float hU = heightfield[x][y-1];
|
// float hU = heightfield[x][y-1];
|
||||||
Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
// Vector3f Normal = new Vector3f(hL - hR, 2.0f, hD - hU);
|
||||||
Normal.normalize();
|
// Normal.normalize();
|
||||||
normals.put(Normal.x);
|
// normals.put(Normal.x);
|
||||||
normals.put(Normal.y);
|
// normals.put(Normal.y);
|
||||||
normals.put(Normal.z);
|
// normals.put(Normal.z);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
//deal with texture coordinates
|
// //deal with texture coordinates
|
||||||
if(x / stride % 2 == 0){
|
// if(x / stride % 2 == 0){
|
||||||
if(y / stride % 2 == 0){
|
// if(y / stride % 2 == 0){
|
||||||
texture_coords.put(0);
|
// texture_coords.put(0);
|
||||||
texture_coords.put(0);
|
// texture_coords.put(0);
|
||||||
} else {
|
// } else {
|
||||||
texture_coords.put(0);
|
// texture_coords.put(0);
|
||||||
texture_coords.put(1);
|
// texture_coords.put(1);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if(y / stride % 2 == 0){
|
// if(y / stride % 2 == 0){
|
||||||
texture_coords.put(1);
|
// texture_coords.put(1);
|
||||||
texture_coords.put(0);
|
// texture_coords.put(0);
|
||||||
} else {
|
// } else {
|
||||||
texture_coords.put(1);
|
// texture_coords.put(1);
|
||||||
texture_coords.put(1);
|
// texture_coords.put(1);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
//deal with faces
|
// //deal with faces
|
||||||
if(x / stride < actualWidth - 1 && y / stride < actualHeight - 1){
|
// if(x / stride < actualWidth - 1 && y / stride < actualHeight - 1){
|
||||||
faces.put((x / stride + 0) * actualHeight + (y / stride + 0));
|
// faces.put((x / stride + 0) * actualHeight + (y / stride + 0));
|
||||||
faces.put((x / stride + 0) * actualHeight + (y / stride + 1));
|
// faces.put((x / stride + 0) * actualHeight + (y / stride + 1));
|
||||||
faces.put((x / stride + 1) * actualHeight + (y / stride + 0));
|
// faces.put((x / stride + 1) * actualHeight + (y / stride + 0));
|
||||||
faces.put((x / stride + 1) * actualHeight + (y / stride + 0));
|
// faces.put((x / stride + 1) * actualHeight + (y / stride + 0));
|
||||||
faces.put((x / stride + 0) * actualHeight + (y / stride + 1));
|
// faces.put((x / stride + 0) * actualHeight + (y / stride + 1));
|
||||||
faces.put((x / stride + 1) * actualHeight + (y / stride + 1));
|
// faces.put((x / stride + 1) * actualHeight + (y / stride + 1));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
vertices.flip();
|
// vertices.flip();
|
||||||
normals.flip();
|
// normals.flip();
|
||||||
faces.flip();
|
// faces.flip();
|
||||||
texture_coords.flip();
|
// texture_coords.flip();
|
||||||
|
//
|
||||||
m.vertexArrayObject = glGenVertexArrays();
|
// m.vertexArrayObject = glGenVertexArrays();
|
||||||
glBindVertexArray(m.vertexArrayObject);
|
// glBindVertexArray(m.vertexArrayObject);
|
||||||
//buffer vertices
|
// //buffer vertices
|
||||||
m.buffer_vertices(vertices, 3);
|
// m.buffer_vertices(vertices, 3);
|
||||||
//buffer normals
|
// //buffer normals
|
||||||
m.buffer_normals(normals, 3);
|
// m.buffer_normals(normals, 3);
|
||||||
//buffer faces
|
// //buffer faces
|
||||||
m.buffer_faces(faces);
|
// m.buffer_faces(faces);
|
||||||
//buffer texture coords
|
// //buffer texture coords
|
||||||
m.buffer_texture_coords(texture_coords, 2);
|
// m.buffer_texture_coords(texture_coords, 2);
|
||||||
m.shader = ShaderProgram.smart_assemble_shader(false,true);
|
// m.shader = ShaderProgram.loadSpecificShader("/Shaders/terrain/terrain.vs", "/Shaders/terrain/terrain.fs");
|
||||||
glBindVertexArray(0);
|
// glBindVertexArray(0);
|
||||||
m.parent = rVal;
|
// m.parent = rVal;
|
||||||
|
//
|
||||||
Material groundMat = new Material();
|
// Material groundMat = new Material();
|
||||||
Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
|
// Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
|
||||||
groundMat.set_diffuse("/Textures/Ground/Dirt1.png");
|
// groundMat.set_diffuse("/Textures/Ground/Dirt1.png");
|
||||||
groundMat.set_specular("/Textures/Ground/Dirt1.png");
|
// groundMat.set_specular("/Textures/Ground/Dirt1.png");
|
||||||
m.set_material(groundMat);
|
// m.set_material(groundMat);
|
||||||
|
//
|
||||||
rVal.meshes.add(m);
|
// rVal.meshes.add(m);
|
||||||
return rVal;
|
// return rVal;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static Model createTerrainModelPrecomputedShader(float[][] heightfield, ShaderProgram program, int stride){
|
public static Model createTerrainModelPrecomputedShader(float[][] heightfield, ShaderProgram program, int stride){
|
||||||
Model rVal = new Model();
|
Model rVal = new Model();
|
||||||
@ -183,6 +183,7 @@ public class ModelUtils {
|
|||||||
FloatBuffer normals;
|
FloatBuffer normals;
|
||||||
IntBuffer faces;
|
IntBuffer faces;
|
||||||
FloatBuffer texture_coords;
|
FloatBuffer texture_coords;
|
||||||
|
IntBuffer textureIndices;
|
||||||
if(stride * actualWidth > width){
|
if(stride * actualWidth > width){
|
||||||
int drawWidth = actualWidth + 1;
|
int drawWidth = actualWidth + 1;
|
||||||
int drawHeight = actualHeight + 1;
|
int drawHeight = actualHeight + 1;
|
||||||
@ -190,11 +191,13 @@ public class ModelUtils {
|
|||||||
normals = BufferUtils.createFloatBuffer(drawWidth * drawHeight * 12);
|
normals = BufferUtils.createFloatBuffer(drawWidth * drawHeight * 12);
|
||||||
faces = BufferUtils.createIntBuffer((drawWidth - 1) * (drawHeight - 1) * 2 * 3);
|
faces = BufferUtils.createIntBuffer((drawWidth - 1) * (drawHeight - 1) * 2 * 3);
|
||||||
texture_coords = BufferUtils.createFloatBuffer(drawWidth * drawHeight * 8);
|
texture_coords = BufferUtils.createFloatBuffer(drawWidth * drawHeight * 8);
|
||||||
|
textureIndices = BufferUtils.createIntBuffer(drawWidth * drawHeight * 16);
|
||||||
} else {
|
} else {
|
||||||
vertices = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 12);
|
vertices = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 12);
|
||||||
normals = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 12);
|
normals = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 12);
|
||||||
faces = BufferUtils.createIntBuffer((actualWidth - 1) * (actualHeight - 1) * 2 * 3);
|
faces = BufferUtils.createIntBuffer((actualWidth - 1) * (actualHeight - 1) * 2 * 3);
|
||||||
texture_coords = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 8);
|
texture_coords = BufferUtils.createFloatBuffer(actualWidth * actualHeight * 8);
|
||||||
|
textureIndices = BufferUtils.createIntBuffer(actualWidth * actualHeight * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
int incrementer = 0;
|
int incrementer = 0;
|
||||||
@ -268,6 +271,13 @@ public class ModelUtils {
|
|||||||
texture_coords.put(1);
|
texture_coords.put(1);
|
||||||
texture_coords.put(1);
|
texture_coords.put(1);
|
||||||
|
|
||||||
|
for(int i = 0; i < 4 ; i++){
|
||||||
|
textureIndices.put(0);
|
||||||
|
textureIndices.put(1);
|
||||||
|
textureIndices.put(2);
|
||||||
|
textureIndices.put(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//deal with faces
|
//deal with faces
|
||||||
if(1.0f * x / stride < actualWidth - 1 && 1.0f * y / stride < actualHeight - 1){
|
if(1.0f * x / stride < actualWidth - 1 && 1.0f * y / stride < actualHeight - 1){
|
||||||
@ -297,6 +307,8 @@ public class ModelUtils {
|
|||||||
m.buffer_faces(faces);
|
m.buffer_faces(faces);
|
||||||
//buffer texture coords
|
//buffer texture coords
|
||||||
m.buffer_texture_coords(texture_coords, 2);
|
m.buffer_texture_coords(texture_coords, 2);
|
||||||
|
//texture indices
|
||||||
|
m.bufferCustomIntAttribArray(textureIndices, 4, 5);
|
||||||
m.shader = program;
|
m.shader = program;
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
m.parent = rVal;
|
m.parent = rVal;
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import electrosphere.renderer.framebuffer.FramebufferUtils;
|
|||||||
import electrosphere.renderer.framebuffer.Renderbuffer;
|
import electrosphere.renderer.framebuffer.Renderbuffer;
|
||||||
import electrosphere.renderer.texture.Texture;
|
import electrosphere.renderer.texture.Texture;
|
||||||
import electrosphere.renderer.ui.Widget;
|
import electrosphere.renderer.ui.Widget;
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
@ -39,10 +40,19 @@ import static org.lwjgl.glfw.GLFW.glfwTerminate;
|
|||||||
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
|
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
|
||||||
import org.lwjgl.glfw.GLFWWindowSizeCallbackI;
|
import org.lwjgl.glfw.GLFWWindowSizeCallbackI;
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
import static org.lwjgl.opengl.GL11.GL_BLEND;
|
import static org.lwjgl.opengl.GL11.GL_BLEND;
|
||||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
|
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_EXP2;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_FOG;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_FOG_COLOR;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_FOG_DENSITY;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_FOG_END;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_FOG_MODE;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_FOG_START;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_LINEAR;
|
||||||
import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
||||||
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||||
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
||||||
@ -55,6 +65,7 @@ import static org.lwjgl.opengl.GL11.glClearColor;
|
|||||||
import static org.lwjgl.opengl.GL11.glDisable;
|
import static org.lwjgl.opengl.GL11.glDisable;
|
||||||
import static org.lwjgl.opengl.GL11.glDrawArrays;
|
import static org.lwjgl.opengl.GL11.glDrawArrays;
|
||||||
import static org.lwjgl.opengl.GL11.glEnable;
|
import static org.lwjgl.opengl.GL11.glEnable;
|
||||||
|
import static org.lwjgl.opengl.GL11.glFogf;
|
||||||
import static org.lwjgl.opengl.GL11.glViewport;
|
import static org.lwjgl.opengl.GL11.glViewport;
|
||||||
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
|
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
|
||||||
import static org.lwjgl.opengl.GL13.GL_TEXTURE1;
|
import static org.lwjgl.opengl.GL13.GL_TEXTURE1;
|
||||||
@ -98,8 +109,8 @@ public class RenderingEngine {
|
|||||||
//Initializes opengl
|
//Initializes opengl
|
||||||
glfwInit();
|
glfwInit();
|
||||||
//Gives hints to glfw to control how opengl will be used
|
//Gives hints to glfw to control how opengl will be used
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
// glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); Allows you to make the background transparent
|
// glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); Allows you to make the background transparent
|
||||||
// glfwWindowHint(GLFW_OPACITY, 23);
|
// glfwWindowHint(GLFW_OPACITY, 23);
|
||||||
@ -160,6 +171,27 @@ public class RenderingEngine {
|
|||||||
Globals.shadowMapTextureLoc = lightDepthBuffer.getTexture();
|
Globals.shadowMapTextureLoc = lightDepthBuffer.getTexture();
|
||||||
// glEnable(GL_CULL_FACE); // enabled for shadow mapping
|
// glEnable(GL_CULL_FACE); // enabled for shadow mapping
|
||||||
|
|
||||||
|
//
|
||||||
|
//Fog
|
||||||
|
//
|
||||||
|
//enable fog
|
||||||
|
// glEnable(GL_FOG);
|
||||||
|
// //set the equation to use for fog
|
||||||
|
// glFogf(GL_FOG_MODE,GL_LINEAR);
|
||||||
|
//// glFogf(GL_FOG_MODE,GL_EXP2);
|
||||||
|
// //set the density of the fog
|
||||||
|
// glFogf(GL_FOG_DENSITY,1.0f);
|
||||||
|
// //these are applicable for the linear equation
|
||||||
|
// glFogf(GL_FOG_START,0.8f);
|
||||||
|
// glFogf(GL_FOG_END,1.0f);
|
||||||
|
// //fog color
|
||||||
|
// FloatBuffer fogColor = FloatBuffer.allocate(4);
|
||||||
|
// fogColor.put(1.0f);
|
||||||
|
// fogColor.put(1.0f);
|
||||||
|
// fogColor.put(1.0f);
|
||||||
|
// fogColor.put(1.0f);
|
||||||
|
// fogColor.flip();
|
||||||
|
// GL11.glFogfv(GL_FOG_COLOR, fogColor);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Projection and View matrix creation
|
// Projection and View matrix creation
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user