From: Mikko Rasa Date: Wed, 11 Apr 2018 21:06:15 +0000 (+0300) Subject: Split the interfaces from singlepass.glsl to a separate module X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=f0293969980969f5b19a2a3c665ea068617dab49 Split the interfaces from singlepass.glsl to a separate module Sometimes it's desirable to make a fully custom shader but still use the common interface. It's also likely that I'll add other types of standard shader templates in the future. --- diff --git a/shaderlib/msp_interface.glsl b/shaderlib/msp_interface.glsl new file mode 100644 index 00000000..e606edf9 --- /dev/null +++ b/shaderlib/msp_interface.glsl @@ -0,0 +1,77 @@ +struct LightSourceParameters +{ + vec4 position; + vec4 diffuse; + vec4 specular; +}; + +struct MaterialParameters +{ + vec4 ambient; + vec4 diffuse; + vec4 specular; + float shininess; +}; + +struct ClipPlane +{ + vec4 equation; +}; + +uniform mat4 eye_obj_matrix; +uniform mat3 eye_obj_normal_matrix; +uniform Transform +{ + mat4 projection_matrix; +}; + +uniform Material +{ + MaterialParameters material; + float reflectivity; +}; + +uniform Lighting +{ + // Declared as an array for compatibility reasons + LightSourceParameters light_sources[1]; + vec4 ambient_color; + vec4 sky_color; + vec3 eye_zenith_dir; + float horizon_limit; + vec4 fog_color; + float fog_density; +}; + +uniform sampler2D diffuse_map; +uniform sampler2D normal_map; + +uniform sampler2DShadow shadow; +uniform ShadowMap +{ + float shadow_darkness; + mat4 shd_eye_matrix; +}; + +uniform samplerCube environment; +uniform EnvMap +{ + mat3 env_eye_matrix; +}; + +const int max_clip_planes = 0; +uniform Clipping +{ + ClipPlane clip_planes[max_clip_planes]; +}; + +#pragma MSP stage(vertex) +layout(location=0) in vec4 vertex; +layout(location=8) in vec4 texcoord; +layout(location=3) in vec4 color; +layout(location=2) in vec3 normal; +layout(location=4) in vec3 tangent; +layout(location=5) in vec3 binormal; + +#pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; diff --git a/shaderlib/singlepass.glsl b/shaderlib/singlepass.glsl index 50c3841f..f782f3da 100644 --- a/shaderlib/singlepass.glsl +++ b/shaderlib/singlepass.glsl @@ -1,35 +1,4 @@ -struct LightSourceParameters -{ - vec4 position; - vec4 diffuse; - vec4 specular; -}; - -struct MaterialParameters -{ - vec4 ambient; - vec4 diffuse; - vec4 specular; - float shininess; -}; - -struct ClipPlane -{ - vec4 equation; -}; - -uniform mat4 eye_obj_matrix; -uniform mat3 eye_obj_normal_matrix; -uniform Transform -{ - mat4 projection_matrix; -}; - -uniform Material -{ - MaterialParameters material; - float reflectivity; -}; +import msp_interface; const bool use_vertex_color = false; @@ -37,53 +6,15 @@ const bool use_lighting = false; const bool use_specular = false; const bool use_sky = false; const bool use_fog = false; -uniform Lighting -{ - // Declared as an array for compatibility reasons - LightSourceParameters light_sources[1]; - vec4 ambient_color; - vec4 sky_color; - vec3 eye_zenith_dir; - float horizon_limit; - vec4 fog_color; - float fog_density; -}; const bool use_diffuse_map = false; -uniform sampler2D diffuse_map; - const bool use_normal_map = false; -uniform sampler2D normal_map; const bool use_shadow_map = false; -uniform sampler2DShadow shadow; -uniform ShadowMap -{ - float shadow_darkness; - mat4 shd_eye_matrix; -}; const bool use_environment_map = false; -uniform samplerCube environment; -uniform EnvMap -{ - mat3 env_eye_matrix; -}; - -const int max_clip_planes = 0; -uniform Clipping -{ - ClipPlane clip_planes[max_clip_planes]; -}; #pragma MSP stage(vertex) -layout(location=0) in vec4 vertex; -layout(location=8) in vec4 texcoord; -layout(location=3) in vec4 color; -layout(location=2) in vec3 normal; -layout(location=4) in vec3 tangent; -layout(location=5) in vec3 binormal; - vec4 get_vertex_position() { return vertex; @@ -128,8 +59,6 @@ void main() } #pragma MSP stage(fragment) -layout(location=0) out vec4 frag_color; - vec4 get_diffuse_sample() { return texture(diffuse_map, texcoord.xy);