# 9 GLSL.std.450mainA amethyst_rendy/shaders/fragment/shaded.fragamethyst_rendy/shaders/fragment/header/environment.fragamethyst_rendy/shaders/fragment/header/math.frag// OpModuleProcessed entry-point main // OpModuleProcessed client vulkan100 // OpModuleProcessed target-env vulkan1.0 // OpModuleProcessed entry-point main #line 1 #version 450 #include "header/math.frag" #include "header/environment.frag" layout(set = 1, binding = 0) uniform Material { UvOffset uv_offset; float alpha_cutoff; }; layout(set = 1, binding = 1) uniform sampler2D albedo; layout(set = 1, binding = 2) uniform sampler2D emission; layout(location = 0) in VertexData { vec3 position; vec3 normal; vec2 tex_coord; vec4 color; } vertex; layout(location = 0) out vec4 out_color; void main() { vec2 final_tex_coords = tex_coords(vertex.tex_coord, uv_offset); vec4 albedo_alpha = texture(albedo, final_tex_coords); float alpha = albedo_alpha.a; if(alpha < alpha_cutoff) discard; vec3 albedo = albedo_alpha.rgb; vec3 emission = texture(emission, final_tex_coords).rgb; vec3 lighting = vec3(0.0); vec3 normal = normalize(vertex.normal); for (uint i = 0u; i < point_light_count; i++) { // Calculate diffuse light vec3 light_dir = normalize(plight[i].position - vertex.position); float diff = max(dot(light_dir, normal), 0.0); vec3 diffuse = diff * normalize(plight[i].color); // Calculate attenuation vec3 dist = plight[i].position - vertex.position; float dist2 = dot(dist, dist); float attenuation = (plight[i].intensity / dist2); lighting += diffuse * attenuation; } for (uint i = 0u; i < directional_light_count; i++) { vec3 dir = dlight[i].direction; float diff = max(dot(-dir, normal), 0.0); vec3 diffuse = diff * dlight[i].color; lighting += diffuse * dlight[i].intensity; } lighting += ambient_color; out_color = vec4(lighting * albedo + emission, alpha) * vertex.color; } // Environment shader definition. // Set 0. // Keep in sync with amethyst_rendy/src/submodules/environment.rs struct PointLight { vec3 position; vec3 color; float intensity; }; struct DirectionalLight { vec3 color; float intensity; vec3 direction; }; struct SpotLight { vec3 position; vec3 color; vec3 direction; float angle; float intensity; float range; float smoothness; }; layout(std140, set = 0, binding = 1) uniform Environment { vec3 ambient_color; vec3 camera_position; int point_light_count; int directional_light_count; int spot_light_count; }; layout(std140, set = 0, binding = 2) uniform PointLights { PointLight plight[128]; }; layout(std140, set = 0, binding = 3) uniform DirectionalLights { DirectionalLight dlight[16]; }; layout(std140, set = 0, binding = 4) uniform SpotLights { SpotLight slight[128]; };##ifndef MATH_FRAG #define MATH_FRAG const float PI = 3.14159265359; struct UvOffset { vec2 u_offset; vec2 v_offset; }; float tex_coord(float coord, vec2 offset) { return offset.x + coord * (offset.y - offset.x); } vec2 tex_coords(vec2 coord, UvOffset offset) { return vec2(tex_coord(coord.x, offset.u_offset), tex_coord(coord.y, offset.v_offset)); } vec3 schlick_fresnel(float HdotV, vec3 fresnel_base) { return fresnel_base + (1.0 - fresnel_base) * pow(1.0 - HdotV, 5.0); } float ggx_normal_distribution(vec3 N, vec3 H, float a) { float a2 = a * a; float NdotH = max(dot(N, H), 0.0); float NdotH2 = NdotH*NdotH; float denom = (NdotH2 * (a2 - 1.0) + 1.0); denom = PI * denom * denom; return (a2 + 0.0000001) / denom; } float ggx_geometry(float NdotV, float NdotL, float r2) { float a1 = r2 + 1.0; float k = a1 * a1 / 8.0; float denom = NdotV * (1.0 - k) + k; float ggx1 = NdotV / denom; denom = NdotL * (1.0 - k) + k; float ggx2 = NdotL / denom; return ggx1 * ggx2; } float s_curve (float x) { x = x * 2.0 - 1.0; return -x * abs(x) * 0.5 + x + 0.5; } #endif  GL_GOOGLE_cpp_style_line_directiveGL_GOOGLE_include_directivemain?VertexData?position?normal?tex_coord?colorAvertexCUvOffsetCu_offsetCv_offsetDMaterialDuv_offsetDalpha_cutoffFYalbedooemissionEnvironmentambient_colorcamera_positionpoint_light_count directional_light_countspot_light_countPointLightpositioncolorintensityPointLightsplightDirectionalLightcolorintensitydirectionDirectionalLightsdlightout_colorG?GAHC#HC#HD#HD#GDGF"GF!GY"GY!Go"Go!H#H#H#H# H#$GG"G!H#H#H#G H#GG"G!H#H# H#G H#GG"G!G!   +( +()+(1= > ?== > @?;@A+(BC DC ED;EF H LC V WV XW;XY b e;Xo+ u,=vuuu x===((( ; (== + ; =+(= =+ ; >; >6AHIAB= JIALMF)=CNMQ ONQ QNQ JQ OQ O    Q JQ !QQ $Q '$! (' )!(P )=WZYW>\ZQ `\AbcF1= dcef`dhfghghO=m\\ =WpoW>rpO=srr#AxyA1==zy ={Ez~~=8vh5hAB=(|e5A)5)==AxA)=== =E {  (uA)51== =E= Ab)5B=  ==851~=786A=(|e6A)6B=== {  (uA)6)===Ab)61= ==7615A)===7=m=sQ Q Q P>`AA=>>>8