summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/basicShader.fs
blob: 8a72e6d380f59e3fadec4a256885f1753ef4866c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#version 330 core
#extension GL_ARB_shading_language_420pack : enable

include(`materialInterface.glsl')
include(`geometryOut.glsl')

layout(binding = 0) uniform sampler2D texture0;
layout(binding = 1) uniform usampler2DRect material;

vec4 getTextureColour(uint midx, vec2 uv)
{
	if (midx > 0u) {
		const vec2 tSize = textureSize(texture0, 0);
		const vec4 sPosSize = texture(material, uvec2(0, midx - 1u));
		uv = (sPosSize.xy + sPosSize.zw * fract(uv)) / tSize;
	}
	return texture(texture0, uv);
}

void
main()
{
	vec4 textureColour = getTextureColour(Material, TexCoords);
	float opaque = step(0.5, mix(textureColour.a, 1, Colour.a));
	gPosition = vec4(FragPos, opaque);
	gNormal = vec4(Normal, opaque);
	gl_FragDepth = mix(1.0, gl_FragCoord.z, opaque);
	gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a);
}