Skip to content

Instantly share code, notes, and snippets.

@cbaggers
Last active January 27, 2016 09:46
Show Gist options
  • Save cbaggers/17b7f3cf3b9e956b9d51 to your computer and use it in GitHub Desktop.
Save cbaggers/17b7f3cf3b9e956b9d51 to your computer and use it in GitHub Desktop.
Spaces doing crappy lighting
;;----------------------------------------------------------------------
;; Shader pipeline
(defun-g first-vert ((vert vertex) &uniform (model-space space-g))
(in *clip-space*
(values (in model-space (p! (pos vert) 1.0))
(normal vert)
(uv vert))))
(defun-g first-frag ((norm :vec3) (uv :vec2) &uniform (tex :sampler-2d) (camera-space space-g) (model-space space-g))
(let ((cos-angle-of-incidence
(clamp (in camera-space
(dot (v:normalize (in model-space (p! norm 0)))
(in *world-space* (p! *dir-to-sun*))))
0 1)))
(* *sun-intensity* (varjo-lang:texture tex uv) cos-angle-of-incidence)))
(defpipeline first-render ()
(g-> #'first-vert #'first-frag))
;;----------------------------------------------------------------------
#version 330
struct VERTEX {
vec3 POS;
vec3 NORMAL;
vec2 UV;
};
layout(location = 0) in vec3 fk_vert_position;
layout(location = 1) in vec3 fk_vert_normal;
layout(location = 2) in vec2 fk_vert_tex_coords;
out vec3 OUT_1345V;
out vec2 OUT_1346V;
uniform mat4 MODEL_SPACE_TO_42CLIP_SPACE42_TRANSFORM;
void main() {
vec3 return1;
vec2 return2;
vec4 V_TMP_1341V_1342V = (MODEL_SPACE_TO_42CLIP_SPACE42_TRANSFORM * vec4(fk_vert_position,1.0f));
return1 = fk_vert_normal;
return2 = fk_vert_tex_coords;
gl_Position = V_TMP_1341V_1342V;
OUT_1345V = return1;
OUT_1346V = return2;
}
#version 330
in vec3 OUT_1345V;
in vec2 OUT_1346V;
layout(location = 0) out vec4 OUTPUT_COLOR_1367V;
uniform sampler2D TEX;
uniform mat4 _42WORLD_SPACE42_TO_CAMERA_SPACE_TRANSFORM;
uniform mat4 MODEL_SPACE_TO_CAMERA_SPACE_TRANSFORM;
uniform vec4 _42SUN_INTENSITY42;
uniform vec4 _42DIR_TO_SUN42;
void main() {
float COS_ANGLE_OF_INCIDENCE_1366V = clamp(dot(normalize((MODEL_SPACE_TO_CAMERA_SPACE_TRANSFORM * vec4(OUT_1345V,0))),(_42WORLD_SPACE42_TO_CAMERA_SPACE_TRANSFORM * _42DIR_TO_SUN42)),0,1);
OUTPUT_COLOR_1367V = (_42SUN_INTENSITY42 * (texture(TEX, OUT_1346V) * COS_ANGLE_OF_INCIDENCE_1366V));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment