9 uniform sampler2D normal_map;
10 uniform samplerCube environment_map;
11 uniform samplerCube irradiance_map;
13 layout(constant_id=auto) const bool use_normal_map = false;
15 #pragma MSP stage(vertex)
16 virtual vec4 get_vertex_position()
21 virtual vec3 get_vertex_normal()
26 virtual mat4 get_vertex_transform()
28 return world_obj_matrix;
31 virtual mat3 get_normal_transform()
33 return world_obj_normal_matrix;
36 void standard_transform()
38 mat4 vertex_tf = get_vertex_transform();
39 mat3 normal_tf = get_normal_transform();
41 out vec4 world_vertex = vertex_tf*get_vertex_position();
42 vec4 eye_vertex = eye_world_matrix*world_vertex;
43 gl_Position = clip_eye_matrix*eye_vertex;
45 out vec3 world_normal = normal_tf*get_vertex_normal();
46 vec3 world_tangent = normal_tf*tangent;
47 vec3 world_binormal = cross(world_normal, world_tangent);
48 out mat3 world_tbn_matrix = mat3(world_tangent, world_binormal, world_normal);
50 vec3 eye_pos = (inverse(eye_world_matrix)*vec4(0.0, 0.0, 0.0, 1.0)).xyz;
51 out vec3 world_look_dir = normalize(world_vertex.xyz-eye_pos);
53 out float fog_coord = eye_vertex.z;
56 virtual void custom_transform()
67 #pragma MSP stage(fragment)
74 layout(location=0) out vec4 frag_color;
76 virtual vec3 get_fragment_normal()
79 return normalize(world_tbn_matrix*(texture(normal_map, texcoord.xy).xyz*2.0-1.0));
81 return normalize(world_normal);
84 virtual IncomingLight get_incoming_light(int index, vec3 world_pos)
86 vec4 light_pos = light_sources[index].position;
87 vec3 rel_pos = light_pos.xyz-world_pos*light_pos.w;
88 float d = length(rel_pos);
89 float attenuation = 1.0/dot(vec3(1.0, d, d*d), light_sources[index].attenuation);
90 return IncomingLight(rel_pos/d, light_sources[index].color*attenuation);
93 virtual vec3 get_environment_sample(vec3 direction, float roughness)
95 float lod = (2-roughness)*roughness*(textureQueryLevels(environment_map)-1);
96 return textureLod(environment_map, env_world_matrix*direction, lod).rgb;
99 virtual vec3 get_reflection(vec3 normal, vec3 look)
101 vec3 reflect_dir = reflect(look, normal);
102 return get_environment_sample(reflect_dir, 0.0);
105 virtual vec3 get_irradiance_sample(vec3 normal)
107 return texture(irradiance_map, env_world_matrix*normal).rgb;
110 vec3 apply_fog(vec3 color)
112 float fog_value = exp(fog_coord*fog_density);
113 return mix(fog_color.rgb, color, fog_value);