add entity shader
This commit is contained in:
parent
8e159009eb
commit
4197746c69
24
res/shaders/entity.glslf
Normal file
24
res/shaders/entity.glslf
Normal file
@ -0,0 +1,24 @@
|
||||
in vec4 a_color;
|
||||
in vec2 a_texCoord;
|
||||
in float a_distance;
|
||||
in vec3 a_dir;
|
||||
out vec4 f_color;
|
||||
|
||||
uniform sampler2D u_texture0;
|
||||
uniform samplerCube u_cubemap;
|
||||
uniform vec3 u_fogColor;
|
||||
uniform float u_fogFactor;
|
||||
uniform float u_fogCurve;
|
||||
|
||||
void main() {
|
||||
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
|
||||
vec4 tex_color = texture(u_texture0, a_texCoord);
|
||||
float depth = (a_distance/256.0);
|
||||
float alpha = a_color.a * tex_color.a;
|
||||
// anyway it's any alpha-test alternative required
|
||||
if (alpha < 0.3f)
|
||||
discard;
|
||||
f_color = mix(a_color * tex_color, vec4(fogColor,1.0),
|
||||
min(1.0, pow(depth*u_fogFactor, u_fogCurve)));
|
||||
f_color.a = alpha;
|
||||
}
|
||||
42
res/shaders/entity.glslv
Normal file
42
res/shaders/entity.glslv
Normal file
@ -0,0 +1,42 @@
|
||||
#include <commons>
|
||||
|
||||
layout (location = 0) in vec3 v_position;
|
||||
layout (location = 1) in vec2 v_texCoord;
|
||||
layout (location = 2) in vec3 v_color;
|
||||
layout (location = 3) in vec3 v_normal;
|
||||
layout (location = 4) in float v_light;
|
||||
|
||||
out vec4 a_color;
|
||||
out vec2 a_texCoord;
|
||||
out float a_distance;
|
||||
out vec3 a_dir;
|
||||
|
||||
uniform mat4 u_model;
|
||||
uniform mat4 u_proj;
|
||||
uniform mat4 u_view;
|
||||
uniform vec3 u_cameraPos;
|
||||
uniform float u_gamma;
|
||||
uniform samplerCube u_cubemap;
|
||||
|
||||
uniform vec3 u_torchlightColor;
|
||||
uniform float u_torchlightDistance;
|
||||
|
||||
void main() {
|
||||
vec4 modelpos = u_model * vec4(v_position, 1.0);
|
||||
vec3 pos3d = modelpos.xyz - u_cameraPos;
|
||||
modelpos.xyz = apply_planet_curvature(modelpos.xyz, pos3d);
|
||||
|
||||
vec4 decomp_light = decompress_light(v_light);
|
||||
vec3 light = decomp_light.rgb;
|
||||
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /
|
||||
u_torchlightDistance);
|
||||
light += torchlight * u_torchlightColor;
|
||||
a_color = vec4(pow(light, vec3(u_gamma)) * v_normal,1.0f);
|
||||
a_texCoord = v_texCoord;
|
||||
|
||||
a_dir = modelpos.xyz - u_cameraPos;
|
||||
vec3 skyLightColor = pick_sky_color(u_cubemap);
|
||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a);
|
||||
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
|
||||
gl_Position = u_proj * u_view * modelpos;
|
||||
}
|
||||
@ -3,9 +3,6 @@
|
||||
|
||||
#include <constants>
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define PI2 (PI*2)
|
||||
|
||||
vec4 decompress_light(float compressed_light) {
|
||||
vec4 result;
|
||||
int compressed = floatBitsToInt(compressed_light);
|
||||
@ -24,4 +21,9 @@ vec3 pick_sky_color(samplerCube cubemap) {
|
||||
return skyLightColor;
|
||||
}
|
||||
|
||||
vec3 apply_planet_curvature(vec3 modelPos, vec3 pos3d) {
|
||||
modelPos.y -= pow(length(pos3d.xz)*CURVATURE_FACTOR, 3.0);
|
||||
return modelPos;
|
||||
}
|
||||
|
||||
#endif // COMMONS_GLSL_
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
#ifndef CONSTANTS_GLSL_
|
||||
#define CONSTANTS_GLSL_
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define PI2 (PI*2)
|
||||
|
||||
// geometry
|
||||
#define CURVATURE_FACTOR 0.002
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ uniform vec3 u_fogColor;
|
||||
uniform float u_fogFactor;
|
||||
uniform float u_fogCurve;
|
||||
|
||||
void main(){
|
||||
void main() {
|
||||
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
|
||||
vec4 tex_color = texture(u_texture0, a_texCoord);
|
||||
float depth = (a_distance/256.0);
|
||||
|
||||
@ -12,7 +12,6 @@ out vec3 a_dir;
|
||||
uniform mat4 u_model;
|
||||
uniform mat4 u_proj;
|
||||
uniform mat4 u_view;
|
||||
uniform vec3 u_skyLightColor;
|
||||
uniform vec3 u_cameraPos;
|
||||
uniform float u_gamma;
|
||||
uniform samplerCube u_cubemap;
|
||||
@ -20,15 +19,15 @@ uniform samplerCube u_cubemap;
|
||||
uniform vec3 u_torchlightColor;
|
||||
uniform float u_torchlightDistance;
|
||||
|
||||
void main(){
|
||||
void main() {
|
||||
vec4 modelpos = u_model * vec4(v_position, 1.0);
|
||||
vec3 pos3d = modelpos.xyz-u_cameraPos.xyz;
|
||||
modelpos.y -= pow(length(pos3d.xz)*CURVATURE_FACTOR, 3.0);
|
||||
vec4 viewmodelpos = u_view * modelpos;
|
||||
vec3 pos3d = modelpos.xyz-u_cameraPos;
|
||||
modelpos.xyz = apply_planet_curvature(modelpos.xyz, pos3d);
|
||||
|
||||
vec4 decomp_light = decompress_light(v_light);
|
||||
|
||||
vec3 light = decomp_light.rgb;
|
||||
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance);
|
||||
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /
|
||||
u_torchlightDistance);
|
||||
light += torchlight * u_torchlightColor;
|
||||
a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
|
||||
a_texCoord = v_texCoord;
|
||||
@ -37,5 +36,5 @@ void main(){
|
||||
vec3 skyLightColor = pick_sky_color(u_cubemap);
|
||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a);
|
||||
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
|
||||
gl_Position = u_proj * viewmodelpos;
|
||||
gl_Position = u_proj * u_view * modelpos;
|
||||
}
|
||||
|
||||
@ -180,6 +180,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
||||
loader.add(AssetType::FONT, FONTS_FOLDER+"/font", "normal");
|
||||
loader.add(AssetType::SHADER, SHADERS_FOLDER+"/ui", "ui");
|
||||
loader.add(AssetType::SHADER, SHADERS_FOLDER+"/main", "main");
|
||||
loader.add(AssetType::SHADER, SHADERS_FOLDER+"/entity", "entity");
|
||||
loader.add(AssetType::SHADER, SHADERS_FOLDER+"/lines", "lines");
|
||||
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/menubg", "gui/menubg");
|
||||
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/delete_icon", "gui/delete_icon");
|
||||
|
||||
@ -141,9 +141,5 @@ std::string GLSLExtension::process(const fs::path& file, const std::string& sour
|
||||
ss << source.substr(pos, endline+1-pos);
|
||||
pos = endline+1;
|
||||
}
|
||||
if (!header) {
|
||||
std::cout << " ========================================================== " << file.u8string() << std::endl;
|
||||
std::cout << ss.str() << std::endl;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user