~shockham/meshi

9df3a66883445a6255ca99463c02380550fe419f — shockham 3 years ago cfa965c
Add override for the texture fragment shader
2 files changed, 34 insertions(+), 2 deletions(-)

A src/shaders/frag.glsl
M src/shaders/mod.rs
A src/shaders/frag.glsl => src/shaders/frag.glsl +30 -0
@@ 0,0 1,30 @@
#version 330

uniform float time;
uniform vec3 cam_pos;
uniform sampler2D tex;
uniform sampler2D normal_tex;
uniform sampler1D dir_lights;

in vec3 g_normal;
in vec3 g_pos;
in vec2 g_texture;

out vec4 frag_output;

void main() {
    int size = textureSize(dir_lights, 0);
    float lum = 0.0;
    float tex_lum = 0.0;
    for (int i = 0; i < size; i++) {
        vec3 light_norm = normalize(texture(dir_lights, i).xyz);
        lum += max(dot(normalize(g_normal), light_norm), 0.0);
        tex_lum += dot(normalize(vec3(texture(normal_tex, g_texture))), light_norm);
    }

    float avg_lum = (lum + tex_lum) / 2.0;

    float dist = abs(distance(cam_pos, g_pos)) / 80.0;

    frag_output = texture(tex, g_texture) * vec4(vec3((0.6 * avg_lum) + (0.4 * dist)), 1.0);
}

M src/shaders/mod.rs => src/shaders/mod.rs +4 -2
@@ 1,5 1,5 @@
use caper::game::Game;
use caper::shader::{default, texture};
use caper::shader::default;
use caper::types::DefaultTag;

pub fn add_custom_shaders(game: &mut Game<DefaultTag>) {


@@ 10,7 10,7 @@ pub fn add_custom_shaders(game: &mut Game<DefaultTag>) {
        display,
        "points",
        default::gl330::VERT,
        texture::gl330::FRAG,
        points::FRAG,
        points::GEOM,
        points::TESS_CONTROL,
        points::TESS_EVAL,


@@ 24,4 24,6 @@ mod points {
    pub const TESS_EVAL: &'static str = include_str!("./tess_eval.glsl");
    /// geometry shader
    pub const GEOM: &'static str = include_str!("./geom.glsl");
    /// fragment shader
    pub const FRAG: &'static str = include_str!("./frag.glsl");
}