X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fmodel_gate.h;h=49986ba43a2a08c3fe574a193cd6c61d6460e02b;hb=5f6a4f9df6c8accc89f1920bfe9ace3cbac4c4b6;hp=1bc558fd5e0be8bba07fe2603a89a7b4f63a6658;hpb=a109f126d8adab622e38fbcc2d4281e75255246a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/model_gate.h b/shaders/model_gate.h index 1bc558f..49986ba 100644 --- a/shaders/model_gate.h +++ b/shaders/model_gate.h @@ -1,137 +1,43 @@ -#ifndef SHADER_model_gate_H -#define SHADER_model_gate_H -static void shader_model_gate_link(void); -static void shader_model_gate_register(void); -static struct vg_shader _shader_model_gate = { - .name = "model_gate", - .link = shader_model_gate_link, - .vs = +#pragma once +#include "vg/vg_engine.h" +extern struct vg_shader _shader_model_gate; +extern GLuint _uniform_model_gate_uMdl; +extern GLuint _uniform_model_gate_uPv; +extern GLuint _uniform_model_gate_uPvmPrev; +extern GLuint _uniform_model_gate_uTime; +extern GLuint _uniform_model_gate_uCam; +extern GLuint _uniform_model_gate_uInvRes; +extern GLuint _uniform_model_gate_uColour; +static inline void shader_model_gate_uMdl(m4x3f m) { -.orig_file = "shaders/model.vs", -.static_src = -"layout (location=0) in vec3 a_co;\n" -"layout (location=1) in vec3 a_norm;\n" -"layout (location=2) in vec2 a_uv;\n" -"layout (location=3) in vec4 a_colour;\n" -"layout (location=4) in vec4 a_weights;\n" -"layout (location=5) in ivec4 a_groups;\n" -"\n" -"#line 1 1 \n" -"const float k_motion_lerp_amount = 0.01;\n" -"\n" -"#line 2 0 \n" -"\n" -"out vec3 aMotionVec0;\n" -"out vec3 aMotionVec1;\n" -"\n" -"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n" -"{\n" -" // This magically solves some artifacting errors!\n" -" //\n" -" vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n" -"\n" -" aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n" -" aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n" -"}\n" -"\n" -"#line 9 0 \n" -"\n" -"uniform mat4x3 uMdl;\n" -"uniform mat4 uPv;\n" -"uniform mat4 uPvmPrev;\n" -"\n" -"out vec4 aColour;\n" -"out vec2 aUv;\n" -"out vec3 aNorm;\n" -"out vec3 aCo;\n" -"out vec3 aWorldCo;\n" -"\n" -"void main()\n" -"{\n" -" vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n" -" vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n" -" vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n" -"\n" -" vs_motion_out( vproj0, vproj1 );\n" -"\n" -" gl_Position = vproj0;\n" -" aWorldCo = world_pos0;\n" -" aColour = a_colour;\n" -" aUv = a_uv;\n" -" aNorm = normalize( mat3(uMdl) * a_norm );\n" -" aCo = a_co;\n" -"}\n" -""}, - .fs = -{ -.orig_file = "shaders/model_gate_lq.fs", -.static_src = -"out vec4 FragColor;\n" -"\n" -"uniform float uTime;\n" -"uniform vec3 uCam;\n" -"uniform vec2 uInvRes;\n" -"uniform vec4 uColour;\n" -"\n" -"in vec3 aNorm;\n" -"in vec2 aUv;\n" -"in vec3 aCo;\n" -"\n" -"void main()\n" -"{\n" -" vec2 ssuv = gl_FragCoord.xy;\n" -" float opacity = 1.0-smoothstep(0.0,1.0,aUv.y+uColour.a);\n" -" \n" -" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n" -" float dither = fract( vDither.g / 71.0 ) - 0.5;\n" -"\n" -" if( opacity+dither<0.5 )\n" -" discard;\n" -"\n" -" FragColor = uColour;\n" -"}\n" -""}, -}; - -static GLuint _uniform_model_gate_uMdl; -static GLuint _uniform_model_gate_uPv; -static GLuint _uniform_model_gate_uPvmPrev; -static GLuint _uniform_model_gate_uTime; -static GLuint _uniform_model_gate_uCam; -static GLuint _uniform_model_gate_uInvRes; -static GLuint _uniform_model_gate_uColour; -static void shader_model_gate_uMdl(m4x3f m){ - glUniformMatrix4x3fv(_uniform_model_gate_uMdl,1,GL_FALSE,(float*)m); + glUniformMatrix4x3fv(_uniform_model_gate_uMdl,1,GL_FALSE,(f32*)m); } -static void shader_model_gate_uPv(m4x4f m){ - glUniformMatrix4fv(_uniform_model_gate_uPv,1,GL_FALSE,(float*)m); +static inline void shader_model_gate_uPv(m4x4f m) +{ + glUniformMatrix4fv(_uniform_model_gate_uPv,1,GL_FALSE,(f32*)m); } -static void shader_model_gate_uPvmPrev(m4x4f m){ - glUniformMatrix4fv(_uniform_model_gate_uPvmPrev,1,GL_FALSE,(float*)m); +static inline void shader_model_gate_uPvmPrev(m4x4f m) +{ + glUniformMatrix4fv(_uniform_model_gate_uPvmPrev,1,GL_FALSE,(f32*)m); } -static void shader_model_gate_uTime(float f){ +static inline void shader_model_gate_uTime(f32 f) +{ glUniform1f(_uniform_model_gate_uTime,f); } -static void shader_model_gate_uCam(v3f v){ +static inline void shader_model_gate_uCam(v3f v) +{ glUniform3fv(_uniform_model_gate_uCam,1,v); } -static void shader_model_gate_uInvRes(v2f v){ +static inline void shader_model_gate_uInvRes(v2f v) +{ glUniform2fv(_uniform_model_gate_uInvRes,1,v); } -static void shader_model_gate_uColour(v4f v){ +static inline void shader_model_gate_uColour(v4f v) +{ glUniform4fv(_uniform_model_gate_uColour,1,v); } -static void shader_model_gate_register(void){ - vg_shader_register( &_shader_model_gate ); -} -static void shader_model_gate_use(void){ glUseProgram(_shader_model_gate.id); } -static void shader_model_gate_link(void){ - _uniform_model_gate_uMdl = glGetUniformLocation( _shader_model_gate.id, "uMdl" ); - _uniform_model_gate_uPv = glGetUniformLocation( _shader_model_gate.id, "uPv" ); - _uniform_model_gate_uPvmPrev = glGetUniformLocation( _shader_model_gate.id, "uPvmPrev" ); - _uniform_model_gate_uTime = glGetUniformLocation( _shader_model_gate.id, "uTime" ); - _uniform_model_gate_uCam = glGetUniformLocation( _shader_model_gate.id, "uCam" ); - _uniform_model_gate_uInvRes = glGetUniformLocation( _shader_model_gate.id, "uInvRes" ); - _uniform_model_gate_uColour = glGetUniformLocation( _shader_model_gate.id, "uColour" ); +static inline void shader_model_gate_use(void); +static inline void shader_model_gate_use(void) +{ + glUseProgram(_shader_model_gate.id); } -#endif /* SHADER_model_gate_H */