Răsfoiți Sursa

Change the code style of GLSL to align to C++. Fix some bugs

Panagiotis Christopoulos Charitos 7 ani în urmă
părinte
comite
5e09da3576
100 a modificat fișierele cu 2536 adăugiri și 2538 ștergeri
  1. 2 1
      CMakeLists.txt
  2. 0 141
      programs/DeferredShading.ankiprog
  3. 0 85
      programs/ExponentialShadowmappingResolve.ankiprog
  4. 0 75
      programs/LensFlareSprite.ankiprog
  5. 0 186
      programs/LightShading.ankiprog
  6. 0 332
      programs/Reflections.ankiprog
  7. 0 142
      programs/TemporalAAResolve.ankiprog
  8. 0 222
      programs/VolumetricFog.ankiprog
  9. 1 1
      samples/simple_scene/assets/room-material.ankimtl
  10. 1 1
      samples/sponza/assets/Material__57_001-material.ankimtl
  11. 1 1
      samples/sponza/assets/arch-material.ankimtl
  12. 1 1
      samples/sponza/assets/bricks-material.ankimtl
  13. 1 1
      samples/sponza/assets/ceiling-material.ankimtl
  14. 1 1
      samples/sponza/assets/chain-material.ankimtl
  15. 1 1
      samples/sponza/assets/column_a-material.ankimtl
  16. 1 1
      samples/sponza/assets/column_b-material.ankimtl
  17. 1 1
      samples/sponza/assets/column_c-material.ankimtl
  18. 1 1
      samples/sponza/assets/details-material.ankimtl
  19. 1 1
      samples/sponza/assets/fabric_a-material.ankimtl
  20. 1 1
      samples/sponza/assets/fabric_c-material.ankimtl
  21. 1 1
      samples/sponza/assets/fabric_d-material.ankimtl
  22. 1 1
      samples/sponza/assets/fabric_e-material.ankimtl
  23. 1 1
      samples/sponza/assets/fabric_f-material.ankimtl
  24. 1 1
      samples/sponza/assets/fire.ankimtl
  25. 1 1
      samples/sponza/assets/flagpole-material.ankimtl
  26. 1 1
      samples/sponza/assets/floor-material.ankimtl
  27. 1 1
      samples/sponza/assets/leaf-material.ankimtl
  28. 1 1
      samples/sponza/assets/lion-material.ankimtl
  29. 1 1
      samples/sponza/assets/lion_stand-material.ankimtl
  30. 1 1
      samples/sponza/assets/roof-material.ankimtl
  31. 1 1
      samples/sponza/assets/smoke.ankimtl
  32. 1 1
      samples/sponza/assets/vase-material.ankimtl
  33. 1 1
      samples/sponza/assets/vase_hanging-material.ankimtl
  34. 1 1
      samples/sponza/assets/vase_round_001-material.ankimtl
  35. 1 1
      samples/sponza/assets/writings-material.ankimtl
  36. 4 4
      shaders/Blit.ankiprog
  37. 13 13
      shaders/Bloom.ankiprog
  38. 9 9
      shaders/BloomUpscale.ankiprog
  39. 32 92
      shaders/ClusterLightCommon.glsl
  40. 0 47
      shaders/Clusterer.glsl
  41. 7 10
      shaders/Common.glsl
  42. 8 8
      shaders/Dbg.ankiprog
  43. 3 3
      shaders/DepthAwareBlur.ankiprog
  44. 30 30
      shaders/DepthAwareBlur.glsl
  45. 3 3
      shaders/DepthAwareBlurCompute.ankiprog
  46. 11 11
      shaders/DepthDownscale.ankiprog
  47. 2 2
      shaders/DownscaleBlur.ankiprog
  48. 12 12
      shaders/DownscaleBlur.glsl
  49. 2 2
      shaders/DownscaleBlurCompute.ankiprog
  50. 85 0
      shaders/ExponentialShadowmappingResolve.ankiprog
  51. 19 19
      shaders/FinalComposite.ankiprog
  52. 44 43
      shaders/ForwardShadingCommonFrag.glsl
  53. 4 4
      shaders/ForwardShadingCommonVert.glsl
  54. 11 11
      shaders/ForwardShadingFog.ankiprog
  55. 21 21
      shaders/ForwardShadingParticles.ankiprog
  56. 11 11
      shaders/ForwardShadingUpscale.ankiprog
  57. 11 11
      shaders/ForwardShadingVolumetricUpscale.ankiprog
  58. 109 109
      shaders/Functions.glsl
  59. 62 62
      shaders/GBufferCommonFrag.glsl
  60. 60 60
      shaders/GBufferCommonTessc.glsl
  61. 49 49
      shaders/GBufferCommonTesse.glsl
  62. 38 38
      shaders/GBufferCommonVert.glsl
  63. 28 25
      shaders/GBufferGeneric.ankiprog
  64. 39 39
      shaders/GBufferPost.ankiprog
  65. 3 3
      shaders/GaussianBlur.ankiprog
  66. 22 22
      shaders/GaussianBlur.glsl
  67. 12 12
      shaders/GaussianBlurCommon.glsl
  68. 3 3
      shaders/GaussianBlurCompute.ankiprog
  69. 19 19
      shaders/Irradiance.ankiprog
  70. 68 0
      shaders/LensFlareSprite.ankiprog
  71. 20 20
      shaders/LensFlareUpdateIndirectInfo.ankiprog
  72. 70 70
      shaders/LightFunctions.glsl
  73. 186 0
      shaders/LightShading.ankiprog
  74. 19 19
      shaders/LumaAwareBlur.ankiprog
  75. 75 75
      shaders/Pack.glsl
  76. 6 6
      shaders/QuadVert.glsl
  77. 332 0
      shaders/Reflections.ankiprog
  78. 17 17
      shaders/SceneDebug.ankiprog
  79. 22 22
      shaders/ScreenSpaceLensFlare.ankiprog
  80. 9 9
      shaders/Ssao.ankiprog
  81. 56 56
      shaders/Ssao.glsl
  82. 8 10
      shaders/SsaoCompute.ankiprog
  83. 0 120
      shaders/Sslr.glsl
  84. 142 0
      shaders/TemporalAAResolve.ankiprog
  85. 24 24
      shaders/Tonemapping.glsl
  86. 25 25
      shaders/TonemappingAverageLuminance.ankiprog
  87. 2 2
      shaders/TonemappingResources.glsl
  88. 127 0
      shaders/TraditionalDeferredShading.ankiprog
  89. 14 14
      shaders/Ui.ankiprog
  90. 223 0
      shaders/VolumetricFog.ankiprog
  91. 75 0
      shaders/glsl_cpp_common/ClusteredShading.h
  92. 50 0
      shaders/glsl_cpp_common/Clusterer.h
  93. 50 0
      shaders/glsl_cpp_common/Common.h
  94. 23 0
      shaders/glsl_cpp_common/LensFlareSprite.h
  95. 38 0
      shaders/glsl_cpp_common/TraditionalDeferredShading.h
  96. 19 0
      src/anki/gr/ShaderCompiler.cpp
  97. 9 19
      src/anki/gr/vulkan/DescriptorSet.cpp
  98. 6 0
      src/anki/math/Vec2.h
  99. 3 3
      src/anki/renderer/Bloom.cpp
  100. 3 9
      src/anki/renderer/Clusterer.h

+ 2 - 1
CMakeLists.txt

@@ -360,7 +360,8 @@ include_directories("src"
 	"thirdparty/khronos"
 	"${CMAKE_CURRENT_BINARY_DIR}"
 	"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glslang"
-	"thirdparty")
+	"thirdparty"
+	${CMAKE_CURRENT_SOURCE_DIR})
 
 if(LINUX OR MACOS OR WINDOWS)
 	include_directories("thirdparty/GLEW/include")

+ 0 - 141
programs/DeferredShading.ankiprog

@@ -1,141 +0,0 @@
-<!-- 
-Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-All rights reserved.
-Code licensed under the BSD License.
-http://www.anki3d.org/LICENSE
--->
-
-<!-- Classic deferred lighting shader -->
-
-<shaderProgram>
-	<mutators>
-		<mutator name="LIGHT_TYPE" values="0 1"/>
-	</mutators>
-
-	<shaders>
-		<shader type="vert">
-			<source><![CDATA[
-#include "shaders/Common.glsl"
-
-layout(location = 0) in vec3 in_position;
-
-out gl_PerVertex
-{
-	vec4 gl_Position;
-};
-
-layout(ANKI_UBO_BINDING(0, 0), row_major) uniform u0_
-{
-	mat4 u_mvp;
-};
-
-void main()
-{
-	gl_Position = u_mvp * vec4(in_position, 1.0);
-}
-			]]></source>
-		</shader>
-
-		<shader type="frag">
-			<inputs>
-				<input name="FB_SIZE" type="uvec2" const="1"/>
-			</inputs>
-
-			<source><![CDATA[
-#include "shaders/Pack.glsl"
-#include "shaders/LightFunctions.glsl"
-
-#define POINT_LIGHT_TYPE 0
-#define SPOT_LIGHT_TYPE 1
-
-layout(location = 0) out vec3 out_color;
-
-// Point light
-struct PointLight
-{
-	vec4 posRadius; // xyz: Light pos in world space. w: The -1/radius
-	vec4 diffuseColorPad1; // xyz: diff color
-};
-
-// Spot light
-struct SpotLight
-{
-	vec4 posRadius; // xyz: Light pos in world space. w: The -1/radius
-	vec4 diffuseColorOuterCos; // xyz: diff color, w: outer cosine of spot
-	vec4 lightDirInnerCos; // xyz: light dir, w: inner cosine of spot
-};
-
-layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msRt0;
-layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_msRt1;
-layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_msRt2;
-layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_msDepthRt;
-
-layout(ANKI_UBO_BINDING(0, 1), row_major) uniform u1_
-{
-	vec4 u_inputTexUvScaleAndOffset; // Use this to get the correct face UVs
-	mat4 u_invViewProjMat;
-	vec4 u_camPosPad1;
-#if LIGHT_TYPE == POINT_LIGHT_TYPE
-	PointLight u_light;
-#elif LIGHT_TYPE == SPOT_LIGHT_TYPE
-	SpotLight u_light;
-#else
-#	error See file
-#endif
-};
-
-#if LIGHT_TYPE == POINT_LIGHT_TYPE
-#	define u_ldiff u_light.diffuseColorPad1.xyz
-#else
-#	define u_ldiff u_light.diffuseColorOuterCos.xyz
-#	define u_lightDir u_light.lightDirInnerCos.xyz
-#	define u_outerCos u_light.diffuseColorOuterCos.w
-#	define u_innerCos u_light.lightDirInnerCos.w
-#	define u_lightDir u_light.lightDirInnerCos.xyz
-#endif
-
-#define u_camPos u_camPosPad1.xyz
-
-void main()
-{
-	// Compute UV coordinates
-	vec2 uv = vec2(gl_FragCoord.xy) / vec2(FB_SIZE.x, FB_SIZE.y);
-	vec2 uvToRead = fma(uv, u_inputTexUvScaleAndOffset.xy, u_inputTexUvScaleAndOffset.zw);
-
-	// Do manual depth test
-	float depth = texture(u_msDepthRt, uvToRead).r;
-	if(gl_FragCoord.z < depth)
-	{
-		discard;
-	}
-
-	// Decode and process gbuffer
-	GbufferInfo gbuffer;
-	readGBuffer(u_msRt0, u_msRt1, u_msRt2, uvToRead, 0.0, gbuffer);
-
-	vec4 worldPos4 = u_invViewProjMat * vec4(UV_TO_NDC(uv), depth, 1.0);
-	vec3 worldPos = worldPos4.xyz / worldPos4.w;
-
-	// Calculate the light color
-	vec3 viewDir = normalize(u_camPos - worldPos);
-	vec3 frag2Light = u_light.posRadius.xyz - worldPos;
-	vec3 l = normalize(frag2Light);
-	float nol = max(0.0, dot(gbuffer.normal, l));
-
-	vec3 specC = computeSpecularColorBrdf(gbuffer, viewDir, l);
-	vec3 diffC = diffuseLambert(gbuffer.diffuse);
-
-	float att = computeAttenuationFactor(u_light.posRadius.w, frag2Light);
-	float lambert = nol;
-
-#if LIGHT_TYPE == POINT_LIGHT_TYPE
-	out_color = (specC + diffC) * u_ldiff * (att * max(lambert, gbuffer.subsurface));
-#else
-	float spot = computeSpotFactor(l, u_outerCos, u_innerCos, u_lightDir);
-	out_color = (diffC + specC) * u_ldiff * (att * spot * max(lambert, gbuffer.subsurface));
-#endif
-}
-			]]></source>
-		</shader>
-	</shaders>
-</shaderProgram>

+ 0 - 85
programs/ExponentialShadowmappingResolve.ankiprog

@@ -1,85 +0,0 @@
-<!-- 
-Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-All rights reserved.
-Code licensed under the BSD License.
-http://www.anki3d.org/LICENSE
--->
-<shaderProgram>
-	<shaders>
-		<shader type="vert">
-			<source><![CDATA[
-#include "shaders/Common.glsl"
-
-out gl_PerVertex
-{
-	vec4 gl_Position;
-};
-
-layout(ANKI_UBO_BINDING(0, 0)) uniform u_
-{
-	vec4 u_nearFarPad2;
-	vec4 u_uvScaleAndTranslation;
-};
-
-layout(location = 0) out vec2 out_uv;
-
-void main()
-{
-	out_uv = vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
-	vec2 pos = out_uv * 2.0 - 1.0;
-
-	out_uv = fma(out_uv, u_uvScaleAndTranslation.zw, u_uvScaleAndTranslation.xy);
-	gl_Position = vec4(pos, 0.0, 1.0);
-}
-			]]></source>
-		</shader>
-
-		<shader type="frag">
-			<inputs>
-				<input name="INPUT_TEXTURE_SIZE" type="uvec2" const="1"/>
-			</inputs>
-
-			<source><![CDATA[
-#include "shaders/GaussianBlurCommon.glsl"
-#include "shaders/Functions.glsl"
-
-layout(location = 0) in vec2 in_uv;
-
-layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_inputTex;
-
-layout(ANKI_UBO_BINDING(0, 0)) uniform u_
-{
-	vec4 u_nearFarPad2;
-	vec4 u_uvScaleAndTranslation;
-};
-
-#define u_near u_nearFarPad2.x
-#define u_far u_nearFarPad2.y
-
-layout(location = 0) out float out_color;
-
-float sampleLinearDepth(vec2 uv)
-{
-	return linearizeDepth(textureLod(u_inputTex, uv, 0.0).r, u_near, u_far);
-}
-
-void main()
-{
-	const vec2 TEXEL_SIZE = 1.0 / vec2(INPUT_TEXTURE_SIZE);
-	vec2 uvOffset = 1.1 * TEXEL_SIZE;
-
-	out_color = sampleLinearDepth(in_uv) * BOX_WEIGHTS[0u];
-	out_color += sampleLinearDepth(in_uv + vec2(uvOffset.x, 0.0)) * BOX_WEIGHTS[1u];
-	out_color += sampleLinearDepth(in_uv + vec2(-uvOffset.x, 0.0)) * BOX_WEIGHTS[1u];
-	out_color += sampleLinearDepth(in_uv + vec2(0.0, uvOffset.y)) * BOX_WEIGHTS[1u];
-	out_color += sampleLinearDepth(in_uv + vec2(0.0, -uvOffset.y)) * BOX_WEIGHTS[1u];
-	out_color += sampleLinearDepth(in_uv + vec2(uvOffset.x, uvOffset.y)) * BOX_WEIGHTS[2u];
-	out_color += sampleLinearDepth(in_uv + vec2(-uvOffset.x, uvOffset.y)) * BOX_WEIGHTS[2u];
-	out_color += sampleLinearDepth(in_uv + vec2(uvOffset.x, -uvOffset.y)) * BOX_WEIGHTS[2u];
-	out_color += sampleLinearDepth(in_uv + vec2(-uvOffset.x, -uvOffset.y)) * BOX_WEIGHTS[2u];
-}
-			]]></source>
-		</shader>
-	</shaders>
-</shaderProgram>
-

+ 0 - 75
programs/LensFlareSprite.ankiprog

@@ -1,75 +0,0 @@
-<!-- 
-Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-All rights reserved.
-Code licensed under the BSD License.
-http://www.anki3d.org/LICENSE
--->
-<shaderProgram>
-	<shaders>
-		<shader type="vert">
-			<inputs>
-				<input name="MAX_SPRITES" type="uint" const="1"/>
-			</inputs>
-
-			<source><![CDATA[
-#include "shaders/Common.glsl"
-
-// Per flare information
-struct Sprite
-{
-	vec4 posScale; // xy: Position, zw: Scale
-	vec4 color;
-	vec4 depthPad3;
-};
-
-// The block contains data for all flares
-layout(std140, ANKI_UBO_BINDING(0, 0)) uniform _blk
-{
-	Sprite u_sprites[MAX_SPRITES];
-};
-
-layout(location = 0) out vec3 out_uv;
-layout(location = 1) flat out vec4 out_color;
-
-out gl_PerVertex
-{
-	vec4 gl_Position;
-};
-
-void main()
-{
-	vec2 position = UV_TO_NDC(vec2(gl_VertexID & 1, gl_VertexID >> 1));
-
-	Sprite sprite = u_sprites[gl_InstanceID];
-
-	// Write tex coords of the 2D array texture
-	out_uv = vec3((position * 0.5) + 0.5, sprite.depthPad3.x);
-
-	vec4 posScale = sprite.posScale;
-	gl_Position = vec4(position * posScale.zw + posScale.xy, 0.0, 1.0);
-
-	out_color = sprite.color;
-}
-			]]></source>
-		</shader>
-
-		<shader type="frag">
-			<source><![CDATA[
-#include "shaders/Common.glsl"
-
-layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2DArray u_tex;
-
-layout(location = 0) in vec3 in_uv;
-layout(location = 1) flat in vec4 in_color;
-
-layout(location = 0) out vec4 out_color;
-
-void main()
-{
-	vec4 col = texture(u_tex, in_uv);
-	out_color = col * in_color;
-}
-			]]></source>
-		</shader>
-	</shaders>
-</shaderProgram>

+ 0 - 186
programs/LightShading.ankiprog

@@ -1,186 +0,0 @@
-<!-- 
-Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-All rights reserved.
-Code licensed under the BSD License.
-http://www.anki3d.org/LICENSE
--->
-<shaderProgram>
-	<inputs>
-		<input name="CLUSTER_COUNT_X" type="uint" const="1"/>
-		<input name="CLUSTER_COUNT_Y" type="uint" const="1"/>
-		<input name="CLUSTER_COUNT_Z" type="uint" const="1"/>
-		<input name="CLUSTER_COUNT" type="uint" const="1"/>
-		<input name="IR_MIPMAP_COUNT" type="uint" const="1"/>
-	</inputs>
-
-	<shaders>
-		<shader type="vert">
-			<source><![CDATA[
-#include "shaders/Common.glsl"
-
-layout(location = 0) out vec2 out_uv;
-layout(location = 1) out vec2 out_clusterIJ;
-
-out gl_PerVertex
-{
-	vec4 gl_Position;
-};
-
-void main()
-{
-	out_uv = vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
-	vec2 pos = out_uv * 2.0 - 1.0;
-	gl_Position = vec4(pos, 0.0, 1.0);
-
-	out_clusterIJ = vec2(CLUSTER_COUNT_X, CLUSTER_COUNT_Y) * out_uv;
-}
-			]]></source>
-		</shader>
-
-		<shader type="frag">
-			<source><![CDATA[
-#include "shaders/Pack.glsl"
-#include "shaders/Clusterer.glsl"
-#include "shaders/Functions.glsl"
-
-#define LIGHT_SET 0
-#define LIGHT_SS_BINDING 0
-#define LIGHT_UBO_BINDING 0
-#define LIGHT_TEX_BINDING 5
-#define LIGHT_LIGHTS
-#define LIGHT_COMMON_UNIS
-#include "shaders/ClusterLightCommon.glsl"
-
-layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msRt0;
-layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_msRt1;
-layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_msRt2;
-layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_msDepthRt;
-layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_indirectRt;
-
-layout(location = 0) in vec2 in_uv;
-layout(location = 1) in vec2 in_clusterIJ;
-
-layout(location = 0) out vec3 out_color;
-
-const float SUBSURFACE_MIN = 0.05;
-
-// Common code for lighting
-#define LIGHTING_COMMON_BRDF() \
-	vec3 frag2Light = light.posRadius.xyz - worldPos; \
-	vec3 l = normalize(frag2Light); \
-	vec3 specC = computeSpecularColorBrdf(gbuffer, viewDir, l); \
-	vec3 diffC = diffuseLambert(gbuffer.diffuse); \
-	float att = computeAttenuationFactor(light.posRadius.w, frag2Light); \
-	float lambert = max(0.0, dot(gbuffer.normal, l));
-
-void main()
-{
-	float depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
-	vec2 ndc = UV_TO_NDC(in_uv);
-
-	// Get world position
-	vec4 worldPos4 = u_invViewProjMat * vec4(ndc, depth, 1.0);
-	vec3 worldPos = worldPos4.xyz / worldPos4.w;
-
-	// Get first light index
-	uint idxOffset;
-	{
-		uint k = computeClusterK(u_clustererMagic, worldPos);
-		uint clusterIdx = 
-			k * (CLUSTER_COUNT_X * CLUSTER_COUNT_Y) + uint(in_clusterIJ.y) * CLUSTER_COUNT_X + uint(in_clusterIJ.x);
-
-		idxOffset = u_clusters[clusterIdx];
-	}
-
-	// Decode GBuffer
-	GbufferInfo gbuffer;
-	readGBuffer(u_msRt0, u_msRt1, u_msRt2, in_uv, 0.0, gbuffer);
-	gbuffer.subsurface = max(gbuffer.subsurface, SUBSURFACE_MIN);
-
-	// Ambient and emissive color
-	out_color = gbuffer.diffuse * gbuffer.emission;
-
-	// Indirect
-	out_color += textureLod(u_indirectRt, in_uv, 0.0).rgb;
-
-	// Skip decals
-	uint count = u_lightIndices[idxOffset];
-	idxOffset += count + 1u;
-
-	// Point lights
-	vec3 viewDir = normalize(u_cameraPos - worldPos);
-	count = u_lightIndices[idxOffset++];
-	uint idxOffsetEnd = idxOffset + count;
-	ANKI_LOOP while(idxOffset < idxOffsetEnd)
-	{
-		PointLight light = u_pointLights[u_lightIndices[idxOffset++]];
-
-		LIGHTING_COMMON_BRDF();
-
-		if(light.diffuseColorTileSize.w >= 0.0)
-		{
-			float shadow = computeShadowFactorOmni(frag2Light, 
-				light.radiusPad1.x, 
-				light.atlasTiles, 
-				light.diffuseColorTileSize.w,
-				u_shadowTex);
-			lambert *= shadow;
-		}
-
-		out_color += (diffC + specC) * light.diffuseColorTileSize.rgb * (att * max(gbuffer.subsurface, lambert));
-	}
-
-	// Spot lights
-	count = u_lightIndices[idxOffset++];
-	idxOffsetEnd = idxOffset + count;
-	ANKI_LOOP while(idxOffset < idxOffsetEnd)
-	{
-		SpotLight light = u_spotLights[u_lightIndices[idxOffset++]];
-
-		LIGHTING_COMMON_BRDF();
-
-		float spot = computeSpotFactor(
-			l, light.outerCosInnerCos.x, light.outerCosInnerCos.y, light.lightDirRadius.xyz);
-
-		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-		if(shadowmapLayerIdx >= 0.0)
-		{
-			float shadow = computeShadowFactorSpot(
-				light.texProjectionMat, worldPos, light.lightDirRadius.w, u_shadowTex);
-			lambert *= shadow;
-		}
-
-		out_color += 
-			(diffC + specC) * light.diffuseColorShadowmapId.rgb * (att * spot * max(gbuffer.subsurface, lambert));
-	}
-
-#if 0
-	count = scount;
-	if(count == 0)
-	{
-		out_color = vec3(0.0, 0.0, 0.0);
-	}
-	else if(count == 1)
-	{
-		out_color = vec3(1.0, 0.0, 0.0);
-	}
-	else if(count == 2)
-	{
-		out_color = vec3(0.0, 1.0, 0.0);
-	}
-	else if(count == 3)
-	{
-		out_color = vec3(0.0, 0.0, 1.0);
-	}
-	else
-	{
-		out_color = vec3(1.0, 1.0, 1.0);
-	}
-#endif
-}
-			]]></source>
-		</shader>
-	</shaders>
-
-</shaderProgram>
-

+ 0 - 332
programs/Reflections.ankiprog

@@ -1,332 +0,0 @@
-<!-- 
-Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-All rights reserved.
-Code licensed under the BSD License.
-http://www.anki3d.org/LICENSE
--->
-<shaderProgram>
-	<mutators>
-		<mutator name="VARIANT" values="0 1"/>
-	</mutators>
-
-	<shaders>
-		<shader type="comp">
-			<inputs>
-				<input name="FB_SIZE" type="uvec2" const="1"/>
-				<input name="WORKGROUP_SIZE" type="uvec2" const="1"/>
-				<input name="MAX_STEPS" type="uint" const="1"/>
-				<input name="LIGHT_BUFFER_MIP_COUNT" type="uint" const="1"/>
-				<input name="HIZ_MIP_COUNT" type="uint" const="1"/>
-				<input name="CLUSTER_COUNT_X" type="uint" const="1"/>
-				<input name="CLUSTER_COUNT_Y" type="uint" const="1"/>
-				<input name="CLUSTER_COUNT_Z" type="uint" const="1"/>
-				<input name="IR_MIPMAP_COUNT" type="uint" const="1"/>
-			</inputs>
-
-			<source><![CDATA[
-// if VARIANT==0 then the checkerboard pattern is (render on 'v'):
-// -----
-// |v| |
-// | |v|
-// -----
-
-
-#include "shaders/Functions.glsl"
-#include "shaders/Pack.glsl"
-#include "shaders/Clusterer.glsl"
-
-#define LIGHT_SET 0
-#define LIGHT_SS_BINDING 0
-#define LIGHT_UBO_BINDING 0
-#define LIGHT_TEX_BINDING 6
-#define LIGHT_INDIRECT
-#define LIGHT_COMMON_UNIS
-#include "shaders/ClusterLightCommon.glsl"
-
-const ivec2 HIZ_SIZE = ivec2(FB_SIZE) >> 1;
-
-layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
-
-layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_gbufferRt0;
-layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_gbufferRt1;
-layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_gbufferRt2;
-layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_depthRt;
-layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_hizRt;
-layout(ANKI_TEX_BINDING(0, 5)) uniform sampler2D u_lightBufferRt;
-
-layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D out_reflAndIndirect;
-
-// Temp buffer to hold the indirect color
-shared vec3 s_pixels[WORKGROUP_SIZE.y][WORKGROUP_SIZE.x];
-
-#define u_normalMat mat3(u_viewMat)
-
-vec4 returnSslrColor(vec3 raySample, float factor, float roughness)
-{
-	// Re-project previous frame
-	vec4 v4 = u_prevViewProjMatMulInvViewProjMat * vec4(UV_TO_NDC(raySample.xy), raySample.z, 1.0);
-	raySample.xy = NDC_TO_UV(v4.xy / v4.w);
-	raySample.xy = saturate(raySample.xy);
-
-	vec2 ndc = abs(UV_TO_NDC(raySample.xy));
-	float contribution = max(ndc.x, ndc.y);
-	contribution = 1.0 - contribution * contribution;
-	contribution *= factor;
-
-	float lod = float(LIGHT_BUFFER_MIP_COUNT - 1u) * roughness;
-	vec3 color = textureLod(u_lightBufferRt, raySample.xy, lod).rgb;
-	return vec4(color, contribution);
-}
-
-// Note: All calculations in view space
-vec4 doSslr(vec3 r, vec3 n, vec3 viewPos, vec2 uv, float depth, float roughness)
-{
-	vec3 p0 = viewPos;
-
-	// Check for view facing reflections [sakibsaikia]
-	vec3 viewDir = normalize(viewPos);
-	float cameraFacingReflectionAttenuation = 1.0 - smoothstep(0.25, 0.5, dot(-viewDir, r));
-	if(cameraFacingReflectionAttenuation <= 0.0)
-	{
-		return vec4(0.0);
-	}
-
-	// Compute an end point p1. This point is supposed to fall in front of the near plane. Add a small padding to near
-	// to avoid having p1 touching the near plane.
-	vec3 p1 = p0 + r * (-p0.z - (u_near + 0.1));
-
-	// Start point
-	vec3 start = vec3(uv, depth);
-
-	// Project end point
-	vec4 end4 = u_projMat * vec4(p1, 1.0);
-	vec3 end = end4.xyz / end4.w;
-	end.xy = NDC_TO_UV(end.xy);
-
-	// Compute the ray and step size
-	vec3 ray = end - start;
-	vec2 texelDims = abs(ray.xy) * vec2(HIZ_SIZE);
-	float stepSize = length(ray.xy) / max(texelDims.x, texelDims.y);
-	ray = normalize(ray);
-
-	// Compute step
-	const uint BIG_STEP_SKIP = 32u;
-	uint stepSkip = BIG_STEP_SKIP;
-
-	uint l = gl_GlobalInvocationID.x & 1u;
-	uint j = gl_GlobalInvocationID.y & 1u;
-	const uint STEPS_ARR[4] = uint[](6u, 25u, 13u, 18u);
-	uint step = STEPS_ARR[l * 2u + j];
-	
-	// Iterate
-	bool found = false;
-	vec3 raySample;
-	ANKI_LOOP for(uint iterations = 0u; iterations < MAX_STEPS; ++iterations)
-	{
-		raySample = start + ray * (float(step) * stepSize);
-
-		// Check if it's out of the view
-		if(raySample.x <= 0.0 || raySample.y <= 0.0 || raySample.x >= 1.0 || raySample.y >= 1.0)
-		{
-			break;
-		}
-
-		float depth = textureLod(u_hizRt, raySample.xy, 0.0).r;
-
-		bool hit = raySample.z - depth >= 0.0;
-		if(!hit)
-		{
-			step += stepSkip;
-		}
-		else if(stepSkip > 1)
-		{
-			step -= BIG_STEP_SKIP - 1u;
-			stepSkip = 1u;
-		}
-		else
-		{
-			found = true;
-			break;
-		}
-	}
-
-	//return vec4(heatmap(float(iterations) / float(MAX_STEPS)), 1.0);
-
-	if(found)
-	{
-		return returnSslrColor(raySample, cameraFacingReflectionAttenuation, roughness);
-	}
-	else
-	{
-		return vec4(0.0);
-	}
-}
-
-// Note: All calculations in world space
-void readReflectionsAndIrradianceFromProbes(
-	uint idxOffset, vec3 worldPos, vec3 normal, float roughness, out vec3 specIndirect, out vec3 diffIndirect)
-{
-	specIndirect = vec3(0.0);
-	diffIndirect = vec3(0.0);
-
-	vec3 viewDir = normalize(worldPos - u_cameraPos);
-	vec3 reflDir = reflect(viewDir, normal);
-
-	float reflLod = float(IR_MIPMAP_COUNT - 1u) * roughness;
-
-	// Check proxy
-	uint count = u_lightIndices[idxOffset++];
-	ANKI_LOOP while(count-- != 0)
-	{
-		ReflectionProbe probe = u_reflectionProbes[u_lightIndices[idxOffset++]];
-
-		float R2 = probe.positionRadiusSq.w;
-		vec3 center = probe.positionRadiusSq.xyz;
-
-		// Get distance from the center of the probe
-		vec3 f = worldPos - center;
-
-		// Cubemap UV in view space
-		vec3 uv = computeCubemapVecAccurate(reflDir, R2, f);
-
-		// Read!
-		float cubemapIndex = probe.cubemapIndexPad3.x;
-		vec3 c = textureLod(u_reflectionsTex, vec4(uv, cubemapIndex), reflLod).rgb;
-
-		// Combine (lerp) with previous color
-		float d = dot(f, f);
-		float factor = d / R2;
-		factor = min(factor, 1.0);
-		specIndirect = mix(c, specIndirect, factor);
-
-		// Do the same for diffuse
-		uv = computeCubemapVecAccurate(normal, R2, f);
-		vec3 id = textureLod(u_irradianceTex, vec4(uv, cubemapIndex), 0.0).rgb;
-		diffIndirect = mix(id, diffIndirect, factor);
-	}
-}
-
-void main()
-{
-	// Compute a global invocation ID that takes the checkerboard pattern into account
-	ivec2 fixedInvocationId = ivec2(gl_GlobalInvocationID.xy);
-	fixedInvocationId.x *= 2;
-#if VARIANT == 0
-	fixedInvocationId.x += ((fixedInvocationId.y + 1) & 1);
-#else
-	fixedInvocationId.x += ((fixedInvocationId.y + 0) & 1);
-#endif
-
-	if(fixedInvocationId.x >= int(FB_SIZE.x) || fixedInvocationId.y >= int(FB_SIZE.y))
-	{
-		// Skip threads outside the writable image
-		return;
-	}
-
-	vec2 uv = (vec2(fixedInvocationId) + 0.5) / vec2(FB_SIZE);
-	vec2 ndc = UV_TO_NDC(uv);
-
-	// Read gbuffer
-	GbufferInfo gbuffer;
-	readGBuffer(u_gbufferRt0, u_gbufferRt1, u_gbufferRt2, uv, 0.0, gbuffer);
-
-	// Get depth
-	float depth = textureLod(u_depthRt, uv, 0.0).r;
-
-	// Get world position
-	vec4 worldPos4 = u_invViewProjMat * vec4(ndc, depth, 1.0);
-	vec3 worldPos = worldPos4.xyz / worldPos4.w;
-
-	// Compute env BRDF
-	vec3 env;
-	{
-		vec3 viewDir = normalize(u_cameraPos - worldPos);
-		float NoV = max(EPSILON, dot(gbuffer.normal, viewDir));
-		env = envBRDF(gbuffer.specular, gbuffer.roughness, u_integrationLut, NoV);
-	}
-
-	// Try SSR
-	float sslrFactor = 0.0;
-	vec3 sslrCol = vec3(0.0);
-	if(env.g > 0.05)
-	{
-		// Get view pos
-		vec4 viewPos4 = u_invProjMat * vec4(UV_TO_NDC(uv), depth, 1.0);
-		vec3 viewPos = viewPos4.xyz / viewPos4.w;
-
-		// Do SSLR
-		vec3 viewDir = normalize(viewPos);
-		vec3 viewNormal = u_normalMat * gbuffer.normal;
-		vec3 reflVec = reflect(viewDir, viewNormal);
-
-		vec4 sslr = doSslr(reflVec, viewNormal, viewPos, uv, depth, gbuffer.roughness);
-		sslrFactor = sslr.w;
-		sslrCol = sslr.xyz;
-		sslrCol = clamp(sslrCol, 0.0, FLT_MAX); // Fix the value just in case
-	}
-
-	// Read probes
-	vec3 probeCol = vec3(0.0);
-	vec3 indirectCol = vec3(0.0);
-	{
-		// Get first light index
-		uint clusterIdx = computeClusterIndex(u_clustererMagic, uv, worldPos, CLUSTER_COUNT_X, CLUSTER_COUNT_Y);
-		uint idxOffset = u_clusters[clusterIdx];
-
-		// Skip decals
-		uint count = u_lightIndices[idxOffset++];
-		idxOffset += count;
-		
-		// Skip point lights
-		count = u_lightIndices[idxOffset++];
-		idxOffset += count;
-
-		// Skip spot lights
-		count = u_lightIndices[idxOffset++];
-		idxOffset += count;
-
-		// Do the probe read
-		readReflectionsAndIrradianceFromProbes(
-			idxOffset, worldPos, gbuffer.normal, gbuffer.roughness, probeCol, indirectCol);
-	}
-
-	// Combine the SSR and probe reflections and write the result
-	vec3 finalRefl = mix(probeCol, sslrCol, sslrFactor);
-
-	// Compute the final color
-	vec3 outColor = indirectCol * gbuffer.diffuse + finalRefl * env;
-
-	// Store the color for the resolve
-	s_pixels[gl_LocalInvocationID.y][gl_LocalInvocationID.x] = outColor;
-
-	// Wait for all the threads to store their stuff
-	memoryBarrierShared();
-	barrier();
-
-	// Compute the missing pixel by resolving with the right or left neighbour
-	ivec2 readPixel, storePixel;
-	readPixel.y = int(gl_LocalInvocationID.y);
-	storePixel.y = fixedInvocationId.y;
-
-#if VARIANT == 0
-	bool pickRightNeighbour = (fixedInvocationId.y & 1) == 1;
-#else
-	bool pickRightNeighbour = (fixedInvocationId.y & 1) == 0;
-#endif
-	int xOffset = (pickRightNeighbour) ? 1 : -1;
-	
-	readPixel.x = int(gl_LocalInvocationID.x) + xOffset;
-	readPixel.x = clamp(readPixel.x, 0, int(WORKGROUP_SIZE.x - 1));
-
-	storePixel.x = fixedInvocationId.x + xOffset;
-
-	vec3 missingColor = (outColor + s_pixels[readPixel.y][readPixel.x]) * 0.5; // average
-
-	// Store both the pixels
-	imageStore(out_reflAndIndirect, fixedInvocationId, vec4(outColor, 0.0));
-	imageStore(out_reflAndIndirect, storePixel, vec4(missingColor, 0.0));
-}
-			]]></source>
-		</shader>
-	</shaders>
-</shaderProgram>

+ 0 - 142
programs/TemporalAAResolve.ankiprog

@@ -1,142 +0,0 @@
-<!-- 
-Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-All rights reserved.
-Code licensed under the BSD License.
-http://www.anki3d.org/LICENSE
--->
-<shaderProgram>
-	<mutators>
-		<mutator name="SHARPEN" values="0 1 2"/> <!-- 0: disabled, 1: vertical, 2: horizontal -->
-		<mutator name="VARIANCE_CLIPPING" values="0 1"/>
-		<mutator name="TONEMAP_FIX" values="0 1"/>
-		<mutator name="YCBCR" values="0 1"/>
-	</mutators>
-
-	<inputs>
-		<input name="VARIANCE_CLIPPING_GAMMA" type="float" const="1"/>
-		<input name="BLEND_FACTOR" type="float" const="1"/>
-	</inputs>
-
-	<shaders>
-		<shader type="vert">
-			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
-			]]></source>
-		</shader>
-
-		<shader type="frag">
-			<source><![CDATA[
-#include "shaders/Functions.glsl"
-#include "shaders/Pack.glsl"
-#include "shaders/Tonemapping.glsl"
-
-layout(location = 0) in vec2 in_uv;
-
-layout(location = 0) out vec3 out_color;
-
-layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
-layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_inputRt;
-layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_historyRt;
-
-layout(ANKI_UBO_BINDING(0, 0), std140, row_major) uniform u0_
-{
-	mat4 u_prevViewProjMatMulInvViewProjMat;
-};
-
-#if TONEMAP_FIX
-#define TONEMAPPING_SET 0
-#define TONEMAPPING_BINDING 1
-#include "shaders/TonemappingResources.glsl"
-#endif
-
-#if YCBCR
-#define sample(s, uv) rgbToYCbCr(textureLod(s, uv, 0.0).rgb)
-#define sampleOffset(s, uv, x, y) rgbToYCbCr(textureLodOffset(s, uv, 0.0, ivec2(x, y)).rgb)
-#else
-#define sample(s, uv) textureLod(s, uv, 0.0).rgb
-#define sampleOffset(s, uv, x, y) textureLodOffset(s, uv, 0.0, ivec2(x, y)).rgb
-#endif
-
-vec3 sharpen()
-{
-	vec3 center = sample(u_inputRt, in_uv);
-#if SHARPEN == 1
-	vec3 near = sampleOffset(u_inputRt, in_uv, 1, 0) + sampleOffset(u_inputRt, in_uv, -1, 0);
-#else
-	vec3 near = sampleOffset(u_inputRt, in_uv, 0, 1) + sampleOffset(u_inputRt, in_uv, 0, -1);
-#endif
-	near *= 0.5;
-	float sharpness = 1.0;
-	return center + (center - near) * sharpness;
-}
-
-void main()
-{
-	float depth = textureLod(u_depthRt, in_uv, 0.0).r;
-
-	// Get prev uv coords
-	vec4 v4 = u_prevViewProjMatMulInvViewProjMat * vec4(UV_TO_NDC(in_uv), depth, 1.0);
-	vec2 oldUv = NDC_TO_UV(v4.xy / v4.w);
-
-	// Read textures
-	vec3 historyCol = sample(u_historyRt, oldUv);
-#if SHARPEN > 0
-	vec3 crntCol = sharpen();
-#else
-	vec3 crntCol = sample(u_inputRt, in_uv);
-#endif
-
-	// Remove ghosting by clamping the history color to neighbour's AABB
-	vec3 near0 = sampleOffset(u_inputRt, in_uv, 1, 0);
-	vec3 near1 = sampleOffset(u_inputRt, in_uv, 0, 1);
-	vec3 near2 = sampleOffset(u_inputRt, in_uv, -1, 0);
-	vec3 near3 = sampleOffset(u_inputRt, in_uv, 0, -1);
-
-#if VARIANCE_CLIPPING
-	vec3 m1 = crntCol + near0 + near1 + near2 + near3;
-	vec3 m2 = crntCol * crntCol + near0 * near0 + near1 * near1 + near2 * near2 + near3 * near3;
-
-	vec3 mu = m1 / 5.0;
-	vec3 sigma = sqrt(m2 / 5.0 - mu * mu);
-
-	vec3 boxMin = mu - VARIANCE_CLIPPING_GAMMA * sigma;
-	vec3 boxMax = mu + VARIANCE_CLIPPING_GAMMA * sigma;
-#else
-	vec3 boxMin = min(crntCol, min(near0, min(near1, min(near2, near3))));
-	vec3 boxMax = max(crntCol, max(near0, max(near1, max(near2, near3))));
-#endif
-
-	historyCol = clamp(historyCol, boxMin, boxMax);
-
-	// Remove jitter (T. Lottes)
-#if YCBCR
-	float lum0 = crntCol.r;
-	float lum1 = historyCol.r;
-	float maxLum = boxMax.r;
-#elif TONEMAP_FIX
-	float lum0 = computeLuminance(tonemap(crntCol, u_exposureThreshold0));
-	float lum1 = computeLuminance(tonemap(historyCol, u_exposureThreshold0));
-	//float maxLum = computeLuminance(tonemap(boxMax, u_exposureThreshold0));
-	float maxLum = 1.0;
-#else
-	float lum0 = computeLuminance(crntCol);
-	float lum1 = computeLuminance(historyCol);
-	float maxLum = computeLuminance(boxMax);
-#endif
-
-	float diff = abs(lum0 - lum1) / max(lum0, max(lum1, maxLum + EPSILON));
-	diff = 1.0 - diff;
-	diff = diff * diff;
-	float feedback = mix(0.0, BLEND_FACTOR, diff);
-
-	// Write result
-#if YCBCR
-	out_color = yCbCrToRgb(mix(historyCol, crntCol, feedback));
-#else
-	out_color = mix(historyCol, crntCol, feedback);
-#endif
-}
-			]]></source>
-		</shader>
-	</shaders>
-</shaderProgram>

+ 0 - 222
programs/VolumetricFog.ankiprog

@@ -1,222 +0,0 @@
-<!-- 
-Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-All rights reserved.
-Code licensed under the BSD License.
-http://www.anki3d.org/LICENSE
--->
-<shaderProgram>
-	<mutators>
-		<mutator name="ENABLE_SHADOWS" values="0 1"/>
-	</mutators>
-
-	<shaders>
-		<shader type="vert">
-			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
-			]]></source>
-		</shader>
-
-		<shader type="frag">
-			<inputs>
-				<input name="FB_SIZE" type="uvec2" const="1"/>
-				<input name="CLUSTER_COUNT" type="uvec3" const="1"/>
-				<input name="NOISE_MAP_SIZE" type="uint" const="1"/>
-			</inputs>
-
-			<source><![CDATA[
-#include "shaders/Common.glsl"
-#include "shaders/Functions.glsl"
-#include "shaders/Clusterer.glsl"
-
-#define LIGHT_TEX_BINDING 3
-#define LIGHT_UBO_BINDING 0
-#define LIGHT_SS_BINDING 0
-#define LIGHT_SET 0
-#define LIGHT_LIGHTS
-#define LIGHT_COMMON_UNIS
-#include "shaders/ClusterLightCommon.glsl"
-
-layout(location = 0) in vec2 in_uv;
-
-layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msDepthRt;
-layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2DArray u_noiseTex;
-layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_historyRt;
-
-layout(std140, ANKI_UBO_BINDING(0, 3), row_major) uniform ubo0_
-{
-	vec4 u_linearizeNoiseTexOffsetLayer;
-	vec4 u_fogParticleColorPad1;
-	mat4 u_prevViewProjMatMulInvViewProjMat2; // TODO Light common ubo has that. Maybe remove it
-};
-
-#define u_linearize UNIFORM(u_linearizeNoiseTexOffsetLayer.xy)
-#define u_noiseYOffset UNIFORM(u_linearizeNoiseTexOffsetLayer.z)
-#define u_noiseLayer UNIFORM(u_linearizeNoiseTexOffsetLayer.w)
-#define u_fogParticleColor UNIFORM(u_fogParticleColorPad1.rgb)
-
-layout(location = 0) out vec3 out_color;
-
-const uint MAX_SAMPLES_PER_CLUSTER = 4u;
-const float DIST_BETWEEN_SAMPLES = 0.25;
-const float HISTORY_FEEDBACK = 1.0 / 16.0;
-
-// Return the diffuse color without taking into account the diffuse term of the particles.
-vec3 computeLightColor(vec3 fragPos, uint plightCount, uint plightIdx, uint slightCount, uint slightIdx)
-{
-	vec3 outColor = vec3(0.0);
-
-	// Point lights
-	ANKI_LOOP while(plightCount-- != 0)
-	{
-		PointLight light = u_pointLights[u_lightIndices[plightIdx++]];
-		vec3 frag2Light = light.posRadius.xyz - fragPos;
-		float factor = computeAttenuationFactor(light.posRadius.w, frag2Light);
-
-#if ENABLE_SHADOWS
-		if(light.diffuseColorTileSize.w >= 0.0)
-		{
-			factor *= computeShadowFactorOmni(frag2Light, 
-				light.radiusPad1.x, 
-				light.atlasTiles,
-				light.diffuseColorTileSize.w,
-				u_shadowTex);
-		}
-#endif
-
-		outColor += light.diffuseColorTileSize.rgb * factor;
-	}
-
-	// Spot lights
-	ANKI_LOOP while(slightCount-- != 0)
-	{
-		SpotLight light = u_spotLights[u_lightIndices[slightIdx++]];
-		vec3 frag2Light = light.posRadius.xyz - fragPos;
-		float factor = computeAttenuationFactor(light.posRadius.w, frag2Light);
-
-		vec3 l = normalize(frag2Light);
-
-		factor *= computeSpotFactor(l, light.outerCosInnerCos.x, light.outerCosInnerCos.y, light.lightDirRadius.xyz);
-
-#if ENABLE_SHADOWS
-		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
-		if(shadowmapLayerIdx >= 0.0)
-		{
-			factor *= computeShadowFactorSpot(
-				light.texProjectionMat, fragPos, light.lightDirRadius.w, u_shadowTex);
-		}
-#endif
-
-		outColor += light.diffuseColorShadowmapId.rgb * factor;
-	}
-
-	return outColor;
-}
-
-vec3 readHistory(vec3 ndc, out float historyFeedback)
-{
-	vec4 v4 = u_prevViewProjMatMulInvViewProjMat2 * vec4(ndc, 1.0);
-	v4.xy /= v4.w;
-
-	vec2 oldUv = NDC_TO_UV(v4.xy);
-	vec3 history = textureLod(u_historyRt, oldUv, 0.0).rgb;
-
-	// Compute the history blend. If clip falls outside NDC then it's 1.0 (use only current fog term) and if it's
-	// inside NDC then use the HISTORY_FEEDBACK value
-	vec2 posNdc = abs(v4.xy);
-	historyFeedback = max(posNdc.x, posNdc.y);
-	historyFeedback = min(floor(historyFeedback), 1.0 - HISTORY_FEEDBACK);
-	historyFeedback += HISTORY_FEEDBACK;
-
-	return history;
-}
-
-void main()
-{
-	float depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
-
-	vec3 ndc = vec3(UV_TO_NDC(in_uv), depth);
-
-	vec3 farPos;
-	farPos.z = u_unprojectionParams.z / (u_unprojectionParams.w + depth);
-	farPos.xy = ndc.xy * u_unprojectionParams.xy * farPos.z;
-	vec3 viewDir = normalize(farPos);
-
-	uint i = uint(in_uv.x * float(CLUSTER_COUNT.x));
-	uint j = uint(in_uv.y * float(CLUSTER_COUNT.y));
-	uint ij = j * CLUSTER_COUNT.x + i;
-
-	vec3 noiseTexUv = vec3(vec2(FB_SIZE) / vec2(NOISE_MAP_SIZE) * in_uv + vec2(0.0, u_noiseYOffset), u_noiseLayer);
-	float randFactor = clamp(texture(u_noiseTex, noiseTexUv).r, EPSILON, 1.0 - EPSILON);
-
-	float kNear = -u_near;
-	vec3 newCol = vec3(0.0);
-	ANKI_LOOP for(uint k = 0u; k < CLUSTER_COUNT.z; ++k)
-	{
-		float kFar = -computeClusterFar(u_clustererMagic, k);
-
-		//
-		// Compute sample count
-		//
-		float diff = kNear - kFar;
-		float samplesf = clamp(diff / DIST_BETWEEN_SAMPLES, 1.0, float(MAX_SAMPLES_PER_CLUSTER));
-		float dist = 1.0 / samplesf;
-		float start = dist * randFactor;
-
-		//
-		// Find index ranges
-		//
-		uint clusterIdx = k * (CLUSTER_COUNT.x * CLUSTER_COUNT.y) + ij;
-		uint idxOffset = u_clusters[clusterIdx];
-
-		// Skip decals
-		uint count = u_lightIndices[idxOffset];
-		idxOffset += count + 1;
-
-		uint plightCount = u_lightIndices[idxOffset++];
-		uint plightIdx = idxOffset;
-		idxOffset += plightCount;
-
-		uint slightCount = u_lightIndices[idxOffset++];
-		uint slightIdx = idxOffset;
-
-		ANKI_LOOP for(float factor = start; factor <= 1.0; factor += dist)
-		{
-			float zMedian = mix(kNear, kFar, factor);
-
-			ANKI_BRANCH if(zMedian < farPos.z)
-			{
-				k = CLUSTER_COUNT.z; // Break the outer loop
-				break;
-			}
-
-			vec3 fragPos = viewDir * (zMedian / viewDir.z);
-
-			// Move to world space
-			vec4 newWorldPos4 = u_invViewMat * vec4(fragPos, 1.0);
-
-			newCol += computeLightColor(newWorldPos4.xyz, plightCount, plightIdx, slightCount, slightIdx);
-		}
-
-		kNear = kFar;
-	}
-
-	newCol *= diffuseLambert(u_fogParticleColor);
-
-	// Read history
-	float historyFeedback;
-	vec3 history = readHistory(ndc, historyFeedback);
-	
-	// Fix ghosting
-	history = max(history, newCol);
-
-	// Blend
-	out_color = mix(history, newCol, historyFeedback);
-}
-			]]></source>
-		</shader>
-	</shaders>
-
-</shaderProgram>
-
-
-

+ 1 - 1
samples/simple_scene/assets/room-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="0"/>

+ 1 - 1
samples/sponza/assets/Material__57_001-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/arch-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/bricks-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/ceiling-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/chain-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/column_a-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/column_b-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/column_c-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/details-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/fabric_a-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/fabric_c-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/fabric_d-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/fabric_e-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/fabric_f-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/fire.ankimtl

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<material shaderProgram="programs/ForwardShadingParticles.ankiprog" forwardShading="1" shadow="0">
+<material shaderProgram="shaders/ForwardShadingParticles.ankiprog" forwardShading="1" shadow="0">
 	<mutators>
 		<mutator name="ANIMATED_TEXTURE" value="0"/>
 		<mutator name="LIGHT" value="0"/>

+ 1 - 1
samples/sponza/assets/flagpole-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/floor-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/leaf-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/lion-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/lion_stand-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/roof-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/smoke.ankimtl

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<material shaderProgram="programs/ForwardShadingParticles.ankiprog" forwardShading="1" shadow="0">
+<material shaderProgram="shaders/ForwardShadingParticles.ankiprog" forwardShading="1" shadow="0">
 	<mutators>
 		<mutator name="ANIMATED_TEXTURE" value="0"/>
 		<mutator name="LIGHT" value="1"/>

+ 1 - 1
samples/sponza/assets/vase-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/vase_hanging-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/vase_round_001-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 1 - 1
samples/sponza/assets/writings-material.ankimtl

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- This file is auto generated by ExporterMaterial.cpp -->
-<material shaderProgram="programs/GBufferGeneric.ankiprog">
+<material shaderProgram="shaders/GBufferGeneric.ankiprog">
 	
 	<mutators>
 		<mutator name="DIFFUSE_TEX" value="1"/>

+ 4 - 4
programs/Blit.ankiprog → shaders/Blit.ankiprog

@@ -8,18 +8,18 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex;
 
-layout(location = 0) in vec2 in_uv;
-layout(location = 0) out vec3 out_col;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 0) out Vec3 out_col;
 
 void main()
 {

+ 13 - 13
programs/Bloom.ankiprog → shaders/Bloom.ankiprog

@@ -8,50 +8,50 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="TEX_SIZE" type="vec2" const="1"/>
+				<input name="TEX_SIZE" type="Vec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Common.glsl"
-#include "shaders/Tonemapping.glsl"
+#include <shaders/Common.glsl>
+#include <shaders/Tonemapping.glsl>
 
 // Vars
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex; ///< Its the IS RT
 
 layout(ANKI_UBO_BINDING(0, 0), std140) uniform u0_
 {
-	vec4 u_thresholdScalePad2;
+	Vec4 u_thresholdScalePad2;
 };
 
 layout(ANKI_SS_BINDING(0, 0), std140) readonly buffer ss0_
 {
-	vec4 u_averageLuminancePad3;
+	Vec4 u_averageLuminancePad3;
 };
 
-layout(location = 0) in vec2 in_uv;
-layout(location = 0) out vec4 out_color;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 0) out Vec4 out_color;
 
 void main()
 {
-	const vec2 TEXEL_SIZE = 1.0 / TEX_SIZE;
+	const Vec2 TEXEL_SIZE = 1.0 / TEX_SIZE;
 
-	vec3 color = textureLod(u_tex, in_uv, 0.0).rgb;
+	Vec3 color = textureLod(u_tex, in_uv, 0.0).rgb;
 	color += textureLod(u_tex, in_uv + TEXEL_SIZE, 0.0).rgb;
 	color += textureLod(u_tex, in_uv - TEXEL_SIZE, 0.0).rgb;
-	color += textureLod(u_tex, in_uv + vec2(TEXEL_SIZE.x, -TEXEL_SIZE.y), 0.0).rgb;
-	color += textureLod(u_tex, in_uv + vec2(-TEXEL_SIZE.x, TEXEL_SIZE.y), 0.0).rgb;
+	color += textureLod(u_tex, in_uv + Vec2(TEXEL_SIZE.x, -TEXEL_SIZE.y), 0.0).rgb;
+	color += textureLod(u_tex, in_uv + Vec2(-TEXEL_SIZE.x, TEXEL_SIZE.y), 0.0).rgb;
 
 	color /= 5.0;
 
 	color = tonemap(color, u_averageLuminancePad3.x, u_thresholdScalePad2.x) * u_thresholdScalePad2.y;
 
-	out_color = vec4(color, 0.25);
+	out_color = Vec4(color, 0.25);
 }
 			]]></source>
 		</shader>

+ 9 - 9
programs/BloomUpscale.ankiprog → shaders/BloomUpscale.ankiprog

@@ -8,33 +8,33 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="TEX_SIZE" type="vec2" const="1"/>
+				<input name="TEX_SIZE" type="Vec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform mediump sampler2D u_tex;
 
-layout(location = 0) in vec2 in_texCoord;
-layout(location = 0) out vec3 out_color;
+layout(location = 0) in Vec2 in_texCoord;
+layout(location = 0) out Vec3 out_color;
 
 void main()
 {
-	const vec2 TEXEL_SIZE = 1.0 / TEX_SIZE;
-	const float MIPMAP = 0.0;
+	const Vec2 TEXEL_SIZE = 1.0 / TEX_SIZE;
+	const F32 MIPMAP = 0.0;
 
 	out_color = textureLod(u_tex, in_texCoord, MIPMAP).rgb;
 	out_color += textureLod(u_tex, in_texCoord + TEXEL_SIZE, MIPMAP).rgb;
 	out_color += textureLod(u_tex, in_texCoord - TEXEL_SIZE, MIPMAP).rgb;
-	out_color += textureLod(u_tex, in_texCoord + vec2(TEXEL_SIZE.x, -TEXEL_SIZE.y), MIPMAP).rgb;
-	out_color += textureLod(u_tex, in_texCoord + vec2(-TEXEL_SIZE.x, TEXEL_SIZE.y), MIPMAP).rgb;
+	out_color += textureLod(u_tex, in_texCoord + Vec2(TEXEL_SIZE.x, -TEXEL_SIZE.y), MIPMAP).rgb;
+	out_color += textureLod(u_tex, in_texCoord + Vec2(-TEXEL_SIZE.x, TEXEL_SIZE.y), MIPMAP).rgb;
 
 	out_color /= 5.0;
 }

+ 32 - 92
shaders/ClusterLightCommon.glsl

@@ -6,110 +6,50 @@
 #ifndef ANKI_SHADERS_CLUSTER_LIGHT_COMMON_GLSL
 #define ANKI_SHADERS_CLUSTER_LIGHT_COMMON_GLSL
 
-#include "shaders/LightFunctions.glsl"
-#include "shaders/Clusterer.glsl"
-
-// Common uniforms between lights
-struct LightingUniforms
-{
-	vec4 unprojectionParams;
-	vec4 rendererSizeTimeNear;
-	vec4 cameraPosFar;
-	ClustererMagicValues clustererMagicValues;
-	uvec4 tileCount;
-	mat4 viewMat;
-	mat4 invViewMat;
-	mat4 projMat;
-	mat4 invProjMat;
-	mat4 viewProjMat;
-	mat4 invViewProjMat;
-	mat4 prevViewProjMat;
-	mat4 prevViewProjMatMulInvViewProjMat; // Used to re-project previous frames
-};
-
-// Point light
-struct PointLight
-{
-	vec4 posRadius; // xyz: Light pos in world space. w: The 1/(radius^2)
-	vec4 diffuseColorTileSize; // xyz: diff color, w: tile size in the shadow atlas
-	vec2 radiusPad1; // x: radius
-	uvec2 atlasTiles; // x: encodes 6 uints with atlas tile indices in the x dir. y: same for y dir.
-};
-const uint SIZEOF_POINT_LIGHT = 3 * SIZEOF_VEC4;
-
-// Spot light
-struct SpotLight
-{
-	vec4 posRadius; // xyz: Light pos in world space. w: The 1/(radius^2)
-	vec4 diffuseColorShadowmapId; // xyz: diff color, w: shadowmap tex ID
-	vec4 lightDirRadius; // xyz: light direction, w: radius
-	vec4 outerCosInnerCos;
-	mat4 texProjectionMat;
-};
-const uint SIZEOF_SPOT_LIGHT = 4 * SIZEOF_VEC4 + SIZEOF_MAT4;
-
-// Representation of a reflection probe
-struct ReflectionProbe
-{
-	// Position of the prove in view space. Radius of probe squared
-	vec4 positionRadiusSq;
-
-	// Slice in u_reflectionsTex vector.
-	vec4 cubemapIndexPad3;
-};
-const uint SIZEOF_REFLECTION_PROBE = 2 * SIZEOF_VEC4;
-
-// Decal
-struct Decal
-{
-	vec4 diffUv;
-	vec4 normRoughnessUv;
-	mat4 texProjectionMat;
-	vec4 blendFactors;
-};
-const uint SIZEOF_DECAL = 3 * SIZEOF_VEC4 + SIZEOF_MAT4;
+#include <shaders/LightFunctions.glsl>
+#include <shaders/glsl_cpp_common/ClusteredShading.h>
 
 //
 // Common uniforms
 //
 #if defined(LIGHT_COMMON_UNIS)
 
-const uint _NEXT_UBO_BINDING = LIGHT_UBO_BINDING + 1;
+const U32 _NEXT_UBO_BINDING = LIGHT_UBO_BINDING + 1;
 
 layout(ANKI_UBO_BINDING(LIGHT_SET, LIGHT_UBO_BINDING), std140, row_major) uniform lu0_
 {
 	LightingUniforms u_lightingUniforms;
 };
 
-#	define u_near UNIFORM(u_lightingUniforms.rendererSizeTimeNear.w)
-#	define u_far UNIFORM(u_lightingUniforms.cameraPosFar.w)
-#	define u_cameraPos UNIFORM(u_lightingUniforms.cameraPosFar.xyz)
-#	define u_clusterCountX UNIFORM(u_lightingUniforms.tileCount.x)
-#	define u_clusterCountY UNIFORM(u_lightingUniforms.tileCount.y)
-#	define u_clustererMagic u_lightingUniforms.clustererMagicValues
-#	define u_time UNIFORM(u_lightingUniforms.rendererSizeTimeNear.z)
-#	define u_unprojectionParams UNIFORM(u_lightingUniforms.unprojectionParams)
-#	define u_rendererSize u_lightingUniforms.rendererSizeTimeNear.xy
-
-#	define u_viewMat u_lightingUniforms.viewMat
-#	define u_invViewMat u_lightingUniforms.invViewMat
-#	define u_projMat u_lightingUniforms.projMat
-#	define u_invProjMat u_lightingUniforms.invProjMat
-#	define u_viewProjMat u_lightingUniforms.viewProjMat
-#	define u_invViewProjMat u_lightingUniforms.invViewProjMat
-#	define u_prevViewProjMat u_lightingUniforms.prevViewProjMat
-#	define u_prevViewProjMatMulInvViewProjMat u_lightingUniforms.prevViewProjMatMulInvViewProjMat
+#	define u_near UNIFORM(u_lightingUniforms.m_rendererSizeTimeNear.w)
+#	define u_far UNIFORM(u_lightingUniforms.m_cameraPosFar.w)
+#	define u_cameraPos UNIFORM(u_lightingUniforms.m_cameraPosFar.xyz)
+#	define u_clusterCountX UNIFORM(u_lightingUniforms.m_tileCount.x)
+#	define u_clusterCountY UNIFORM(u_lightingUniforms.m_tileCount.y)
+#	define u_clustererMagic u_lightingUniforms.m_clustererMagicValues
+#	define u_time UNIFORM(u_lightingUniforms.m_rendererSizeTimeNear.z)
+#	define u_unprojectionParams UNIFORM(u_lightingUniforms.m_unprojectionParams)
+#	define u_rendererSize u_lightingUniforms.m_rendererSizeTimeNear.xy
+
+#	define u_viewMat u_lightingUniforms.m_viewMat
+#	define u_invViewMat u_lightingUniforms.m_invViewMat
+#	define u_projMat u_lightingUniforms.m_projMat
+#	define u_invProjMat u_lightingUniforms.m_invProjMat
+#	define u_viewProjMat u_lightingUniforms.m_viewProjMat
+#	define u_invViewProjMat u_lightingUniforms.m_invViewProjMat
+#	define u_prevViewProjMat u_lightingUniforms.m_prevViewProjMat
+#	define u_prevViewProjMatMulInvViewProjMat u_lightingUniforms.m_prevViewProjMatMulInvViewProjMat
 
 #else
-const uint _NEXT_UBO_BINDING = LIGHT_UBO_BINDING;
+const U32 _NEXT_UBO_BINDING = LIGHT_UBO_BINDING;
 #endif
 
 //
 // Light uniforms
 //
 #if defined(LIGHT_LIGHTS)
-const uint _NEXT_UBO_BINDING_2 = _NEXT_UBO_BINDING + 2;
-const uint _NEXT_TEX_BINDING_2 = LIGHT_TEX_BINDING + 1;
+const U32 _NEXT_UBO_BINDING_2 = _NEXT_UBO_BINDING + 2;
+const U32 _NEXT_TEX_BINDING_2 = LIGHT_TEX_BINDING + 1;
 
 layout(ANKI_UBO_BINDING(LIGHT_SET, _NEXT_UBO_BINDING), std140) uniform u1_
 {
@@ -123,16 +63,16 @@ layout(ANKI_UBO_BINDING(LIGHT_SET, _NEXT_UBO_BINDING + 1), std140, row_major) un
 
 layout(ANKI_TEX_BINDING(LIGHT_SET, LIGHT_TEX_BINDING + 0)) uniform highp sampler2D u_shadowTex;
 #else
-const uint _NEXT_UBO_BINDING_2 = _NEXT_UBO_BINDING;
-const uint _NEXT_TEX_BINDING_2 = LIGHT_TEX_BINDING;
+const U32 _NEXT_UBO_BINDING_2 = _NEXT_UBO_BINDING;
+const U32 _NEXT_TEX_BINDING_2 = LIGHT_TEX_BINDING;
 #endif
 
 //
 // Indirect uniforms
 //
 #if defined(LIGHT_INDIRECT)
-const uint _NEXT_UBO_BINDING_3 = _NEXT_UBO_BINDING_2 + 1;
-const uint _NEXT_TEX_BINDING_3 = _NEXT_TEX_BINDING_2 + 3;
+const U32 _NEXT_UBO_BINDING_3 = _NEXT_UBO_BINDING_2 + 1;
+const U32 _NEXT_TEX_BINDING_3 = _NEXT_TEX_BINDING_2 + 3;
 
 layout(std140, row_major, ANKI_UBO_BINDING(LIGHT_SET, _NEXT_UBO_BINDING_2)) uniform u3_
 {
@@ -143,8 +83,8 @@ layout(ANKI_TEX_BINDING(LIGHT_SET, _NEXT_TEX_BINDING_2 + 0)) uniform samplerCube
 layout(ANKI_TEX_BINDING(LIGHT_SET, _NEXT_TEX_BINDING_2 + 1)) uniform samplerCubeArray u_irradianceTex;
 layout(ANKI_TEX_BINDING(LIGHT_SET, _NEXT_TEX_BINDING_2 + 2)) uniform sampler2D u_integrationLut;
 #else
-const uint _NEXT_UBO_BINDING_3 = _NEXT_UBO_BINDING_2;
-const uint _NEXT_TEX_BINDING_3 = _NEXT_TEX_BINDING_2;
+const U32 _NEXT_UBO_BINDING_3 = _NEXT_UBO_BINDING_2;
+const U32 _NEXT_TEX_BINDING_3 = _NEXT_TEX_BINDING_2;
 #endif
 
 //
@@ -165,12 +105,12 @@ layout(ANKI_TEX_BINDING(LIGHT_SET, _NEXT_TEX_BINDING_3 + 1)) uniform sampler2D u
 //
 layout(ANKI_SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 0), std430) readonly buffer s0_
 {
-	uint u_clusters[];
+	U32 u_clusters[];
 };
 
 layout(std430, ANKI_SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 1)) readonly buffer s1_
 {
-	uint u_lightIndices[];
+	U32 u_lightIndices[];
 };
 
 #endif

+ 0 - 47
shaders/Clusterer.glsl

@@ -1,47 +0,0 @@
-// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-// Contains functions for the clusterer
-
-#ifndef ANKI_SHADERS_CLUSTERER_GLSL
-#define ANKI_SHADERS_CLUSTERER_GLSL
-
-#include "shaders/Common.glsl"
-
-// See the documentation of the Clusterer class.
-struct ClustererMagicValues
-{
-	vec4 val0;
-	vec4 val1;
-};
-
-uint computeClusterK(ClustererMagicValues magic, vec3 worldPos)
-{
-	float fz = sqrt(dot(magic.val0.xyz, worldPos) - magic.val0.w);
-	uint z = uint(fz);
-	return z;
-}
-
-// Compute cluster index
-uint computeClusterIndex(ClustererMagicValues magic, vec2 uv, vec3 worldPos, uint clusterCountX, uint clusterCountY)
-{
-	uvec2 xy = uvec2(uv * vec2(clusterCountX, clusterCountY));
-
-	return computeClusterK(magic, worldPos) * (clusterCountX * clusterCountY) + xy.y * clusterCountX + xy.x;
-}
-
-// Compute the Z of the near plane given a cluster idx
-float computeClusterNear(ClustererMagicValues magic, uint k)
-{
-	float fk = float(k);
-	return magic.val1.x * fk * fk + magic.val1.y;
-}
-
-float computeClusterFar(ClustererMagicValues magic, uint k)
-{
-	return computeClusterNear(magic, k + 1u);
-}
-
-#endif

+ 7 - 10
shaders/Common.glsl

@@ -31,18 +31,15 @@
 #endif
 
 // Constants
-precision DEFAULT_FLOAT_PRECISION float;
-precision DEFAULT_INT_PRECISION int;
+precision DEFAULT_FLOAT_PRECISION F32;
+precision DEFAULT_INT_PRECISION I32;
 
-const float EPSILON = 0.000001;
-const float FLT_MAX = 3.402823e+38;
-const uint MAX_U32 = 0xFFFFFFFFu;
+const F32 EPSILON = 0.000001;
+const F32 FLT_MAX = 3.402823e+38;
+const U32 MAX_U32 = 0xFFFFFFFFu;
 
-const float PI = 3.14159265358979323846;
-const uint UBO_MAX_SIZE = 16384u;
-
-const uint SIZEOF_VEC4 = 4 * 4;
-const uint SIZEOF_MAT4 = 4 * SIZEOF_VEC4;
+const F32 PI = 3.14159265358979323846;
+const U32 UBO_MAX_SIZE = 16384u;
 
 // Macros
 #define UV_TO_NDC(x_) ((x_)*2.0 - 1.0)

+ 8 - 8
programs/Dbg.ankiprog → shaders/Dbg.ankiprog

@@ -8,16 +8,16 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
-layout(location = 0) in vec4 in_position;
-layout(location = 1) in vec4 in_color;
+layout(location = 0) in Vec4 in_position;
+layout(location = 1) in Vec4 in_color;
 
-layout(location = 0) out vec4 out_color;
+layout(location = 0) out Vec4 out_color;
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
 void main()
@@ -30,10 +30,10 @@ void main()
 
 		<shader type="frag">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
-layout(location = 0) in vec4 in_color;
-layout(location = 0) out vec4 out_color;
+layout(location = 0) in Vec4 in_color;
+layout(location = 0) out Vec4 out_color;
 
 void main()
 {

+ 3 - 3
programs/DepthAwareBlur.ankiprog → shaders/DepthAwareBlur.ankiprog

@@ -14,13 +14,13 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="TEXTURE_SIZE" type="uvec2" const="1"/>
+				<input name="TEXTURE_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
@@ -32,7 +32,7 @@ http://www.anki3d.org/LICENSE
 #	define BOX 1
 #endif
 
-#include "shaders/DepthAwareBlur.glsl"
+#include <shaders/DepthAwareBlur.glsl>
 			]]></source>
 		</shader>
 	</shaders>

+ 30 - 30
shaders/DepthAwareBlur.glsl

@@ -13,7 +13,7 @@
 #ifndef ANKI_SHADERS_DEPTH_AWARE_BLUR_GLSL
 #define ANKI_SHADERS_DEPTH_AWARE_BLUR_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #if SAMPLE_COUNT < 3
 #	error See file
@@ -27,17 +27,17 @@
 
 // Define some macros depending on the number of components
 #if COLOR_COMPONENTS == 4
-#	define COL_TYPE vec4
+#	define COL_TYPE Vec4
 #	define TEX_FETCH rgba
 #	define TO_VEC4(x_) x_
 #elif COLOR_COMPONENTS == 3
-#	define COL_TYPE vec3
+#	define COL_TYPE Vec3
 #	define TEX_FETCH rgb
-#	define TO_VEC4(x_) vec4(x_, 0.0)
+#	define TO_VEC4(x_) Vec4(x_, 0.0)
 #elif COLOR_COMPONENTS == 1
-#	define COL_TYPE float
+#	define COL_TYPE F32
 #	define TEX_FETCH r
-#	define TO_VEC4(x_) vec4(x_, 0.0, 0.0, 0.0)
+#	define TO_VEC4(x_) Vec4(x_, 0.0, 0.0, 0.0)
 #else
 #	error See file
 #endif
@@ -49,26 +49,26 @@ layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_depthTex;
 layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
 layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D u_outImg;
 #else
-layout(location = 0) in vec2 in_uv;
+layout(location = 0) in Vec2 in_uv;
 layout(location = 0) out COL_TYPE out_color;
 #endif
 
-float computeDepthWeight(float refDepth, float depth)
+F32 computeDepthWeight(F32 refDepth, F32 depth)
 {
-	float diff = abs(refDepth - depth);
-	float weight = 1.0 / (EPSILON + diff);
+	F32 diff = abs(refDepth - depth);
+	F32 weight = 1.0 / (EPSILON + diff);
 	return sqrt(weight);
 }
 
-float readDepth(vec2 uv)
+F32 readDepth(Vec2 uv)
 {
 	return textureLod(u_depthTex, uv, 0.0).r;
 }
 
-void sampleTex(vec2 uv, float refDepth, inout COL_TYPE col, inout float weight)
+void sampleTex(Vec2 uv, F32 refDepth, inout COL_TYPE col, inout F32 weight)
 {
 	COL_TYPE color = textureLod(u_inTex, uv, 0.0).TEX_FETCH;
-	float w = computeDepthWeight(refDepth, readDepth(uv));
+	F32 w = computeDepthWeight(refDepth, readDepth(uv));
 	col += color * w;
 	weight += w;
 }
@@ -83,17 +83,17 @@ void main()
 		return;
 	}
 
-	vec2 uv = (vec2(gl_GlobalInvocationID.xy) + 0.5) / vec2(TEXTURE_SIZE);
+	Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(TEXTURE_SIZE);
 #else
-	vec2 uv = in_uv;
+	Vec2 uv = in_uv;
 #endif
 
-	const vec2 TEXEL_SIZE = 1.0 / vec2(TEXTURE_SIZE);
+	const Vec2 TEXEL_SIZE = 1.0 / Vec2(TEXTURE_SIZE);
 
 	// Sample
 	COL_TYPE color = textureLod(u_inTex, uv, 0.0).TEX_FETCH;
-	float refDepth = readDepth(uv);
-	float weight = 1.0;
+	F32 refDepth = readDepth(uv);
+	F32 weight = 1.0;
 
 #if !defined(BOX)
 	// Do seperable
@@ -104,10 +104,10 @@ void main()
 #		define X_OR_Y y
 #	endif
 
-	vec2 uvOffset = vec2(0.0);
+	Vec2 uvOffset = Vec2(0.0);
 	uvOffset.X_OR_Y = 1.5 * TEXEL_SIZE.X_OR_Y;
 
-	ANKI_UNROLL for(uint i = 0u; i < (SAMPLE_COUNT - 1u) / 2u; ++i)
+	ANKI_UNROLL for(U32 i = 0u; i < (SAMPLE_COUNT - 1u) / 2u; ++i)
 	{
 		sampleTex(uv + uvOffset, refDepth, color, weight);
 		sampleTex(uv - uvOffset, refDepth, color, weight);
@@ -117,23 +117,23 @@ void main()
 #else
 	// Do box
 
-	const vec2 OFFSET = 1.5 * TEXEL_SIZE;
+	const Vec2 OFFSET = 1.5 * TEXEL_SIZE;
 
-	sampleTex(uv + vec2(+OFFSET.x, +OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + vec2(+OFFSET.x, -OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + vec2(-OFFSET.x, +OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + vec2(-OFFSET.x, -OFFSET.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(+OFFSET.x, +OFFSET.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(+OFFSET.x, -OFFSET.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(-OFFSET.x, +OFFSET.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(-OFFSET.x, -OFFSET.y), refDepth, color, weight);
 
-	sampleTex(uv + vec2(OFFSET.x, 0.0), refDepth, color, weight);
-	sampleTex(uv + vec2(0.0, OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + vec2(-OFFSET.x, 0.0), refDepth, color, weight);
-	sampleTex(uv + vec2(0.0, -OFFSET.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(OFFSET.x, 0.0), refDepth, color, weight);
+	sampleTex(uv + Vec2(0.0, OFFSET.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(-OFFSET.x, 0.0), refDepth, color, weight);
+	sampleTex(uv + Vec2(0.0, -OFFSET.y), refDepth, color, weight);
 #endif
 	color = color / weight;
 
 	// Write value
 #if USE_COMPUTE
-	imageStore(u_outImg, ivec2(gl_GlobalInvocationID.xy), TO_VEC4(color));
+	imageStore(u_outImg, IVec2(gl_GlobalInvocationID.xy), TO_VEC4(color));
 #else
 	out_color = color;
 #endif

+ 3 - 3
programs/DepthAwareBlurCompute.ankiprog → shaders/DepthAwareBlurCompute.ankiprog

@@ -14,8 +14,8 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="comp">
 			<inputs>
-				<input name="TEXTURE_SIZE" type="uvec2" const="1"/>
-				<input name="WORKGROUP_SIZE" type="uvec2" const="1"/>
+				<input name="TEXTURE_SIZE" type="UVec2" const="1"/>
+				<input name="WORKGROUP_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
@@ -27,7 +27,7 @@ http://www.anki3d.org/LICENSE
 #	define BOX 1
 #endif
 
-#include "shaders/DepthAwareBlur.glsl"
+#include <shaders/DepthAwareBlur.glsl>
 			]]></source>
 		</shader>
 	</shaders>

+ 11 - 11
programs/DepthDownscale.ankiprog → shaders/DepthDownscale.ankiprog

@@ -14,13 +14,13 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #define AVG 0
 #define MIN 1
@@ -29,34 +29,34 @@ http://www.anki3d.org/LICENSE
 #if COPY_TO_CLIENT
 struct PushConsts
 {
-	uvec2 textureSize;
+	UVec4 textureSize;
 };
 ANKI_PUSH_CONSTANTS(PushConsts, u_regs);
 
 layout(std430, ANKI_SS_BINDING(0, 0)) writeonly buffer s1_
 {
-	float u_clientBuf[];
+	F32 u_clientBuf[];
 };
 #endif
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
 
-layout(location = 0) in vec2 in_uv;
+layout(location = 0) in Vec2 in_uv;
 
-layout(location = 0) out float out_color;
+layout(location = 0) out F32 out_color;
 
 void main()
 {
-	vec4 depths = textureGather(u_depthRt, in_uv, 0);
+	Vec4 depths = textureGather(u_depthRt, in_uv, 0);
 
 #if SAMPLE_RESOLVE_TYPE == MIN
-	vec2 mind2 = min(depths.xy, depths.zw);
+	Vec2 mind2 = min(depths.xy, depths.zw);
 	out_color = min(mind2.x, mind2.y);
 #elif SAMPLE_RESOLVE_TYPE == MAX
-	vec2 max2 = max(depths.xy, depths.zw);
+	Vec2 max2 = max(depths.xy, depths.zw);
 	out_color = max(max2.x, max2.y);
 #elif SAMPLE_RESOLVE_TYPE == AVG
-	out_color = dot(depths, vec4(1.0 / 4.0));
+	out_color = dot(depths, Vec4(1.0 / 4.0));
 #else
 #	error See file
 #endif
@@ -66,7 +66,7 @@ void main()
 #endif
 
 #if COPY_TO_CLIENT
-	u_clientBuf[uint(gl_FragCoord.y) * u_regs.textureSize.x + uint(gl_FragCoord.x)] = out_color;
+	u_clientBuf[U32(gl_FragCoord.y) * u_regs.textureSize.x + U32(gl_FragCoord.x)] = out_color;
 #endif
 }
 			]]></source>

+ 2 - 2
programs/DownscaleBlur.ankiprog → shaders/DownscaleBlur.ankiprog

@@ -8,13 +8,13 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<source><![CDATA[
-#include "shaders/DownscaleBlur.glsl"
+#include <shaders/DownscaleBlur.glsl>
 			]]></source>
 		</shader>
 	</shaders>

+ 12 - 12
shaders/DownscaleBlur.glsl

@@ -6,7 +6,7 @@
 #ifndef ANKI_SHADERS_DOWNSCALE_BLUR_GLSL
 #define ANKI_SHADERS_DOWNSCALE_BLUR_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex;
 
@@ -16,17 +16,17 @@ layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_s
 // Push constants hold the size of the output image
 struct PushConsts
 {
-	uvec4 outImageSizePad2;
+	UVec4 m_outImageSizePad2;
 };
 ANKI_PUSH_CONSTANTS(PushConsts, u_regs);
-#	define u_fbSize (u_regs.outImageSizePad2.xy)
+#	define u_fbSize (u_regs.m_outImageSizePad2.xy)
 
-vec2 in_uv = (vec2(gl_GlobalInvocationID.xy) + 0.5) / vec2(u_fbSize);
+Vec2 in_uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(u_fbSize);
 layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D out_img;
-vec3 out_color;
+Vec3 out_color;
 #else
-layout(location = 0) in vec2 in_uv;
-layout(location = 0) out vec3 out_color;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 0) out Vec3 out_color;
 #endif
 
 void main()
@@ -40,15 +40,15 @@ void main()
 #endif
 
 	out_color = textureLod(u_tex, in_uv, 0.0).rgb;
-	out_color += textureLodOffset(u_tex, in_uv, 0.0, ivec2(+1, +1)).rgb;
-	out_color += textureLodOffset(u_tex, in_uv, 0.0, ivec2(-1, -1)).rgb;
-	out_color += textureLodOffset(u_tex, in_uv, 0.0, ivec2(+1, -1)).rgb;
-	out_color += textureLodOffset(u_tex, in_uv, 0.0, ivec2(-1, +1)).rgb;
+	out_color += textureLodOffset(u_tex, in_uv, 0.0, IVec2(+1, +1)).rgb;
+	out_color += textureLodOffset(u_tex, in_uv, 0.0, IVec2(-1, -1)).rgb;
+	out_color += textureLodOffset(u_tex, in_uv, 0.0, IVec2(+1, -1)).rgb;
+	out_color += textureLodOffset(u_tex, in_uv, 0.0, IVec2(-1, +1)).rgb;
 
 	out_color *= (1.0 / 5.0);
 
 #if defined(ANKI_COMPUTE_SHADER)
-	imageStore(out_img, ivec2(gl_GlobalInvocationID.xy), vec4(out_color, 0.0));
+	imageStore(out_img, IVec2(gl_GlobalInvocationID.xy), Vec4(out_color, 0.0));
 #endif
 }
 

+ 2 - 2
programs/DownscaleBlurCompute.ankiprog → shaders/DownscaleBlurCompute.ankiprog

@@ -8,11 +8,11 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="comp">
 			<inputs>
-				<input name="WORKGROUP_SIZE" type="uvec2" const="1"/>
+				<input name="WORKGROUP_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/DownscaleBlur.glsl"
+#include <shaders/DownscaleBlur.glsl>
 			]]></source>
 		</shader>
 	</shaders>

+ 85 - 0
shaders/ExponentialShadowmappingResolve.ankiprog

@@ -0,0 +1,85 @@
+<!-- 
+Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+<shaderProgram>
+	<shaders>
+		<shader type="vert">
+			<source><![CDATA[
+#include <shaders/Common.glsl>
+
+out gl_PerVertex
+{
+	Vec4 gl_Position;
+};
+
+layout(ANKI_UBO_BINDING(0, 0)) uniform u_
+{
+	Vec4 u_nearFarPad2;
+	Vec4 u_uvScaleAndTranslation;
+};
+
+layout(location = 0) out Vec2 out_uv;
+
+void main()
+{
+	out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
+	Vec2 pos = out_uv * 2.0 - 1.0;
+
+	out_uv = fma(out_uv, u_uvScaleAndTranslation.zw, u_uvScaleAndTranslation.xy);
+	gl_Position = Vec4(pos, 0.0, 1.0);
+}
+			]]></source>
+		</shader>
+
+		<shader type="frag">
+			<inputs>
+				<input name="INPUT_TEXTURE_SIZE" type="UVec2" const="1"/>
+			</inputs>
+
+			<source><![CDATA[
+#include <shaders/GaussianBlurCommon.glsl>
+#include <shaders/Functions.glsl>
+
+layout(location = 0) in Vec2 in_uv;
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_inputTex;
+
+layout(ANKI_UBO_BINDING(0, 0)) uniform u_
+{
+	Vec4 u_nearFarPad2;
+	Vec4 u_uvScaleAndTranslation;
+};
+
+#define u_near u_nearFarPad2.x
+#define u_far u_nearFarPad2.y
+
+layout(location = 0) out F32 out_color;
+
+F32 sampleLinearDepth(Vec2 uv)
+{
+	return linearizeDepth(textureLod(u_inputTex, uv, 0.0).r, u_near, u_far);
+}
+
+void main()
+{
+	const Vec2 TEXEL_SIZE = 1.0 / Vec2(INPUT_TEXTURE_SIZE);
+	Vec2 uvOffset = 1.1 * TEXEL_SIZE;
+
+	out_color = sampleLinearDepth(in_uv) * BOX_WEIGHTS[0u];
+	out_color += sampleLinearDepth(in_uv + Vec2(uvOffset.x, 0.0)) * BOX_WEIGHTS[1u];
+	out_color += sampleLinearDepth(in_uv + Vec2(-uvOffset.x, 0.0)) * BOX_WEIGHTS[1u];
+	out_color += sampleLinearDepth(in_uv + Vec2(0.0, uvOffset.y)) * BOX_WEIGHTS[1u];
+	out_color += sampleLinearDepth(in_uv + Vec2(0.0, -uvOffset.y)) * BOX_WEIGHTS[1u];
+	out_color += sampleLinearDepth(in_uv + Vec2(uvOffset.x, uvOffset.y)) * BOX_WEIGHTS[2u];
+	out_color += sampleLinearDepth(in_uv + Vec2(-uvOffset.x, uvOffset.y)) * BOX_WEIGHTS[2u];
+	out_color += sampleLinearDepth(in_uv + Vec2(uvOffset.x, -uvOffset.y)) * BOX_WEIGHTS[2u];
+	out_color += sampleLinearDepth(in_uv + Vec2(-uvOffset.x, -uvOffset.y)) * BOX_WEIGHTS[2u];
+}
+			]]></source>
+		</shader>
+	</shaders>
+</shaderProgram>
+

+ 19 - 19
programs/FinalComposite.ankiprog → shaders/FinalComposite.ankiprog

@@ -15,20 +15,20 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="LUT_SIZE" type="uint" const="1"/>
-				<input name="FB_SIZE" type="uvec2" const="1"/>
+				<input name="LUT_SIZE" type="U32" const="1"/>
+				<input name="FB_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Common.glsl"
-#include "shaders/Tonemapping.glsl"
-#include "shaders/Functions.glsl"
+#include <shaders/Common.glsl>
+#include <shaders/Tonemapping.glsl>
+#include <shaders/Functions.glsl>
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_isRt;
 layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_ppsBloomLfRt;
@@ -40,28 +40,28 @@ layout(ANKI_TEX_BINDING(0, 5)) uniform sampler2D u_dbgRt;
 
 layout(std140, ANKI_UBO_BINDING(0, 0)) uniform u0_
 {
-	vec4 u_blueNoiseLayerPad3;
+	Vec4 u_blueNoiseLayerPad3;
 };
 
 #define TONEMAPPING_BINDING 1
-#include "shaders/TonemappingResources.glsl"
+#include <shaders/TonemappingResources.glsl>
 
-layout(location = 0) in vec2 in_uv;
-layout(location = 0) out vec3 out_color;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 0) out Vec3 out_color;
 
-vec3 colorGrading(in vec3 color)
+Vec3 colorGrading(in Vec3 color)
 {
-	const vec3 LUT_SCALE = vec3((float(LUT_SIZE) - 1.0) / float(LUT_SIZE));
-	const vec3 LUT_OFFSET = vec3(1.0 / (2.0 * float(LUT_SIZE)));
+	const Vec3 LUT_SCALE = Vec3((F32(LUT_SIZE) - 1.0) / F32(LUT_SIZE));
+	const Vec3 LUT_OFFSET = Vec3(1.0 / (2.0 * F32(LUT_SIZE)));
 
-	color = min(color, vec3(1.0));
-	vec3 lutCoords = color * LUT_SCALE + LUT_OFFSET;
+	color = min(color, Vec3(1.0));
+	Vec3 lutCoords = color * LUT_SCALE + LUT_OFFSET;
 	return textureLod(u_lut, lutCoords, 0.0).rgb;
 }
 
 void main()
 {
-	vec2 uv = in_uv.xy;
+	Vec2 uv = in_uv.xy;
 
 #if SHARPEN_ENABLED
 	out_color = readSharpen(u_isRt, uv, 0.15, true);
@@ -72,14 +72,14 @@ void main()
 	out_color = tonemap(out_color, UNIFORM(u_exposureThreshold0));
 
 #if BLOOM_ENABLED
-	vec3 bloom = textureLod(u_ppsBloomLfRt, uv, 0.0).rgb;
+	Vec3 bloom = textureLod(u_ppsBloomLfRt, uv, 0.0).rgb;
 	out_color += bloom;
 #endif
 
 	out_color = colorGrading(out_color);
 
 #if BLUE_NOISE
-	vec3 blueNoise = textureLod(u_blueNoise, vec3(FB_SIZE / vec2(64.0) * uv, u_blueNoiseLayerPad3.x), 0.0).rgb;
+	Vec3 blueNoise = textureLod(u_blueNoise, Vec3(FB_SIZE / Vec2(64.0) * uv, u_blueNoiseLayerPad3.x), 0.0).rgb;
 	blueNoise = blueNoise * 2.0 - 1.0;
 	blueNoise = sign(blueNoise) * (1.0 - sqrt(1.0 - abs(blueNoise)));
 
@@ -88,7 +88,7 @@ void main()
 
 #if 0
 	{
-		out_color = vec3(textureLod(u_isRt, uv, 0.0).rgb);
+		out_color = Vec3(textureLod(u_isRt, uv, 0.0).rgb);
 	}
 #endif
 

+ 44 - 43
shaders/ForwardShadingCommonFrag.glsl

@@ -7,9 +7,9 @@
 #define ANKI_SHADERS_FORWARD_SHADING_COMMON_FRAG_GLSL
 
 // Common code for all fragment shaders of BS
-#include "shaders/Common.glsl"
-#include "shaders/Functions.glsl"
-#include "shaders/Clusterer.glsl"
+#include <shaders/Common.glsl>
+#include <shaders/Functions.glsl>
+#include <shaders/glsl_cpp_common/Clusterer.h>
 
 // Global resources
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D anki_msDepthRt;
@@ -19,59 +19,59 @@ layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D anki_msDepthRt;
 #define LIGHT_TEX_BINDING 1
 #define LIGHT_LIGHTS
 #define LIGHT_COMMON_UNIS
-#include "shaders/ClusterLightCommon.glsl"
+#include <shaders/ClusterLightCommon.glsl>
 
 #define anki_u_time u_time
 #define RENDERER_SIZE (u_rendererSize * 0.5)
 
-layout(location = 0) out vec4 out_color;
+layout(location = 0) out Vec4 out_color;
 
-void writeGBuffer(in vec4 color)
+void writeGBuffer(in Vec4 color)
 {
-	out_color = vec4(color.rgb, 1.0 - color.a);
+	out_color = Vec4(color.rgb, 1.0 - color.a);
 }
 
-vec4 readAnimatedTextureRgba(sampler2DArray tex, float period, vec2 uv, float time)
+Vec4 readAnimatedTextureRgba(sampler2DArray tex, F32 period, Vec2 uv, F32 time)
 {
-	float layerCount = float(textureSize(tex, 0).z);
-	float layer = mod(time * layerCount / period, layerCount);
-	return texture(tex, vec3(uv, layer));
+	F32 layerCount = F32(textureSize(tex, 0).z);
+	F32 layer = mod(time * layerCount / period, layerCount);
+	return texture(tex, Vec3(uv, layer));
 }
 
-vec3 computeLightColor(vec3 diffCol, vec3 worldPos)
+Vec3 computeLightColor(Vec3 diffCol, Vec3 worldPos)
 {
-	vec3 outColor = vec3(0.0);
+	Vec3 outColor = Vec3(0.0);
 
 	// Find the cluster and then the light counts
-	uint clusterIdx = computeClusterIndex(
+	U32 clusterIdx = computeClusterIndex(
 		u_clustererMagic, gl_FragCoord.xy / RENDERER_SIZE, worldPos, u_clusterCountX, u_clusterCountY);
 
-	uint idxOffset = u_clusters[clusterIdx];
+	U32 idxOffset = u_clusters[clusterIdx];
 
 	// Skip decals
-	uint count = u_lightIndices[idxOffset];
+	U32 count = u_lightIndices[idxOffset];
 	idxOffset += count + 1;
 
 	// Point lights
 	count = u_lightIndices[idxOffset++];
-	uint idxOffsetEnd = idxOffset + count;
+	U32 idxOffsetEnd = idxOffset + count;
 	ANKI_LOOP while(idxOffset < idxOffsetEnd)
 	{
 		PointLight light = u_pointLights[u_lightIndices[idxOffset++]];
 
-		vec3 diffC = diffuseLambert(diffCol) * light.diffuseColorTileSize.rgb;
+		Vec3 diffC = diffuseLambert(diffCol) * light.m_diffuseColorTileSize.rgb;
 
-		vec3 frag2Light = light.posRadius.xyz - worldPos;
-		float att = computeAttenuationFactor(light.posRadius.w, frag2Light);
+		Vec3 frag2Light = light.m_posRadius.xyz - worldPos;
+		F32 att = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
 
 #if LOD > 1
-		const float shadow = 1.0;
+		const F32 shadow = 1.0;
 #else
-		float shadow = 1.0;
-		if(light.diffuseColorTileSize.w >= 0.0)
+		F32 shadow = 1.0;
+		if(light.m_diffuseColorTileSize.w >= 0.0)
 		{
 			shadow = computeShadowFactorOmni(
-				frag2Light, light.radiusPad1.x, light.atlasTiles, light.diffuseColorTileSize.w, u_shadowTex);
+				frag2Light, light.m_radiusPad1.x, light.m_atlasTiles, light.m_diffuseColorTileSize.w, u_shadowTex);
 		}
 #endif
 
@@ -85,23 +85,24 @@ vec3 computeLightColor(vec3 diffCol, vec3 worldPos)
 	{
 		SpotLight light = u_spotLights[u_lightIndices[idxOffset++]];
 
-		vec3 diffC = diffuseLambert(diffCol) * light.diffuseColorShadowmapId.rgb;
+		Vec3 diffC = diffuseLambert(diffCol) * light.m_diffuseColorShadowmapId.rgb;
 
-		vec3 frag2Light = light.posRadius.xyz - worldPos;
-		float att = computeAttenuationFactor(light.posRadius.w, frag2Light);
+		Vec3 frag2Light = light.m_posRadius.xyz - worldPos;
+		F32 att = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
 
-		vec3 l = normalize(frag2Light);
+		Vec3 l = normalize(frag2Light);
 
-		float spot = computeSpotFactor(l, light.outerCosInnerCos.x, light.outerCosInnerCos.y, light.lightDirRadius.xyz);
+		F32 spot =
+			computeSpotFactor(l, light.m_outerCosInnerCos.x, light.m_outerCosInnerCos.y, light.m_lightDirRadius.xyz);
 
 #if LOD > 1
-		const float shadow = 1.0;
+		const F32 shadow = 1.0;
 #else
-		float shadow = 1.0;
-		float shadowmapLayerIdx = light.diffuseColorShadowmapId.w;
+		F32 shadow = 1.0;
+		F32 shadowmapLayerIdx = light.m_diffuseColorShadowmapId.w;
 		if(shadowmapLayerIdx >= 0.0)
 		{
-			shadow = computeShadowFactorSpot(light.texProjectionMat, worldPos, light.lightDirRadius.w, u_shadowTex);
+			shadow = computeShadowFactorSpot(light.m_texProjectionMat, worldPos, light.m_lightDirRadius.w, u_shadowTex);
 		}
 #endif
 
@@ -111,27 +112,27 @@ vec3 computeLightColor(vec3 diffCol, vec3 worldPos)
 	return outColor;
 }
 
-void particleAlpha(vec4 color, vec4 scaleColor, vec4 biasColor)
+void particleAlpha(Vec4 color, Vec4 scaleColor, Vec4 biasColor)
 {
 	writeGBuffer(color * scaleColor + biasColor);
 }
 
-void fog(vec3 color, float fogAlphaScale, float fogDistanceOfMaxThikness, float zVSpace)
+void fog(Vec3 color, F32 fogAlphaScale, F32 fogDistanceOfMaxThikness, F32 zVSpace)
 {
-	const vec2 screenSize = 1.0 / RENDERER_SIZE;
+	const Vec2 screenSize = 1.0 / RENDERER_SIZE;
 
-	vec2 texCoords = gl_FragCoord.xy * screenSize;
-	float depth = texture(anki_msDepthRt, texCoords).r;
-	float zFeatherFactor;
+	Vec2 texCoords = gl_FragCoord.xy * screenSize;
+	F32 depth = texture(anki_msDepthRt, texCoords).r;
+	F32 zFeatherFactor;
 
-	vec4 fragPosVspace4 = u_invProjMat * vec4(vec3(UV_TO_NDC(texCoords), depth), 1.0);
-	float sceneZVspace = fragPosVspace4.z / fragPosVspace4.w;
+	Vec4 fragPosVspace4 = u_invProjMat * Vec4(Vec3(UV_TO_NDC(texCoords), depth), 1.0);
+	F32 sceneZVspace = fragPosVspace4.z / fragPosVspace4.w;
 
-	float diff = max(0.0, zVSpace - sceneZVspace);
+	F32 diff = max(0.0, zVSpace - sceneZVspace);
 
 	zFeatherFactor = min(1.0, diff / fogDistanceOfMaxThikness);
 
-	writeGBuffer(vec4(color, zFeatherFactor * fogAlphaScale));
+	writeGBuffer(Vec4(color, zFeatherFactor * fogAlphaScale));
 }
 
 #endif

+ 4 - 4
shaders/ForwardShadingCommonVert.glsl

@@ -7,7 +7,7 @@
 #define ANKI_SHADERS_FORWARD_SHADING_COMMON_VERT_GLSL
 
 // Common code for all vertex shaders of FS
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 // Global resources
 #define LIGHT_SET 0
@@ -15,17 +15,17 @@
 #define LIGHT_TEX_BINDING 1
 #define LIGHT_UBO_BINDING 0
 #define LIGHT_MINIMAL
-#include "shaders/ClusterLightCommon.glsl"
+#include <shaders/ClusterLightCommon.glsl>
 #undef LIGHT_SET
 #undef LIGHT_SS_BINDING
 #undef LIGHT_TEX_BINDING
 
 // In/out
-layout(location = POSITION_LOCATION) in vec3 in_position;
+layout(location = POSITION_LOCATION) in Vec3 in_position;
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
 #endif

+ 11 - 11
programs/ForwardShadingFog.ankiprog → shaders/ForwardShadingFog.ankiprog

@@ -10,34 +10,34 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<inputs>
-				<input name="mvp" type="mat4"/>
-				<input name="modelView" type="mat4"/>
+				<input name="mvp" type="Mat4"/>
+				<input name="modelView" type="Mat4"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/ForwardShadingCommonVert.glsl"
+#include <shaders/ForwardShadingCommonVert.glsl>
 
-layout(location = 0) out float out_zVSpace;
+layout(location = 0) out F32 out_zVSpace;
 
 void main() 
 {
-	gl_Position = mvp * vec4(in_position, 1.0);
-	out_zVSpace = (modelView * vec4(in_position, 1.0)).z;
+	gl_Position = mvp * Vec4(in_position, 1.0);
+	out_zVSpace = (modelView * Vec4(in_position, 1.0)).z;
 }
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="fogColor" type="vec3" const="1"/>
-				<input name="fogAlphaScale" type="float" const="1"/>
-				<input name="fogDistanceOfMaxThikness" type="float" const="1"/>
+				<input name="fogColor" type="Vec3" const="1"/>
+				<input name="fogAlphaScale" type="F32" const="1"/>
+				<input name="fogDistanceOfMaxThikness" type="F32" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/ForwardShadingCommonFrag.glsl"
+#include <shaders/ForwardShadingCommonFrag.glsl>
 
-layout(location = 0) in float in_zVSpace;
+layout(location = 0) in F32 in_zVSpace;
 
 void main() 
 {

+ 21 - 21
programs/ForwardShadingParticles.ankiprog → shaders/ForwardShadingParticles.ankiprog

@@ -15,26 +15,26 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<inputs>
-				<input name="mvp" type="mat4"/>
-				<input name="cameraRotMat" type="mat3"/>
+				<input name="mvp" type="Mat4"/>
+				<input name="cameraRotMat" type="Mat3"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/ForwardShadingCommonVert.glsl"
+#include <shaders/ForwardShadingCommonVert.glsl>
 
-layout(location = SCALE_LOCATION) in float in_scale;
-layout(location = ALPHA_LOCATION) in float in_alpha;
+layout(location = SCALE_LOCATION) in F32 in_scale;
+layout(location = ALPHA_LOCATION) in F32 in_alpha;
 
-layout(location = 0) flat out float out_alpha;
-layout(location = 1) out vec2 out_uv;
-layout(location = 2) out vec3 out_worldPos;
+layout(location = 0) flat out F32 out_alpha;
+layout(location = 1) out Vec2 out_uv;
+layout(location = 2) out Vec3 out_worldPos;
 
 void main() 
 {
-	out_uv = vec2(gl_VertexID & 1, gl_VertexID >> 1);
+	out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1);
 
-	out_worldPos = cameraRotMat * vec3((out_uv - 0.5) * in_scale, 0.0) + in_position;
-	gl_Position = mvp * vec4(out_worldPos, 1.0);
+	out_worldPos = cameraRotMat * Vec3((out_uv - 0.5) * in_scale, 0.0) + in_position;
+	gl_Position = mvp * Vec4(out_worldPos, 1.0);
 
 	out_alpha = in_alpha;
 }
@@ -54,35 +54,35 @@ void main()
 						<mutator name="ANIMATED_TEXTURE" values="1"/>
 					</mutators>
 				</input>
-				<input name="animationPeriod" type="float" const="1">
+				<input name="animationPeriod" type="F32" const="1">
 					<mutators>
 						<mutator name="ANIMATED_TEXTURE" values="1"/>
 					</mutators>
 				</input>
-				<input name="colorScale" type="vec4" const="1"/>
-				<input name="colorBias" type="vec4" const="1"/>
+				<input name="colorScale" type="Vec4" const="1"/>
+				<input name="colorBias" type="Vec4" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/ForwardShadingCommonFrag.glsl"
+#include <shaders/ForwardShadingCommonFrag.glsl>
 
-layout(location = 0) flat in float in_alpha;
-layout(location = 1) in vec2 in_uv;
-layout(location = 2) in vec3 in_worldPos;
+layout(location = 0) flat in F32 in_alpha;
+layout(location = 1) in Vec2 in_uv;
+layout(location = 2) in Vec3 in_worldPos;
 
 void main() 
 {
 #if ANIMATED_TEXTURE == 1
-	vec4 texCol = readAnimatedTextureRgba(diffuseMapArr, animationPeriod, in_uv, anki_u_time);
+	Vec4 texCol = readAnimatedTextureRgba(diffuseMapArr, animationPeriod, in_uv, anki_u_time);
 #else
-	vec4 texCol = texture(diffuseMap, in_uv);
+	Vec4 texCol = texture(diffuseMap, in_uv);
 #endif
 
 #if LIGHT
 	texCol.rgb = computeLightColor(texCol.rgb, in_worldPos);
 #endif
 	
-	vec4 colScale = colorScale;
+	Vec4 colScale = colorScale;
 	colScale.a *= in_alpha;
 	particleAlpha(texCol, colScale, colorBias);
 }

+ 11 - 11
programs/ForwardShadingUpscale.ankiprog → shaders/ForwardShadingUpscale.ankiprog

@@ -8,26 +8,26 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="SRC_SIZE" type="vec2" const="1"/>
-				<input name="FB_SIZE" type="vec2" const="1"/>
-				<input name="NOISE_TEX_SIZE" type="uint" const="1"/>
+				<input name="SRC_SIZE" type="Vec2" const="1"/>
+				<input name="FB_SIZE" type="Vec2" const="1"/>
+				<input name="NOISE_TEX_SIZE" type="U32" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Common.glsl"
-#include "shaders/Functions.glsl"
+#include <shaders/Common.glsl>
+#include <shaders/Functions.glsl>
 
 #define BLUE_NOISE 1
 
-layout(location = 0) in vec2 in_uv;
+layout(location = 0) in Vec2 in_uv;
 
-layout(location = 0) out vec4 out_color;
+layout(location = 0) out Vec4 out_color;
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthFullTex;
 layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_depthHalfTex;
@@ -38,16 +38,16 @@ layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2DArray u_noiseTex;
 
 layout(ANKI_UBO_BINDING(0, 0)) uniform u0_
 {
-	vec4 u_linearizeCfPad2;
+	Vec4 u_linearizeCfPad2;
 };
 
 void main()
 {
 	out_color =
-		bilateralUpsample(u_depthFullTex, u_depthHalfTex, u_fsRt, 1.0 / vec2(SRC_SIZE), in_uv, u_linearizeCfPad2.xy);
+		bilateralUpsample(u_depthFullTex, u_depthHalfTex, u_fsRt, 1.0 / Vec2(SRC_SIZE), in_uv, u_linearizeCfPad2.xy);
 
 #if BLUE_NOISE
-	vec3 blueNoise = texture(u_noiseTex, vec3(FB_SIZE / vec2(NOISE_TEX_SIZE) * in_uv, 0.0), 0.0).rgb;
+	Vec3 blueNoise = texture(u_noiseTex, Vec3(FB_SIZE / Vec2(NOISE_TEX_SIZE) * in_uv, 0.0), 0.0).rgb;
 	blueNoise = blueNoise * 2.0 - 1.0;
 	blueNoise = sign(blueNoise) * (1.0 - sqrt(1.0 - abs(blueNoise)));
 	out_color.rgb += blueNoise / 32.0;

+ 11 - 11
programs/ForwardShadingVolumetricUpscale.ankiprog → shaders/ForwardShadingVolumetricUpscale.ankiprog

@@ -8,24 +8,24 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="SRC_SIZE" type="vec2" const="1"/>
-				<input name="FB_SIZE" type="vec2" const="1"/>
-				<input name="NOISE_TEX_SIZE" type="uint" const="1"/>
+				<input name="SRC_SIZE" type="Vec2" const="1"/>
+				<input name="FB_SIZE" type="Vec2" const="1"/>
+				<input name="NOISE_TEX_SIZE" type="U32" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Functions.glsl"
+#include <shaders/Functions.glsl>
 
 #define BLUE_NOISE 0
 
-layout(location = 0) in vec2 in_uv;
-layout(location = 0) out vec4 out_color;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 0) out Vec4 out_color;
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthFullTex;
 layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_depthHalfTex;
@@ -36,22 +36,22 @@ layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2DArray u_noiseTex;
 
 layout(ANKI_UBO_BINDING(0, 0)) uniform u0_
 {
-	vec4 u_linearizeCfPad2;
+	Vec4 u_linearizeCfPad2;
 };
 
 void main()
 {
-	vec3 col =
+	Vec3 col =
 		bilateralUpsample(u_depthFullTex, u_depthHalfTex, u_colorTex, 1.0 / SRC_SIZE, in_uv, u_linearizeCfPad2.xy).rgb;
 
 #if BLUE_NOISE
-	vec3 blueNoise = texture(u_noiseTex, vec3(FB_SIZE / vec2(NOISE_TEX_SIZE) * in_uv, 0.0), 0.0).rgb;
+	Vec3 blueNoise = texture(u_noiseTex, Vec3(FB_SIZE / Vec2(NOISE_TEX_SIZE) * in_uv, 0.0), 0.0).rgb;
 	blueNoise = blueNoise * 2.0 - 1.0;
 	blueNoise = sign(blueNoise) * (1.0 - sqrt(1.0 - abs(blueNoise)));
 	col += blueNoise / 16.0;
 #endif
 
-	out_color = vec4(col, 0.0);
+	out_color = Vec4(col, 0.0);
 }
 			]]></source>
 		</shader>

+ 109 - 109
shaders/Functions.glsl

@@ -6,13 +6,13 @@
 #ifndef ANKI_SHADERS_FUNCTIONS_GLSL
 #define ANKI_SHADERS_FUNCTIONS_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #if defined(ANKI_FRAGMENT_SHADER)
-vec3 dither(in vec3 col, in float C)
+Vec3 dither(in Vec3 col, in F32 C)
 {
-	vec3 vDither = vec3(dot(vec2(171.0, 231.0), gl_FragCoord.xy));
-	vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0));
+	Vec3 vDither = Vec3(dot(Vec2(171.0, 231.0), gl_FragCoord.xy));
+	vDither.rgb = fract(vDither.rgb / Vec3(103.0, 71.0, 97.0));
 
 	col = col * (255.0 / C) + vDither.rgb;
 	col = floor(col) / 255.0;
@@ -21,9 +21,9 @@ vec3 dither(in vec3 col, in float C)
 	return col;
 }
 
-float dither(in float col, in float C)
+F32 dither(in F32 col, in F32 C)
 {
-	float vDither = dot(vec2(171.0, 231.0), gl_FragCoord.xy);
+	F32 vDither = dot(Vec2(171.0, 231.0), gl_FragCoord.xy);
 	vDither = fract(vDither / 103.0);
 
 	col = col * (255.0 / C) + vDither;
@@ -35,21 +35,21 @@ float dither(in float col, in float C)
 #endif
 
 // Convert to linear depth
-float linearizeDepth(in float depth, in float zNear, in float zFar)
+F32 linearizeDepth(in F32 depth, in F32 zNear, in F32 zFar)
 {
 	return zNear / ((zNear - zFar) + zFar / depth);
 }
 
 // This is the optimal linearizeDepth where a=(n-f)/n and b=f/n
-float linearizeDepthOptimal(in float depth, in float a, in float b)
+F32 linearizeDepthOptimal(in F32 depth, in F32 a, in F32 b)
 {
 	return 1.0 / (a + b / depth);
 }
 
 // Project a vector by knowing only the non zero values of a perspective matrix
-vec4 projectPerspective(in vec4 vec, in float m00, in float m11, in float m22, in float m23)
+Vec4 projectPerspective(in Vec4 vec, in F32 m00, in F32 m11, in F32 m22, in F32 m23)
 {
-	vec4 o;
+	Vec4 o;
 	o.x = vec.x * m00;
 	o.y = vec.y * m11;
 	o.z = vec.z * m22 + vec.w * m23;
@@ -58,14 +58,14 @@ vec4 projectPerspective(in vec4 vec, in float m00, in float m11, in float m22, i
 }
 
 // Stolen from shadertoy.com/view/4tyGDD
-vec4 textureCatmullRom4Samples(sampler2D tex, vec2 uv, vec2 texSize)
+Vec4 textureCatmullRom4Samples(sampler2D tex, Vec2 uv, Vec2 texSize)
 {
-	vec2 halff = 2.0 * fract(0.5 * uv * texSize - 0.25) - 1.0;
-	vec2 f = fract(halff);
-	vec2 sum0 = (2.0 * f - 3.5) * f + 0.5;
-	vec2 sum1 = (2.0 * f - 2.5) * f - 0.5;
-	vec4 w = vec4(f * sum0 + 1.0, f * sum1);
-	vec4 pos = vec4((((-2.0 * f + 3.0) * f + 0.5) * f - 1.5) * f / (w.xy * texSize) + uv,
+	Vec2 halff = 2.0 * fract(0.5 * uv * texSize - 0.25) - 1.0;
+	Vec2 f = fract(halff);
+	Vec2 sum0 = (2.0 * f - 3.5) * f + 0.5;
+	Vec2 sum1 = (2.0 * f - 2.5) * f - 0.5;
+	Vec4 w = Vec4(f * sum0 + 1.0, f * sum1);
+	Vec4 pos = Vec4((((-2.0 * f + 3.0) * f + 0.5) * f - 1.5) * f / (w.xy * texSize) + uv,
 		(((-2.0 * f + 5.0) * f - 2.5) * f - 0.5) / (sum1 * texSize) + uv);
 	w.xz *= halff.x * halff.y > 0.0 ? 1.0 : -1.0;
 
@@ -73,19 +73,19 @@ vec4 textureCatmullRom4Samples(sampler2D tex, vec2 uv, vec2 texSize)
 		   + (texture(tex, pos.xw) * w.x + texture(tex, pos.zw) * w.z) * w.w;
 }
 
-float rand(vec2 n)
+F32 rand(Vec2 n)
 {
-	return 0.5 + 0.5 * fract(sin(dot(n, vec2(12.9898, 78.233))) * 43758.5453);
+	return 0.5 + 0.5 * fract(sin(dot(n, Vec2(12.9898, 78.233))) * 43758.5453);
 }
 
-vec3 nearestDepthUpscale(vec2 uv, sampler2D depthFull, sampler2D depthHalf, sampler2D colorTex, float depthThreshold)
+Vec3 nearestDepthUpscale(Vec2 uv, sampler2D depthFull, sampler2D depthHalf, sampler2D colorTex, F32 depthThreshold)
 {
-	float fullDepth = texture(depthFull, uv).r;
-	vec4 halfDepths = textureGather(depthHalf, uv, 0);
-	vec4 diffs = abs(vec4(fullDepth) - halfDepths);
-	vec3 color;
+	F32 fullDepth = texture(depthFull, uv).r;
+	Vec4 halfDepths = textureGather(depthHalf, uv, 0);
+	Vec4 diffs = abs(Vec4(fullDepth) - halfDepths);
+	Vec3 color;
 
-	if(all(lessThan(diffs, vec4(depthThreshold))))
+	if(all(lessThan(diffs, Vec4(depthThreshold))))
 	{
 		// No major discontinuites, sample with bilinear
 		color = texture(colorTex, uv).rgb;
@@ -93,12 +93,12 @@ vec3 nearestDepthUpscale(vec2 uv, sampler2D depthFull, sampler2D depthHalf, samp
 	else
 	{
 		// Some discontinuites, need to use the newUv
-		vec4 r = textureGather(colorTex, uv, 0);
-		vec4 g = textureGather(colorTex, uv, 1);
-		vec4 b = textureGather(colorTex, uv, 2);
+		Vec4 r = textureGather(colorTex, uv, 0);
+		Vec4 g = textureGather(colorTex, uv, 1);
+		Vec4 b = textureGather(colorTex, uv, 2);
 
-		float minDiff = diffs.x;
-		uint comp = 0;
+		F32 minDiff = diffs.x;
+		U32 comp = 0;
 
 		if(diffs.y < minDiff)
 		{
@@ -117,184 +117,184 @@ vec3 nearestDepthUpscale(vec2 uv, sampler2D depthFull, sampler2D depthHalf, samp
 			comp = 3;
 		}
 
-		color = vec3(r[comp], g[comp], b[comp]);
+		color = Vec3(r[comp], g[comp], b[comp]);
 	}
 
 	return color;
 }
 
-float _calcDepthWeight(sampler2D depthLow, vec2 uv, float ref, vec2 linearDepthCf)
+F32 _calcDepthWeight(sampler2D depthLow, Vec2 uv, F32 ref, Vec2 linearDepthCf)
 {
-	float d = texture(depthLow, uv).r;
-	float linearD = linearizeDepthOptimal(d, linearDepthCf.x, linearDepthCf.y);
+	F32 d = texture(depthLow, uv).r;
+	F32 linearD = linearizeDepthOptimal(d, linearDepthCf.x, linearDepthCf.y);
 	return 1.0 / (EPSILON + abs(ref - linearD));
 }
 
-vec4 _sampleAndWeight(sampler2D depthLow,
+Vec4 _sampleAndWeight(sampler2D depthLow,
 	sampler2D colorLow,
-	vec2 lowInvSize,
-	vec2 uv,
-	vec2 offset,
-	float ref,
-	float weight,
-	vec2 linearDepthCf,
-	inout float normalize)
+	Vec2 lowInvSize,
+	Vec2 uv,
+	Vec2 offset,
+	F32 ref,
+	F32 weight,
+	Vec2 linearDepthCf,
+	inout F32 normalize)
 {
 	uv += offset * lowInvSize;
-	float dw = _calcDepthWeight(depthLow, uv, ref, linearDepthCf);
-	vec4 v = texture(colorLow, uv);
+	F32 dw = _calcDepthWeight(depthLow, uv, ref, linearDepthCf);
+	Vec4 v = texture(colorLow, uv);
 	normalize += weight * dw;
 	return v * dw * weight;
 }
 
-vec4 bilateralUpsample(
-	sampler2D depthHigh, sampler2D depthLow, sampler2D colorLow, vec2 lowInvSize, vec2 uv, vec2 linearDepthCf)
+Vec4 bilateralUpsample(
+	sampler2D depthHigh, sampler2D depthLow, sampler2D colorLow, Vec2 lowInvSize, Vec2 uv, Vec2 linearDepthCf)
 {
-	const vec3 WEIGHTS = vec3(0.25, 0.125, 0.0625);
-	float depthRef = linearizeDepthOptimal(texture(depthHigh, uv).r, linearDepthCf.x, linearDepthCf.y);
-	float normalize = 0.0;
+	const Vec3 WEIGHTS = Vec3(0.25, 0.125, 0.0625);
+	F32 depthRef = linearizeDepthOptimal(texture(depthHigh, uv).r, linearDepthCf.x, linearDepthCf.y);
+	F32 normalize = 0.0;
 
-	vec4 sum = _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(0.0, 0.0), depthRef, WEIGHTS.x, linearDepthCf, normalize);
+	Vec4 sum = _sampleAndWeight(
+		depthLow, colorLow, lowInvSize, uv, Vec2(0.0, 0.0), depthRef, WEIGHTS.x, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(-1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(-1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(0.0, -1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(0.0, -1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(0.0, 1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(0.0, 1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(-1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(-1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
 	sum += _sampleAndWeight(
-		depthLow, colorLow, lowInvSize, uv, vec2(-1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
+		depthLow, colorLow, lowInvSize, uv, Vec2(-1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
 
 	return sum / normalize;
 }
 
-vec3 getCubemapDirection(vec2 norm, uint faceIdx)
+Vec3 getCubemapDirection(Vec2 norm, U32 faceIdx)
 {
-	vec3 zDir = vec3((faceIdx <= 1u) ? 1 : 0, (faceIdx & 2u) >> 1u, (faceIdx & 4u) >> 2u);
+	Vec3 zDir = Vec3((faceIdx <= 1u) ? 1 : 0, (faceIdx & 2u) >> 1u, (faceIdx & 4u) >> 2u);
 	zDir *= (((faceIdx & 1u) == 1u) ? -1.0 : 1.0);
-	vec3 yDir = (faceIdx == 2u) ? vec3(0.0, 0.0, 1.0) : (faceIdx == 3u) ? vec3(0.0, 0.0, -1.0) : vec3(0.0, -1.0, 0.0);
-	vec3 xDir = cross(zDir, yDir);
+	Vec3 yDir = (faceIdx == 2u) ? Vec3(0.0, 0.0, 1.0) : (faceIdx == 3u) ? Vec3(0.0, 0.0, -1.0) : Vec3(0.0, -1.0, 0.0);
+	Vec3 xDir = cross(zDir, yDir);
 	return normalize(norm.x * xDir + norm.y * yDir + zDir);
 }
 
 // Convert 3D cubemap coordinates to 2D plus face index. v doesn't need to be normalized.
-vec2 convertCubeUvs(vec3 v, out float faceIndex)
+Vec2 convertCubeUvs(Vec3 v, out F32 faceIndex)
 {
-	vec3 absV = abs(v);
-	float mag;
-	vec2 uv;
+	Vec3 absV = abs(v);
+	F32 mag;
+	Vec2 uv;
 
 	if(all(greaterThanEqual(absV.zz, absV.xy)))
 	{
 		faceIndex = (v.z < 0.0) ? 5.0 : 4.0;
-		uv = vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
+		uv = Vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
 		mag = absV.z;
 	}
 	else if(absV.y >= absV.x)
 	{
 		faceIndex = (v.y < 0.0) ? 3.0 : 2.0;
-		uv = vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
+		uv = Vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
 		mag = absV.y;
 	}
 	else
 	{
 		faceIndex = (v.x < 0.0) ? 1.0 : 0.0;
-		uv = vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
+		uv = Vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
 		mag = absV.x;
 	}
 
 	return 0.5 / mag * uv + 0.5;
 }
 
-// Same as convertCubeUvs but it returns the faceIndex as unsigned int.
-vec2 convertCubeUvsu(vec3 v, out uint faceIndex)
+// Same as convertCubeUvs but it returns the faceIndex as unsigned I32.
+Vec2 convertCubeUvsu(Vec3 v, out U32 faceIndex)
 {
-	vec3 absV = abs(v);
-	float mag;
-	vec2 uv;
+	Vec3 absV = abs(v);
+	F32 mag;
+	Vec2 uv;
 
 	if(all(greaterThanEqual(absV.zz, absV.xy)))
 	{
 		faceIndex = (v.z < 0.0) ? 5u : 4u;
-		uv = vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
+		uv = Vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
 		mag = absV.z;
 	}
 	else if(absV.y >= absV.x)
 	{
 		faceIndex = (v.y < 0.0) ? 3u : 2u;
-		uv = vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
+		uv = Vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
 		mag = absV.y;
 	}
 	else
 	{
 		faceIndex = (v.x < 0.0) ? 1u : 0u;
-		uv = vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
+		uv = Vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
 		mag = absV.x;
 	}
 
 	return 0.5 / mag * uv + 0.5;
 }
 
-vec3 grayScale(vec3 col)
+Vec3 grayScale(Vec3 col)
 {
-	float grey = (col.r + col.g + col.b) * (1.0 / 3.0);
-	return vec3(grey);
+	F32 grey = (col.r + col.g + col.b) * (1.0 / 3.0);
+	return Vec3(grey);
 }
 
-vec3 saturateColor(vec3 col, float factor)
+Vec3 saturateColor(Vec3 col, F32 factor)
 {
-	const vec3 LUM_COEFF = vec3(0.2125, 0.7154, 0.0721);
-	vec3 intensity = vec3(dot(col, LUM_COEFF));
+	const Vec3 LUM_COEFF = Vec3(0.2125, 0.7154, 0.0721);
+	Vec3 intensity = Vec3(dot(col, LUM_COEFF));
 	return mix(intensity, col, factor);
 }
 
-vec3 gammaCorrection(vec3 gamma, vec3 col)
+Vec3 gammaCorrection(Vec3 gamma, Vec3 col)
 {
 	return pow(col, 1.0 / gamma);
 }
 
 // Can use 0.15 for sharpenFactor
-vec3 readSharpen(sampler2D tex, vec2 uv, float sharpenFactor, bool detailed)
+Vec3 readSharpen(sampler2D tex, Vec2 uv, F32 sharpenFactor, bool detailed)
 {
-	vec3 col = textureLod(tex, uv, 0.0).rgb;
+	Vec3 col = textureLod(tex, uv, 0.0).rgb;
 
-	vec3 col2 = textureLodOffset(tex, uv, 0.0, ivec2(1, 1)).rgb;
-	col2 += textureLodOffset(tex, uv, 0.0, ivec2(-1, -1)).rgb;
-	col2 += textureLodOffset(tex, uv, 0.0, ivec2(1, -1)).rgb;
-	col2 += textureLodOffset(tex, uv, 0.0, ivec2(-1, 1)).rgb;
+	Vec3 col2 = textureLodOffset(tex, uv, 0.0, IVec2(1, 1)).rgb;
+	col2 += textureLodOffset(tex, uv, 0.0, IVec2(-1, -1)).rgb;
+	col2 += textureLodOffset(tex, uv, 0.0, IVec2(1, -1)).rgb;
+	col2 += textureLodOffset(tex, uv, 0.0, IVec2(-1, 1)).rgb;
 
-	float f = 4.0;
+	F32 f = 4.0;
 	if(detailed)
 	{
-		col2 += textureLodOffset(tex, uv, 0.0, ivec2(0, 1)).rgb;
-		col2 += textureLodOffset(tex, uv, 0.0, ivec2(1, 0)).rgb;
-		col2 += textureLodOffset(tex, uv, 0.0, ivec2(-1, 0)).rgb;
-		col2 += textureLodOffset(tex, uv, 0.0, ivec2(0, -1)).rgb;
+		col2 += textureLodOffset(tex, uv, 0.0, IVec2(0, 1)).rgb;
+		col2 += textureLodOffset(tex, uv, 0.0, IVec2(1, 0)).rgb;
+		col2 += textureLodOffset(tex, uv, 0.0, IVec2(-1, 0)).rgb;
+		col2 += textureLodOffset(tex, uv, 0.0, IVec2(0, -1)).rgb;
 
 		f = 8.0;
 	}
 
 	col = col * (f * sharpenFactor + 1.0) - sharpenFactor * col2;
-	return max(vec3(0.0), col);
+	return max(Vec3(0.0), col);
 }
 
-vec3 readErosion(sampler2D tex, vec2 uv)
+Vec3 readErosion(sampler2D tex, Vec2 uv)
 {
-	vec3 minValue = textureLod(tex, uv, 0.0).rgb;
+	Vec3 minValue = textureLod(tex, uv, 0.0).rgb;
 
 #define ANKI_EROSION(x, y) \
-	col2 = textureLodOffset(tex, uv, 0.0, ivec2(x, y)).rgb; \
+	col2 = textureLodOffset(tex, uv, 0.0, IVec2(x, y)).rgb; \
 	minValue = min(col2, minValue);
 
-	vec3 col2;
+	Vec3 col2;
 	ANKI_EROSION(1, 1);
 	ANKI_EROSION(-1, -1);
 	ANKI_EROSION(1, -1);
@@ -310,30 +310,30 @@ vec3 readErosion(sampler2D tex, vec2 uv)
 }
 
 // 5 color heatmap from a factor.
-vec3 heatmap(float factor)
+Vec3 heatmap(F32 factor)
 {
-	float intPart;
-	float fractional = modf(factor * 4.0, intPart);
+	F32 intPart;
+	F32 fractional = modf(factor * 4.0, intPart);
 
 	if(intPart < 1.0)
 	{
-		return mix(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 1.0), fractional);
+		return mix(Vec3(0.0, 0.0, 0.0), Vec3(0.0, 0.0, 1.0), fractional);
 	}
 	else if(intPart < 2.0)
 	{
-		return mix(vec3(0.0, 0.0, 1.0), vec3(0.0, 1.0, 0.0), fractional);
+		return mix(Vec3(0.0, 0.0, 1.0), Vec3(0.0, 1.0, 0.0), fractional);
 	}
 	else if(intPart < 3.0)
 	{
-		return mix(vec3(0.0, 1.0, 0.0), vec3(1.0, 1.0, 0.0), fractional);
+		return mix(Vec3(0.0, 1.0, 0.0), Vec3(1.0, 1.0, 0.0), fractional);
 	}
 	else
 	{
-		return mix(vec3(1.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), fractional);
+		return mix(Vec3(1.0, 1.0, 0.0), Vec3(1.0, 0.0, 0.0), fractional);
 	}
 }
 
-bool incorrectColor(vec3 c)
+bool incorrectColor(Vec3 c)
 {
 	return isnan(c.x) || isnan(c.y) || isnan(c.z) || isinf(c.x) || isinf(c.y) || isinf(c.z);
 }

+ 62 - 62
shaders/GBufferCommonFrag.glsl

@@ -6,31 +6,31 @@
 #ifndef ANKI_SHADERS_GBUFFER_COMMON_FRAG_GLSL
 #define ANKI_SHADERS_GBUFFER_COMMON_FRAG_GLSL
 
-#include "shaders/Pack.glsl"
-#include "shaders/Common.glsl"
+#include <shaders/Pack.glsl>
+#include <shaders/Common.glsl>
 
 //
 // Input
 //
 #if PASS == PASS_GB_FS
-layout(location = 0) in highp vec2 in_uv;
-layout(location = 1) in mediump vec3 in_normal;
-layout(location = 2) in mediump vec4 in_tangent;
+layout(location = 0) in highp Vec2 in_uv;
+layout(location = 1) in mediump Vec3 in_normal;
+layout(location = 2) in mediump Vec4 in_tangent;
 #	if CALC_BITANGENT_IN_VERT
-layout(location = 3) in mediump vec3 in_bitangent;
+layout(location = 3) in mediump Vec3 in_bitangent;
 #	endif
-layout(location = 4) in mediump float in_distFromTheCamera; // Parallax
-layout(location = 5) in mediump vec3 in_eyeTangentSpace; // Parallax
-layout(location = 6) in mediump vec3 in_normalTangentSpace; // Parallax
+layout(location = 4) in mediump F32 in_distFromTheCamera; // Parallax
+layout(location = 5) in mediump Vec3 in_eyeTangentSpace; // Parallax
+layout(location = 6) in mediump Vec3 in_normalTangentSpace; // Parallax
 #endif // PASS == PASS_GB_FS
 
 //
 // Output
 //
 #if PASS == PASS_GB_FS || PASS == PASS_EZ
-layout(location = 0) out vec4 out_msRt0;
-layout(location = 1) out vec4 out_msRt1;
-layout(location = 2) out vec4 out_msRt2;
+layout(location = 0) out Vec4 out_msRt0;
+layout(location = 1) out Vec4 out_msRt1;
+layout(location = 2) out Vec4 out_msRt2;
 #endif
 
 //
@@ -38,28 +38,28 @@ layout(location = 2) out vec4 out_msRt2;
 //
 #if PASS == PASS_GB_FS
 // Do normal mapping
-vec3 readNormalFromTexture(sampler2D map, highp vec2 texCoords)
+Vec3 readNormalFromTexture(sampler2D map, highp Vec2 texCoords)
 {
 	// First read the texture
-	vec3 nAtTangentspace = normalize((texture(map, texCoords).rgb - 0.5) * 2.0);
+	Vec3 nAtTangentspace = normalize((texture(map, texCoords).rgb - 0.5) * 2.0);
 
-	vec3 n = normalize(in_normal);
-	vec3 t = normalize(in_tangent.xyz);
+	Vec3 n = normalize(in_normal);
+	Vec3 t = normalize(in_tangent.xyz);
 #	if CALC_BITANGENT_IN_VERT
-	vec3 b = normalize(in_bitangent.xyz);
+	Vec3 b = normalize(in_bitangent.xyz);
 #	else
-	vec3 b = cross(n, t) * in_tangent.w;
+	Vec3 b = cross(n, t) * in_tangent.w;
 #	endif
 
-	mat3 tbnMat = mat3(t, b, n);
+	Mat3 tbnMat = Mat3(t, b, n);
 
 	return tbnMat * nAtTangentspace;
 }
 
 // Using a 4-channel texture and a tolerance discard the fragment if the texture's alpha is less than the tolerance
-vec3 readTextureRgbAlphaTesting(sampler2D map, in highp vec2 texCoords, float tolerance)
+Vec3 readTextureRgbAlphaTesting(sampler2D map, in highp Vec2 texCoords, F32 tolerance)
 {
-	vec4 col = vec4(texture(map, texCoords));
+	Vec4 col = Vec4(texture(map, texCoords));
 	if(col.a < tolerance)
 	{
 		discard;
@@ -68,53 +68,53 @@ vec3 readTextureRgbAlphaTesting(sampler2D map, in highp vec2 texCoords, float to
 	return col.rgb;
 }
 
-vec2 computeTextureCoordParallax(in sampler2D heightMap, in vec2 uv, in float heightMapScale)
+Vec2 computeTextureCoordParallax(in sampler2D heightMap, in Vec2 uv, in F32 heightMapScale)
 {
-	const uint MAX_SAMPLES = 25;
-	const uint MIN_SAMPLES = 1;
-	const float MAX_EFFECTIVE_DISTANCE = 32.0;
+	const U32 MAX_SAMPLES = 25;
+	const U32 MIN_SAMPLES = 1;
+	const F32 MAX_EFFECTIVE_DISTANCE = 32.0;
 
 	// Get that because we are sampling inside a loop
-	vec2 dPdx = dFdx(uv);
-	vec2 dPdy = dFdy(uv);
+	Vec2 dPdx = dFdx(uv);
+	Vec2 dPdy = dFdy(uv);
 
-	vec3 eyeTangentSpace = in_eyeTangentSpace;
-	vec3 normTangentSpace = in_normalTangentSpace;
+	Vec3 eyeTangentSpace = in_eyeTangentSpace;
+	Vec3 normTangentSpace = in_normalTangentSpace;
 
-	float parallaxLimit = -length(eyeTangentSpace.xy) / eyeTangentSpace.z;
+	F32 parallaxLimit = -length(eyeTangentSpace.xy) / eyeTangentSpace.z;
 	parallaxLimit *= heightMapScale;
 
-	vec2 offsetDir = normalize(eyeTangentSpace.xy);
-	vec2 maxOffset = offsetDir * parallaxLimit;
+	Vec2 offsetDir = normalize(eyeTangentSpace.xy);
+	Vec2 maxOffset = offsetDir * parallaxLimit;
 
-	vec3 E = normalize(eyeTangentSpace);
+	Vec3 E = normalize(eyeTangentSpace);
 
-	float factor0 = -dot(E, normTangentSpace);
-	float factor1 = in_distFromTheCamera / -MAX_EFFECTIVE_DISTANCE;
-	float factor = (1.0 - factor0) * (1.0 - factor1);
-	float sampleCountf = mix(float(MIN_SAMPLES), float(MAX_SAMPLES), factor);
+	F32 factor0 = -dot(E, normTangentSpace);
+	F32 factor1 = in_distFromTheCamera / -MAX_EFFECTIVE_DISTANCE;
+	F32 factor = (1.0 - factor0) * (1.0 - factor1);
+	F32 sampleCountf = mix(F32(MIN_SAMPLES), F32(MAX_SAMPLES), factor);
 
-	float stepSize = 1.0 / sampleCountf;
+	F32 stepSize = 1.0 / sampleCountf;
 
-	float crntRayHeight = 1.0;
-	vec2 crntOffset = vec2(0.0);
-	vec2 lastOffset = vec2(0.0);
+	F32 crntRayHeight = 1.0;
+	Vec2 crntOffset = Vec2(0.0);
+	Vec2 lastOffset = Vec2(0.0);
 
-	float lastSampledHeight = 1.0;
-	float crntSampledHeight = 1.0;
+	F32 lastSampledHeight = 1.0;
+	F32 crntSampledHeight = 1.0;
 
-	uint crntSample = 0;
+	U32 crntSample = 0;
 
-	uint sampleCount = uint(sampleCountf);
+	U32 sampleCount = U32(sampleCountf);
 	ANKI_LOOP while(crntSample < sampleCount)
 	{
 		crntSampledHeight = textureGrad(heightMap, uv + crntOffset, dPdx, dPdy).r;
 
 		if(crntSampledHeight > crntRayHeight)
 		{
-			float delta1 = crntSampledHeight - crntRayHeight;
-			float delta2 = (crntRayHeight + stepSize) - lastSampledHeight;
-			float ratio = delta1 / (delta1 + delta2);
+			F32 delta1 = crntSampledHeight - crntRayHeight;
+			F32 delta2 = (crntRayHeight + stepSize) - lastSampledHeight;
+			F32 ratio = delta1 / (delta1 + delta2);
 
 			crntOffset = mix(crntOffset, lastOffset, ratio);
 
@@ -137,22 +137,22 @@ vec2 computeTextureCoordParallax(in sampler2D heightMap, in vec2 uv, in float he
 }
 
 // Write the data to FAIs
-void writeRts(in vec3 diffColor, // from 0 to 1
-	in vec3 normal,
-	in vec3 specularColor,
-	in float roughness,
-	in float subsurface,
-	in vec3 emission,
-	in float metallic)
+void writeRts(in Vec3 diffColor, // from 0 to 1
+	in Vec3 normal,
+	in Vec3 specularColor,
+	in F32 roughness,
+	in F32 subsurface,
+	in Vec3 emission,
+	in F32 metallic)
 {
 	GbufferInfo g;
-	g.diffuse = diffColor;
-	g.normal = normal;
-	g.specular = specularColor;
-	g.roughness = roughness;
-	g.subsurface = subsurface;
-	g.emission = (emission.r + emission.g + emission.b) / 3.0;
-	g.metallic = metallic;
+	g.m_diffuse = diffColor;
+	g.m_normal = normal;
+	g.m_specular = specularColor;
+	g.m_roughness = roughness;
+	g.m_subsurface = subsurface;
+	g.m_emission = (emission.r + emission.g + emission.b) / 3.0;
+	g.m_metallic = metallic;
 	writeGBuffer(g, out_msRt0, out_msRt1, out_msRt2);
 }
 #endif // PASS == PASS_GB_FS

+ 60 - 60
shaders/GBufferCommonTessc.glsl

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include "shaders/MsBsCommon.glsl"
+#include <shaders/MsBsCommon.glsl>
 
 layout(vertices = 3) out;
 
@@ -18,17 +18,17 @@ layout(vertices = 3) out;
 //
 in gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 }
 gl_in[];
 
-layout(location = 0) in vec2 inTexCoords[];
-layout(location = 1) in mediump vec3 inNormal[];
+layout(location = 0) in Vec2 inTexCoords[];
+layout(location = 1) in mediump Vec3 inNormal[];
 #if PASS == COLOR
-layout(location = 2) in mediump vec4 inTangent[];
+layout(location = 2) in mediump Vec4 inTangent[];
 #endif
 #if INSTANCE_ID_FRAGMENT_SHADER
-layout(location = 3) flat in uint inInstanceId[];
+layout(location = 3) flat in U32 inInstanceId[];
 #endif
 
 //
@@ -37,37 +37,37 @@ layout(location = 3) flat in uint inInstanceId[];
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 }
 gl_out[];
 
-layout(location = 0) out vec2 outTexCoord[];
-layout(location = 1) out vec3 outNormal[];
+layout(location = 0) out Vec2 outTexCoord[];
+layout(location = 1) out Vec3 outNormal[];
 #if PASS == COLOR
-layout(location = 2) out vec4 outTangent[];
+layout(location = 2) out Vec4 outTangent[];
 #endif
 
 #if INSTANCE_ID_FRAGMENT_SHADER
 struct CommonPatch
 {
-	uint instanceId;
+	U32 instanceId;
 };
 #endif
 
 struct PNPatch
 {
-	vec3 pos021;
-	vec3 pos012;
-	vec3 pos102;
-	vec3 pos201;
-	vec3 pos210;
-	vec3 pos120;
-	vec3 pos111;
+	Vec3 pos021;
+	Vec3 pos012;
+	Vec3 pos102;
+	Vec3 pos201;
+	Vec3 pos210;
+	Vec3 pos120;
+	Vec3 pos111;
 };
 
 struct PhongPatch
 {
-	vec3 terms[3];
+	Vec3 terms[3];
 };
 
 out patch PNPatch pnPatch;
@@ -77,11 +77,11 @@ out patch CommonPatch commonPatch;
 #endif
 
 // Project point to plane
-vec3 projectToPlane(vec3 point, vec3 planePoint, vec3 planeNormal)
+Vec3 projectToPlane(Vec3 point, Vec3 planePoint, Vec3 planeNormal)
 {
-	vec3 v = point - planePoint;
-	float pen = dot(v, planeNormal);
-	vec3 d = pen * planeNormal;
+	Vec3 v = point - planePoint;
+	F32 pen = dot(v, planeNormal);
+	Vec3 d = pen * planeNormal;
 	return (point - d);
 }
 
@@ -89,18 +89,18 @@ vec3 projectToPlane(vec3 point, vec3 planePoint, vec3 planeNormal)
 void calcPositions()
 {
 	// The original vertices stay the same
-	vec3 pos030 = IN_POS3(0);
-	vec3 pos003 = IN_POS3(1);
-	vec3 pos300 = IN_POS3(2);
+	Vec3 pos030 = IN_POS3(0);
+	Vec3 pos003 = IN_POS3(1);
+	Vec3 pos300 = IN_POS3(2);
 
 	OUT_POS4(0) = IN_POS4(0);
 	OUT_POS4(1) = IN_POS4(1);
 	OUT_POS4(2) = IN_POS4(2);
 
 	// edges are names according to the opposing vertex
-	vec3 edgeB300 = pos003 - pos030;
-	vec3 edgeB030 = pos300 - pos003;
-	vec3 edgeB003 = pos030 - pos300;
+	Vec3 edgeB300 = pos003 - pos030;
+	Vec3 edgeB030 = pos300 - pos003;
+	Vec3 edgeB003 = pos030 - pos300;
 
 	// Generate two midpoints on each edge
 	pnPatch.pos021 = pos030 + edgeB300 / 3.0;
@@ -118,61 +118,61 @@ void calcPositions()
 	pnPatch.pos120 = projectToPlane(pnPatch.pos120, pos030, outNormal[0]);
 
 	// Handle the center
-	vec3 center = (pos003 + pos030 + pos300) / 3.0;
+	Vec3 center = (pos003 + pos030 + pos300) / 3.0;
 	pnPatch.pos111 =
 		(pnPatch.pos021 + pnPatch.pos012 + pnPatch.pos102 + pnPatch.pos201 + pnPatch.pos210 + pnPatch.pos120) / 6.0;
 	pnPatch.pos111 += (pnPatch.pos111 - center) / 2.0;
 }
 
-vec3 calcFaceNormal(in vec3 v0, in vec3 v1, in vec3 v2)
+Vec3 calcFaceNormal(in Vec3 v0, in Vec3 v1, in Vec3 v2)
 {
 	return normalize(cross(v1 - v0, v2 - v0));
 }
 
-float calcEdgeTessLevel(in vec3 n0, in vec3 n1, in float maxTessLevel)
+F32 calcEdgeTessLevel(in Vec3 n0, in Vec3 n1, in F32 maxTessLevel)
 {
-	vec3 norm = normalize(n0 + n1);
-	float tess = (1.0 - norm.z) * (maxTessLevel - 1.0) + 1.0;
+	Vec3 norm = normalize(n0 + n1);
+	F32 tess = (1.0 - norm.z) * (maxTessLevel - 1.0) + 1.0;
 	return tess;
 }
 
-/*float calcEdgeTessLevel(in vec2 p0, in vec2 p1, in float maxTessLevel)
+/*F32 calcEdgeTessLevel(in Vec2 p0, in Vec2 p1, in F32 maxTessLevel)
 {
-	float dist = distance(p0, p1) * 10.0;
+	F32 dist = distance(p0, p1) * 10.0;
 	return dist * (maxTessLevel - 1.0) + 1.0;
 }*/
 
 // Given the face positions in NDC caclulate if the face is front facing or not
-bool isFaceFrontFacing(in vec2 posNdc[3])
+bool isFaceFrontFacing(in Vec2 posNdc[3])
 {
-	vec2 a = posNdc[1] - posNdc[0];
-	vec2 b = posNdc[2] - posNdc[1];
-	vec2 c = a.xy * b.yx;
+	Vec2 a = posNdc[1] - posNdc[0];
+	Vec2 b = posNdc[2] - posNdc[1];
+	Vec2 c = a.xy * b.yx;
 	return (c.x - c.y) > 0.0;
 }
 
 // Check if a single NDC position is outside the clip space
-bool posOutsideClipSpace(in vec2 posNdc)
+bool posOutsideClipSpace(in Vec2 posNdc)
 {
-	bvec2 compa = lessThan(posNdc, vec2(-1.0));
-	bvec2 compb = greaterThan(posNdc, vec2(1.0));
+	bvec2 compa = lessThan(posNdc, Vec2(-1.0));
+	bvec2 compb = greaterThan(posNdc, Vec2(1.0));
 	return all(bvec4(compa, compb));
 }
 
 // Check if a face in NDC is outside the clip space
-bool isFaceOutsideClipSpace(in vec2 posNdc[3])
+bool isFaceOutsideClipSpace(in Vec2 posNdc[3])
 {
 	return any(bvec3(posOutsideClipSpace(posNdc[0]), posOutsideClipSpace(posNdc[1]), posOutsideClipSpace(posNdc[2])));
 }
 
 // Check if a face is visible
-bool isFaceVisible(in mat4 mvp)
+bool isFaceVisible(in Mat4 mvp)
 {
 	// Calculate clip positions
-	vec2 clip[3];
-	for(int i = 0; i < 3; i++)
+	Vec2 clip[3];
+	for(I32 i = 0; i < 3; i++)
 	{
-		vec4 v = mvp * IN_POS4(i);
+		Vec4 v = mvp * IN_POS4(i);
 		clip[i] = v.xy / (v.w * 0.5 + 0.5);
 	}
 
@@ -180,11 +180,11 @@ bool isFaceVisible(in mat4 mvp)
 	return isFaceFrontFacing(clip) && !isFaceOutsideClipSpace(clip);
 }
 
-void setSilhouetteTessLevels(in mat3 normalMat, in float maxTessLevel)
+void setSilhouetteTessLevels(in Mat3 normalMat, in F32 maxTessLevel)
 {
 	// Calculate the normals in view space
-	vec3 nv[3];
-	for(int i = 0; i < 3; i++)
+	Vec3 nv[3];
+	for(I32 i = 0; i < 3; i++)
 	{
 		nv[i] = normalMat * inNormal[i];
 	}
@@ -195,7 +195,7 @@ void setSilhouetteTessLevels(in mat3 normalMat, in float maxTessLevel)
 	gl_TessLevelInner[0] = (gl_TessLevelOuter[0] + gl_TessLevelOuter[1] + gl_TessLevelOuter[2]) / 3.0;
 }
 
-void setConstantTessLevels(in float maxTessLevel)
+void setConstantTessLevels(in F32 maxTessLevel)
 {
 	gl_TessLevelOuter[0] = maxTessLevel;
 	gl_TessLevelOuter[1] = maxTessLevel;
@@ -212,27 +212,27 @@ void discardPatch()
 }
 
 // Used in phong method
-float calcPhongTerm(int ivId, int i, vec3 q)
+F32 calcPhongTerm(I32 ivId, I32 i, Vec3 q)
 {
-	vec3 qMinusP = q - IN_POS3(i);
+	Vec3 qMinusP = q - IN_POS3(i);
 	return q[ivId] - dot(qMinusP, inNormal[i]) * inNormal[i][ivId];
 }
 
 // This function is part of the point-normal tessellation method
 #define tessellatePNPositionNormalTangentTexCoord_DEFINED
-void tessellatePNPositionNormalTangentTexCoord(in float maxTessLevel, in mat4 mvp, in mat3 normalMat)
+void tessellatePNPositionNormalTangentTexCoord(in F32 maxTessLevel, in Mat4 mvp, in Mat3 normalMat)
 {
-	float tessLevel = 0.0;
+	F32 tessLevel = 0.0;
 
 	// Calculate the face normal in view space
-	vec3 faceNorm = calcFaceNormal(IN_POS3(0), IN_POS3(1), IN_POS3(2));
+	Vec3 faceNorm = calcFaceNormal(IN_POS3(0), IN_POS3(1), IN_POS3(2));
 	faceNorm = (normalMat * faceNorm);
 
 	if(faceNorm.z >= 0.0)
 	{
 		// The face is front facing
 
-		for(int i = 0; i < 3; i++)
+		for(I32 i = 0; i < 3; i++)
 		{
 			outTexCoord[i] = inTexCoords[i];
 			outNormal[i] = inNormal[i];
@@ -256,7 +256,7 @@ void tessellatePNPositionNormalTangentTexCoord(in float maxTessLevel, in mat4 mv
 }
 
 #define tessellatePhongPositionNormalTangentTexCoord_DEFINED
-void tessellatePhongPositionNormalTangentTexCoord(in float maxTessLevel, in mat4 mvp, in mat3 normalMat)
+void tessellatePhongPositionNormalTangentTexCoord(in F32 maxTessLevel, in Mat4 mvp, in Mat3 normalMat)
 {
 	if(IID == 0)
 	{
@@ -289,7 +289,7 @@ void tessellatePhongPositionNormalTangentTexCoord(in float maxTessLevel, in mat4
 }
 
 #define tessellateDispMapPositionNormalTangentTexCoord_DEFINED
-void tessellateDispMapPositionNormalTangentTexCoord(in float maxTessLevel, in mat4 mvp, in mat3 normalMat)
+void tessellateDispMapPositionNormalTangentTexCoord(in F32 maxTessLevel, in Mat4 mvp, in Mat3 normalMat)
 {
 	if(IID == 0)
 	{

+ 49 - 49
shaders/GBufferCommonTesse.glsl

@@ -14,30 +14,30 @@ layout(triangles, equal_spacing, ccw) in;
 
 struct PNPatch
 {
-	vec3 pos021;
-	vec3 pos012;
-	vec3 pos102;
-	vec3 pos201;
-	vec3 pos210;
-	vec3 pos120;
-	vec3 pos111;
+	Vec3 pos021;
+	Vec3 pos012;
+	Vec3 pos102;
+	Vec3 pos201;
+	Vec3 pos210;
+	Vec3 pos120;
+	Vec3 pos111;
 };
 
 struct PhongPatch
 {
-	vec3 terms[3];
+	Vec3 terms[3];
 };
 
 #if INSTANCE_ID_FRAGMENT_SHADER
 struct CommonPatch
 {
-	uint instanceId;
+	U32 instanceId;
 };
 #endif
 
 in gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 }
 gl_in[];
 
@@ -47,10 +47,10 @@ in patch PhongPatch phongPatch;
 in patch CommonPatch commonPatch;
 #endif
 
-layout(location = 0) in vec2 inTexCoord[];
-layout(location = 1) in vec3 inNormal[];
+layout(location = 0) in Vec2 inTexCoord[];
+layout(location = 1) in Vec3 inNormal[];
 #if PASS == COLOR
-layout(location = 2) in vec4 inTangent[];
+layout(location = 2) in Vec4 inTangent[];
 #endif
 
 //
@@ -59,20 +59,20 @@ layout(location = 2) in vec4 inTangent[];
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
-layout(location = 0) out highp vec2 outTexCoord;
+layout(location = 0) out highp Vec2 outTexCoord;
 #if PASS == COLOR
-layout(location = 1) out mediump vec3 outNormal;
-layout(location = 2) out mediump vec4 outTangent;
+layout(location = 1) out mediump Vec3 outNormal;
+layout(location = 2) out mediump Vec4 outTangent;
 #endif
 
 #define INTERPOLATE(x_) (x_[0] * gl_TessCoord.x + x_[1] * gl_TessCoord.y + x_[2] * gl_TessCoord.z)
 
 // Smooth tessellation
 #define tessellatePNPositionNormalTangentTexCoord_DEFINED
-void tessellatePNPositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalMat)
+void tessellatePNPositionNormalTangentTexCoord(in Mat4 mvp, in Mat3 normalMat)
 {
 #if PASS == COLOR
 	outNormal = normalize(normalMat * INTERPOLATE(inNormal));
@@ -82,30 +82,30 @@ void tessellatePNPositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalMat)
 
 	outTexCoord = INTERPOLATE(inTexCoord);
 
-	float u = gl_TessCoord.x;
-	float v = gl_TessCoord.y;
-	float w = gl_TessCoord.z;
+	F32 u = gl_TessCoord.x;
+	F32 v = gl_TessCoord.y;
+	F32 w = gl_TessCoord.z;
 
-	float uPow3 = pow(u, 3);
-	float vPow3 = pow(v, 3);
-	float wPow3 = pow(w, 3);
-	float uPow2 = pow(u, 2);
-	float vPow2 = pow(v, 2);
-	float wPow2 = pow(w, 2);
+	F32 uPow3 = pow(u, 3);
+	F32 vPow3 = pow(v, 3);
+	F32 wPow3 = pow(w, 3);
+	F32 uPow2 = pow(u, 2);
+	F32 vPow2 = pow(v, 2);
+	F32 wPow2 = pow(w, 2);
 
-	vec3 pos030 = IN_POS3(0);
-	vec3 pos003 = IN_POS3(1);
-	vec3 pos300 = IN_POS3(2);
+	Vec3 pos030 = IN_POS3(0);
+	Vec3 pos003 = IN_POS3(1);
+	Vec3 pos300 = IN_POS3(2);
 
-	vec3 pos = pos300 * wPow3 + pos030 * uPow3 + pos003 * vPow3 + pnPatch.pos210 * 3.0 * wPow2 * u
+	Vec3 pos = pos300 * wPow3 + pos030 * uPow3 + pos003 * vPow3 + pnPatch.pos210 * 3.0 * wPow2 * u
 			   + pnPatch.pos120 * 3.0 * w * uPow2 + pnPatch.pos201 * 3.0 * wPow2 * v + pnPatch.pos021 * 3.0 * uPow2 * v
 			   + pnPatch.pos102 * 3.0 * w * vPow2 + pnPatch.pos012 * 3.0 * u * vPow2 + pnPatch.pos111 * 6.0 * w * u * v;
 
-	gl_Position = mvp * vec4(pos, 1.0);
+	gl_Position = mvp * Vec4(pos, 1.0);
 }
 
 #define tessellatePhongPositionNormalTangentTexCoord_DEFINED
-void tessellatePhongPositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalMat)
+void tessellatePhongPositionNormalTangentTexCoord(in Mat4 mvp, in Mat3 normalMat)
 {
 #if PASS == COLOR
 	outNormal = normalize(normalMat * INTERPOLATE(inNormal));
@@ -116,30 +116,30 @@ void tessellatePhongPositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalMat
 	outTexCoord = INTERPOLATE(inTexCoord);
 
 	// interpolated position
-	vec3 inpos[3] = vec3[](IN_POS3(0), IN_POS3(1), IN_POS3(2));
-	vec3 barPos = INTERPOLATE(inpos);
+	Vec3 inpos[3] = Vec3[](IN_POS3(0), IN_POS3(1), IN_POS3(2));
+	Vec3 barPos = INTERPOLATE(inpos);
 
 	// build terms
-	vec3 termIJ = vec3(phongPatch.terms[0][0], phongPatch.terms[1][0], phongPatch.terms[2][0]);
-	vec3 termJK = vec3(phongPatch.terms[0][1], phongPatch.terms[1][1], phongPatch.terms[2][1]);
-	vec3 termIK = vec3(phongPatch.terms[0][2], phongPatch.terms[1][2], phongPatch.terms[2][2]);
+	Vec3 termIJ = Vec3(phongPatch.terms[0][0], phongPatch.terms[1][0], phongPatch.terms[2][0]);
+	Vec3 termJK = Vec3(phongPatch.terms[0][1], phongPatch.terms[1][1], phongPatch.terms[2][1]);
+	Vec3 termIK = Vec3(phongPatch.terms[0][2], phongPatch.terms[1][2], phongPatch.terms[2][2]);
 
-	vec3 tc2 = gl_TessCoord * gl_TessCoord;
+	Vec3 tc2 = gl_TessCoord * gl_TessCoord;
 
 	// phong tesselated pos
-	vec3 phongPos = tc2[0] * inpos[0] + tc2[1] * inpos[1] + tc2[2] * inpos[2]
+	Vec3 phongPos = tc2[0] * inpos[0] + tc2[1] * inpos[1] + tc2[2] * inpos[2]
 					+ gl_TessCoord[0] * gl_TessCoord[1] * termIJ + gl_TessCoord[1] * gl_TessCoord[2] * termJK
 					+ gl_TessCoord[2] * gl_TessCoord[0] * termIK;
 
-	float tessAlpha = 1.0;
-	vec3 finalPos = (1.0 - tessAlpha) * barPos + tessAlpha * phongPos;
-	gl_Position = mvp * vec4(finalPos, 1.0);
+	F32 tessAlpha = 1.0;
+	Vec3 finalPos = (1.0 - tessAlpha) * barPos + tessAlpha * phongPos;
+	gl_Position = mvp * Vec4(finalPos, 1.0);
 }
 
 #define tessellateDispMapPositionNormalTangentTexCoord_DEFINED
-void tessellateDispMapPositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalMat, in sampler2D dispMap)
+void tessellateDispMapPositionNormalTangentTexCoord(in Mat4 mvp, in Mat3 normalMat, in sampler2D dispMap)
 {
-	vec3 norm = INTERPOLATE(inNormal);
+	Vec3 norm = INTERPOLATE(inNormal);
 #if PASS == COLOR
 	outNormal = normalize(normalMat * norm);
 	outTangent = INTERPOLATE(inTangent);
@@ -148,10 +148,10 @@ void tessellateDispMapPositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalM
 
 	outTexCoord = INTERPOLATE(inTexCoord);
 
-	float height = texture(dispMap, outTexCoord).r;
+	F32 height = texture(dispMap, outTexCoord).r;
 	height = height * 0.7 - 0.35;
 
-	vec3 inpos[3] = vec3[](IN_POS3(0), IN_POS3(1), IN_POS3(2));
-	vec3 pos = INTERPOLATE(inpos) + norm * height;
-	gl_Position = mvp * vec4(pos, 1.0);
+	Vec3 inpos[3] = Vec3[](IN_POS3(0), IN_POS3(1), IN_POS3(2));
+	Vec3 pos = INTERPOLATE(inpos) + norm * height;
+	gl_Position = mvp * Vec4(pos, 1.0);
 }

+ 38 - 38
shaders/GBufferCommonVert.glsl

@@ -6,7 +6,7 @@
 #ifndef ANKI_SHADERS_GBUFFER_COMMON_VERT_GLSL
 #define ANKI_SHADERS_GBUFFER_COMMON_VERT_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 //
 // Uniforms
@@ -14,23 +14,23 @@
 #if BONES
 layout(ANKI_SS_BINDING(0, 0), row_major) readonly buffer ss00_
 {
-	mat4 u_boneTransforms[];
+	Mat4 u_boneTransforms[];
 };
 #endif
 
 //
 // Input
 //
-layout(location = POSITION_LOCATION) in highp vec3 in_position;
+layout(location = POSITION_LOCATION) in highp Vec3 in_position;
 #if PASS == PASS_GB_FS
-layout(location = TEXTURE_COORDINATE_LOCATION) in highp vec2 in_uv;
-layout(location = NORMAL_LOCATION) in mediump vec3 in_normal;
-layout(location = TANGENT_LOCATION) in mediump vec4 in_tangent;
+layout(location = TEXTURE_COORDINATE_LOCATION) in highp Vec2 in_uv;
+layout(location = NORMAL_LOCATION) in mediump Vec3 in_normal;
+layout(location = TANGENT_LOCATION) in mediump Vec4 in_tangent;
 #endif
 
 #if BONES
-layout(location = BONE_WEIGHTS_LOCATION) in mediump vec4 in_boneWeights;
-layout(location = BONE_INDICES_LOCATION) in uvec4 in_boneIndices;
+layout(location = BONE_WEIGHTS_LOCATION) in mediump Vec4 in_boneWeights;
+layout(location = BONE_INDICES_LOCATION) in UVec4 in_boneIndices;
 #endif
 
 //
@@ -38,29 +38,29 @@ layout(location = BONE_INDICES_LOCATION) in uvec4 in_boneIndices;
 //
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
 #if PASS == PASS_GB_FS
-layout(location = 0) out highp vec2 out_uv;
-layout(location = 1) out mediump vec3 out_normal;
-layout(location = 2) out mediump vec4 out_tangent;
+layout(location = 0) out highp Vec2 out_uv;
+layout(location = 1) out mediump Vec3 out_normal;
+layout(location = 2) out mediump Vec4 out_tangent;
 #	if CALC_BITANGENT_IN_VERT
-layout(location = 3) out mediump vec3 out_bitangent;
+layout(location = 3) out mediump Vec3 out_bitangent;
 #	endif
-layout(location = 4) out mediump float out_distFromTheCamera; // Parallax
-layout(location = 5) out mediump vec3 out_eyeTangentSpace; // Parallax
-layout(location = 6) out mediump vec3 out_normalTangentSpace; // Parallax
+layout(location = 4) out mediump F32 out_distFromTheCamera; // Parallax
+layout(location = 5) out mediump Vec3 out_eyeTangentSpace; // Parallax
+layout(location = 6) out mediump Vec3 out_normalTangentSpace; // Parallax
 #endif
 
 //
 // Globals
 //
-vec3 g_position = in_position;
+Vec3 g_position = in_position;
 #if PASS == PASS_GB_FS
-highp vec2 g_uv = in_uv;
-mediump vec3 g_normal = in_normal;
-mediump vec4 g_tangent = in_tangent;
+highp Vec2 g_uv = in_uv;
+mediump Vec3 g_normal = in_normal;
+mediump Vec4 g_tangent = in_tangent;
 #endif
 
 //
@@ -69,10 +69,10 @@ mediump vec4 g_tangent = in_tangent;
 
 // Common store function
 #if PASS == PASS_GB_FS
-void positionUvNormalTangent(mat4 mvp, mat3 rotationMat)
+void positionUvNormalTangent(Mat4 mvp, Mat3 rotationMat)
 {
 	out_uv = g_uv;
-	gl_Position = mvp * vec4(g_position, 1.0);
+	gl_Position = mvp * Vec4(g_position, 1.0);
 
 	out_normal = rotationMat * g_normal.xyz;
 	out_tangent.xyz = rotationMat * g_tangent.xyz;
@@ -86,16 +86,16 @@ void positionUvNormalTangent(mat4 mvp, mat3 rotationMat)
 
 // Store stuff for parallax mapping
 #if PASS == PASS_GB_FS
-void parallax(mat4 modelViewMat)
+void parallax(Mat4 modelViewMat)
 {
-	vec3 n = in_normal;
-	vec3 t = in_tangent.xyz;
-	vec3 b = cross(n, t) * in_tangent.w;
+	Vec3 n = in_normal;
+	Vec3 t = in_tangent.xyz;
+	Vec3 b = cross(n, t) * in_tangent.w;
 
-	mat3 normalMat = mat3(modelViewMat);
-	mat3 invTbn = transpose(normalMat * mat3(t, b, n));
+	Mat3 normalMat = Mat3(modelViewMat);
+	Mat3 invTbn = transpose(normalMat * Mat3(t, b, n));
 
-	vec3 viewPos = (modelViewMat * vec4(g_position, 1.0)).xyz;
+	Vec3 viewPos = (modelViewMat * Vec4(g_position, 1.0)).xyz;
 	out_distFromTheCamera = viewPos.z;
 
 	out_eyeTangentSpace = invTbn * viewPos;
@@ -107,20 +107,20 @@ void parallax(mat4 modelViewMat)
 #if BONES
 void skinning()
 {
-	vec3 position = vec3(0.0);
-	vec3 normal = vec3(0.0);
-	vec3 tangent = vec3(0.0);
-	for(uint i = 0; i < 4; ++i)
+	Vec3 position = Vec3(0.0);
+	Vec3 normal = Vec3(0.0);
+	Vec3 tangent = Vec3(0.0);
+	for(U32 i = 0; i < 4; ++i)
 	{
-		uint boneIdx = in_boneIndices[i];
+		U32 boneIdx = in_boneIndices[i];
 		if(boneIdx < 0xFFFF)
 		{
-			float boneWeight = in_boneWeights[i];
+			F32 boneWeight = in_boneWeights[i];
 
-			position += (u_boneTransforms[boneIdx] * vec4(g_position * boneWeight, 1.0)).xyz;
+			position += (u_boneTransforms[boneIdx] * Vec4(g_position * boneWeight, 1.0)).xyz;
 #	if PASS == PASS_GB_FS
-			normal += (u_boneTransforms[boneIdx] * vec4(g_normal * boneWeight, 0.0)).xyz;
-			tangent += (u_boneTransforms[boneIdx] * vec4(g_tangent.xyz * boneWeight, 0.0)).xyz;
+			normal += (u_boneTransforms[boneIdx] * Vec4(g_normal * boneWeight, 0.0)).xyz;
+			tangent += (u_boneTransforms[boneIdx] * Vec4(g_tangent.xyz * boneWeight, 0.0)).xyz;
 #	endif
 		}
 	}

+ 28 - 25
programs/GBufferGeneric.ankiprog → shaders/GBufferGeneric.ankiprog

@@ -22,13 +22,13 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<inputs>
-				<input name="mvp" type="mat4" instanced="1"/>
-				<input name="rotationMat" type="mat3" instanced="1">
+				<input name="mvp" type="Mat4" instanced="1"/>
+				<input name="rotationMat" type="Mat3" instanced="1">
 					<mutators>
 						<mutator name="PASS" values="0"/>
 					</mutators>
 				</input>
-				<input name="modelViewMat" type="mat4" instanced="1">
+				<input name="modelViewMat" type="Mat4" instanced="1">
 					<mutators>
 						<mutator name="PASS" values="0"/>
 						<mutator name="PARALLAX" values="1"/>
@@ -36,7 +36,8 @@ http://www.anki3d.org/LICENSE
 				</input>
 			</inputs>
 
-			<source><![CDATA[#include "shaders/GBufferCommonVert.glsl"
+			<source><![CDATA[
+#include <shaders/GBufferCommonVert.glsl>
 
 void main() 
 {
@@ -51,7 +52,7 @@ void main()
 	parallax(modelViewMat);
 #	endif
 #else
-	gl_Position = mvp * vec4(g_position, 1.0);
+	gl_Position = mvp * Vec4(g_position, 1.0);
 #endif
 }
 			]]>
@@ -61,44 +62,44 @@ void main()
 		<shader type="frag">
 			<inputs>
 				<!-- Consts -->
-				<input name="diffColor" type="vec3" const="1">
+				<input name="diffColor" type="Vec3" const="1">
 					<mutators>
 						<mutator name="DIFFUSE_TEX" values="0"/>
 						<mutator name="PASS" values="0"/>
 					</mutators>
 				</input>
-				<input name="specColor" type="vec3" const="1">
+				<input name="specColor" type="Vec3" const="1">
 					<mutators>
 						<mutator name="SPECULAR_TEX" values="0"/>
 						<mutator name="PASS" values="0"/>
 					</mutators>
 				</input>
-				<input name="roughness" type="float" const="1">
+				<input name="roughness" type="F32" const="1">
 					<mutators>
 						<mutator name="ROUGHNESS_TEX" values="0"/>
 						<mutator name="PASS" values="0"/>
 					</mutators>
 				</input>
-				<input name="metallic" type="float" const="1">
+				<input name="metallic" type="F32" const="1">
 					<mutators>
 						<mutator name="METAL_TEX" values="0"/>
 						<mutator name="PASS" values="0"/>
 					</mutators>
 				</input>
-				<input name="emission" type="vec3" const="1">
+				<input name="emission" type="Vec3" const="1">
 					<mutators>
 						<mutator name="EMISSIVE_TEX" values="0"/>
 						<mutator name="PASS" values="0"/>
 					</mutators>
 				</input>
-				<input name="heightMapScale" type="float" const="1">
+				<input name="heightMapScale" type="F32" const="1">
 					<mutators>
 						<mutator name="PARALLAX" values="1"/>
 						<mutator name="PASS" values="0"/>
 						<mutator name="LOD" values="0"/>
 					</mutators>
 				</input>
-				<input name="subsurface" type="float" const="1">
+				<input name="subsurface" type="F32" const="1">
 					<mutators>
 						<mutator name="PASS" values="0"/>
 					</mutators>
@@ -151,47 +152,49 @@ void main()
 				</input>
 			</inputs>
 
-			<source><![CDATA[#include "shaders/GBufferCommonFrag.glsl"
+			<source><![CDATA[
+#include <shaders/GBufferCommonFrag.glsl>
+
 void main()
 {
 #if PASS == PASS_GB_FS
 #	if heightTex_DEFINED
-		vec2 uv =  computeTextureCoordParallax(heightTex, in_uv, heightMapScale);
+		Vec2 uv =  computeTextureCoordParallax(heightTex, in_uv, heightMapScale);
 #	else
-		vec2 uv = in_uv;
+		Vec2 uv = in_uv;
 #	endif
 
 #	if diffTex_DEFINED
-		vec3 diffColor = texture(diffTex, uv).rgb;
+		Vec3 diffColor = texture(diffTex, uv).rgb;
 #	endif
 
 #	if specTex_DEFINED
-		vec3 specColor = texture(specTex, uv).rgb;
+		Vec3 specColor = texture(specTex, uv).rgb;
 #	endif
 
 #	if roughnessTex_DEFINED
-		float roughness = texture(roughnessTex, uv).r;
+		F32 roughness = texture(roughnessTex, uv).r;
 #	endif
 
 #	if metalTex_DEFINED
-		float metallic = texture(metalTex, uv).r;
+		F32 metallic = texture(metalTex, uv).r;
 #	endif
 
 #	if normalTex_DEFINED
-		vec3 normal = readNormalFromTexture(normalTex, uv);
+		Vec3 normal = readNormalFromTexture(normalTex, uv);
 #	else
-		vec3 normal = normalize(in_normal);
+		Vec3 normal = normalize(in_normal);
 #	endif
 
 #	if emissiveTex_DEFINED
-		vec3 emission = texture(emissiveTex, uv).rgb;
+		Vec3 emission = texture(emissiveTex, uv).rgb;
 #	endif
 
 	writeRts(diffColor, normal, specColor, roughness, subsurface, emission, metallic);
 #elif PASS == PASS_EZ
-	out_msRt0 = vec4(0.0);
-	out_msRt1 = vec4(0.0);
-	out_msRt2 = vec4(0.0);
+	out_msRt0 = Vec4(0.0);
+	out_msRt1 = Vec4(0.0);
+	out_msRt2 = Vec4(0.0);
 #endif
 }
 			]]></source>

+ 39 - 39
programs/GBufferPost.ankiprog → shaders/GBufferPost.ankiprog

@@ -6,40 +6,40 @@ http://www.anki3d.org/LICENSE
 -->
 <shaderProgram>
 	<inputs>
-		<input name="CLUSTER_COUNT_X" type="uint" const="1"/>
-		<input name="CLUSTER_COUNT_Y" type="uint" const="1"/>
-		<input name="CLUSTER_COUNT_Z" type="uint" const="1"/>
+		<input name="CLUSTER_COUNT_X" type="U32" const="1"/>
+		<input name="CLUSTER_COUNT_Y" type="U32" const="1"/>
+		<input name="CLUSTER_COUNT_Z" type="U32" const="1"/>
 	</inputs>
 
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
-layout(location = 0) out vec2 out_uv;
-layout(location = 1) out vec2 out_clusterIJ;
+layout(location = 0) out Vec2 out_uv;
+layout(location = 1) out Vec2 out_clusterIJ;
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
 void main()
 {
-	out_uv = vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
-	vec2 pos = out_uv * 2.0 - 1.0;
-	gl_Position = vec4(pos, 0.0, 1.0);
+	out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
+	Vec2 pos = out_uv * 2.0 - 1.0;
+	gl_Position = Vec4(pos, 0.0, 1.0);
 
-	out_clusterIJ = vec2(CLUSTER_COUNT_X, CLUSTER_COUNT_Y) * out_uv;
+	out_clusterIJ = Vec2(CLUSTER_COUNT_X, CLUSTER_COUNT_Y) * out_uv;
 }
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<source><![CDATA[
-#include "shaders/Pack.glsl"
-#include "shaders/Clusterer.glsl"
-#include "shaders/Functions.glsl"
+#include <shaders/Pack.glsl>
+#include <shaders/glsl_cpp_common/Clusterer.h>
+#include <shaders/Functions.glsl>
 
 #define LIGHT_SET 0
 #define LIGHT_SS_BINDING 0
@@ -47,16 +47,16 @@ void main()
 #define LIGHT_TEX_BINDING 2
 #define LIGHT_DECALS
 #define LIGHT_COMMON_UNIS
-#include "shaders/ClusterLightCommon.glsl"
+#include <shaders/ClusterLightCommon.glsl>
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msDepthRt;
 layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_ssaoTex;
 
-layout(location = 0) in vec2 in_uv;
-layout(location = 1) in vec2 in_clusterIJ;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 1) in Vec2 in_clusterIJ;
 
-layout(location = 0) out vec4 out_color0;
-layout(location = 1) out vec4 out_color1;
+layout(location = 0) out Vec4 out_color0;
+layout(location = 1) out Vec4 out_color1;
 
 void main()
 {
@@ -67,31 +67,31 @@ void main()
 	// 2nd decal: d''=d'*(1-f')+D'*f' <=> d''=d*(1-f)*(1-f')+D*f*(1-f')+D'*f'
 	// By looking at the trend we will have to multiply the gbuffer.diff with: (1-f)*(1-f') ... (1-f'''')
 
-	vec4 outDiffuse = vec4(0.0, 0.0, 0.0, 1.0);
-	vec4 outSpecular = vec4(0.0, 0.0, 0.0, 1.0);
+	Vec4 outDiffuse = Vec4(0.0, 0.0, 0.0, 1.0);
+	Vec4 outSpecular = Vec4(0.0, 0.0, 0.0, 1.0);
 
 	// Sample SSAO
-	float ssao = textureLod(u_ssaoTex, in_uv, 0.0).r;
+	F32 ssao = textureLod(u_ssaoTex, in_uv, 0.0).r;
 	outDiffuse.a *= ssao;
 
 	// Get worldPos
-	float depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
-	vec2 ndc = UV_TO_NDC(in_uv);
-	vec4 worldPos4 = u_invViewProjMat * vec4(ndc, depth, 1.0);
-	vec3 worldPos = worldPos4.xyz / worldPos4.w;
+	F32 depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
+	Vec2 ndc = UV_TO_NDC(in_uv);
+	Vec4 worldPos4 = u_invViewProjMat * Vec4(ndc, depth, 1.0);
+	Vec3 worldPos = worldPos4.xyz / worldPos4.w;
 
 	// Get first light index
-	uint idxOffset;
+	U32 idxOffset;
 	{
-		uint k = computeClusterK(u_clustererMagic, worldPos);
-		uint clusterIdx = 
-			k * (CLUSTER_COUNT_X * CLUSTER_COUNT_Y) + uint(in_clusterIJ.y) * CLUSTER_COUNT_X + uint(in_clusterIJ.x);
+		U32 k = computeClusterK(u_clustererMagic, worldPos);
+		U32 clusterIdx = 
+			k * (CLUSTER_COUNT_X * CLUSTER_COUNT_Y) + U32(in_clusterIJ.y) * CLUSTER_COUNT_X + U32(in_clusterIJ.x);
 
 		idxOffset = u_clusters[clusterIdx];
 	}
 
 	// Process decals
-	uint count = u_lightIndices[idxOffset++];
+	U32 count = u_lightIndices[idxOffset++];
 	if(count == 0 && ssao >= (1.0 - EPSILON))
 	{
 		discard;
@@ -102,33 +102,33 @@ void main()
 		Decal decal = u_decals[u_lightIndices[idxOffset++]];
 
 		// Project pos to decal space
-		vec4 texCoords4 = decal.texProjectionMat * vec4(worldPos, 1.0);
+		Vec4 texCoords4 = decal.m_texProjectionMat * Vec4(worldPos, 1.0);
 		if(texCoords4.w <= 0.7)
 		{
 			// Behind the decal, skip
 			continue;
 		}
 
-		vec2 texCoords2 = texCoords4.xy / texCoords4.w;
+		Vec2 texCoords2 = texCoords4.xy / texCoords4.w;
 
 		// Clamp the tex coords. Expect a border in the texture atlas
 		texCoords2 = saturate(texCoords2);
 	
 		// Read diffuse
-		vec2 diffUv = mad(texCoords2, decal.diffUv.zw, decal.diffUv.xy);
-		vec4 decalDiff = texture(u_diffDecalTex, diffUv);
+		Vec2 diffUv = mad(texCoords2, decal.m_diffUv.zw, decal.m_diffUv.xy);
+		Vec4 decalDiff = texture(u_diffDecalTex, diffUv);
 
 		// Read roughness
-		vec2 specUv = mad(texCoords2, decal.normRoughnessUv.zw, decal.normRoughnessUv.xy);
-		vec3 spec = texture(u_specularRoughnessDecalTex, specUv).rgb;
+		Vec2 specUv = mad(texCoords2, decal.m_normRoughnessUv.zw, decal.m_normRoughnessUv.xy);
+		Vec3 spec = texture(u_specularRoughnessDecalTex, specUv).rgb;
 
 		// Update diffuse
-		float f = decalDiff.a * decal.blendFactors[0];
+		F32 f = decalDiff.a * decal.m_blendFactors[0];
 		outDiffuse.rgb = outDiffuse.rgb * (1.0 - f) + decalDiff.rgb * f;
 		outDiffuse.a *= (1.0 - f);
 
 		// Update specular
-		f = decalDiff.a * decal.blendFactors[1];
+		f = decalDiff.a * decal.m_blendFactors[1];
 		outSpecular.rgb = outSpecular.rgb * (1.0 - f) + spec.rgb * f;
 		outSpecular.a *= (1.0 - f);
 	}

+ 3 - 3
programs/GaussianBlur.ankiprog → shaders/GaussianBlur.ankiprog

@@ -14,13 +14,13 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="TEXTURE_SIZE" type="uvec2" const="1"/>
+				<input name="TEXTURE_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
@@ -32,7 +32,7 @@ http://www.anki3d.org/LICENSE
 #	define BOX 1
 #endif
 
-#include "shaders/GaussianBlur.glsl"
+#include <shaders/GaussianBlur.glsl>
 			]]></source>
 		</shader>
 	</shaders>

+ 22 - 22
shaders/GaussianBlur.glsl

@@ -13,7 +13,7 @@
 #ifndef ANKI_SHADERS_GAUSSIAN_BLUR_GLSL
 #define ANKI_SHADERS_GAUSSIAN_BLUR_GLSL
 
-#include "shaders/GaussianBlurCommon.glsl"
+#include <shaders/GaussianBlurCommon.glsl>
 
 #if defined(ANKI_COMPUTE_SHADER)
 #	define USE_COMPUTE 1
@@ -23,17 +23,17 @@
 
 // Determine color type
 #if COLOR_COMPONENTS == 4
-#	define COL_TYPE vec4
+#	define COL_TYPE Vec4
 #	define TEX_FETCH rgba
 #	define TO_VEC4(x_) x_
 #elif COLOR_COMPONENTS == 3
-#	define COL_TYPE vec3
+#	define COL_TYPE Vec3
 #	define TEX_FETCH rgb
-#	define TO_VEC4(x_) vec4(x_, 0.0)
+#	define TO_VEC4(x_) Vec4(x_, 0.0)
 #elif COLOR_COMPONENTS == 1
-#	define COL_TYPE float
+#	define COL_TYPE F32
 #	define TEX_FETCH r
-#	define TO_VEC4(x_) vec4(x_, 0.0, 0.0, 0.0)
+#	define TO_VEC4(x_) Vec4(x_, 0.0, 0.0, 0.0)
 #else
 #	error See file
 #endif
@@ -44,7 +44,7 @@ layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex; ///< Input texture
 layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
 layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D u_outImg;
 #else
-layout(location = 0) in vec2 in_uv;
+layout(location = 0) in Vec2 in_uv;
 layout(location = 0) out COL_TYPE out_color;
 #endif
 
@@ -58,12 +58,12 @@ void main()
 		return;
 	}
 
-	vec2 uv = (vec2(gl_GlobalInvocationID.xy) + 0.5) / vec2(TEXTURE_SIZE);
+	Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(TEXTURE_SIZE);
 #else
-	vec2 uv = in_uv;
+	Vec2 uv = in_uv;
 #endif
 
-	const vec2 TEXEL_SIZE = 1.0 / vec2(TEXTURE_SIZE);
+	const Vec2 TEXEL_SIZE = 1.0 / Vec2(TEXTURE_SIZE);
 
 #if !defined(BOX)
 	// Do seperable
@@ -76,10 +76,10 @@ void main()
 
 	COL_TYPE color = textureLod(u_tex, uv, 0.0).TEX_FETCH * WEIGHTS[0u];
 
-	vec2 uvOffset = vec2(0.0);
+	Vec2 uvOffset = Vec2(0.0);
 	uvOffset.X_OR_Y = 1.5 * TEXEL_SIZE.X_OR_Y;
 
-	ANKI_UNROLL for(uint i = 0u; i < STEP_COUNT; ++i)
+	ANKI_UNROLL for(U32 i = 0u; i < STEP_COUNT; ++i)
 	{
 		COL_TYPE col =
 			textureLod(u_tex, uv + uvOffset, 0.0).TEX_FETCH + textureLod(u_tex, uv - uvOffset, 0.0).TEX_FETCH;
@@ -90,27 +90,27 @@ void main()
 #else
 	// Do box
 
-	const vec2 OFFSET = 1.5 * TEXEL_SIZE;
+	const Vec2 OFFSET = 1.5 * TEXEL_SIZE;
 
 	COL_TYPE color = textureLod(u_tex, uv, 0.0).TEX_FETCH * BOX_WEIGHTS[0u];
 
 	COL_TYPE col;
-	col = textureLod(u_tex, uv + vec2(OFFSET.x, 0.0), 0.0).TEX_FETCH;
-	col += textureLod(u_tex, uv + vec2(0.0, OFFSET.y), 0.0).TEX_FETCH;
-	col += textureLod(u_tex, uv + vec2(-OFFSET.x, 0.0), 0.0).TEX_FETCH;
-	col += textureLod(u_tex, uv + vec2(0.0, -OFFSET.y), 0.0).TEX_FETCH;
+	col = textureLod(u_tex, uv + Vec2(OFFSET.x, 0.0), 0.0).TEX_FETCH;
+	col += textureLod(u_tex, uv + Vec2(0.0, OFFSET.y), 0.0).TEX_FETCH;
+	col += textureLod(u_tex, uv + Vec2(-OFFSET.x, 0.0), 0.0).TEX_FETCH;
+	col += textureLod(u_tex, uv + Vec2(0.0, -OFFSET.y), 0.0).TEX_FETCH;
 	color += col * BOX_WEIGHTS[1u];
 
-	col = textureLod(u_tex, uv + vec2(+OFFSET.x, +OFFSET.y), 0.0).TEX_FETCH;
-	col += textureLod(u_tex, uv + vec2(+OFFSET.x, -OFFSET.y), 0.0).TEX_FETCH;
-	col += textureLod(u_tex, uv + vec2(-OFFSET.x, +OFFSET.y), 0.0).TEX_FETCH;
-	col += textureLod(u_tex, uv + vec2(-OFFSET.x, -OFFSET.y), 0.0).TEX_FETCH;
+	col = textureLod(u_tex, uv + Vec2(+OFFSET.x, +OFFSET.y), 0.0).TEX_FETCH;
+	col += textureLod(u_tex, uv + Vec2(+OFFSET.x, -OFFSET.y), 0.0).TEX_FETCH;
+	col += textureLod(u_tex, uv + Vec2(-OFFSET.x, +OFFSET.y), 0.0).TEX_FETCH;
+	col += textureLod(u_tex, uv + Vec2(-OFFSET.x, -OFFSET.y), 0.0).TEX_FETCH;
 	color += col * BOX_WEIGHTS[2u];
 #endif
 
 	// Write value
 #if USE_COMPUTE
-	imageStore(u_outImg, ivec2(gl_GlobalInvocationID.xy), TO_VEC4(color));
+	imageStore(u_outImg, IVec2(gl_GlobalInvocationID.xy), TO_VEC4(color));
 #else
 	out_color = color;
 #endif

+ 12 - 12
shaders/GaussianBlurCommon.glsl

@@ -6,23 +6,23 @@
 #ifndef ANKI_SHADERS_GAUSSIAN_BLUR_COMMON_GLSL
 #define ANKI_SHADERS_GAUSSIAN_BLUR_COMMON_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #if KERNEL_SIZE == 3
-const uint STEP_COUNT = 1u;
-const float WEIGHTS[STEP_COUNT + 1u] = {0.361069, 0.319466};
+const U32 STEP_COUNT = 1u;
+const F32 WEIGHTS[STEP_COUNT + 1u] = {0.361069, 0.319466};
 #elif KERNEL_SIZE == 5
-const uint STEP_COUNT = 2u;
-const float WEIGHTS[STEP_COUNT + 1u] = {0.250301, 0.221461, 0.153388};
+const U32 STEP_COUNT = 2u;
+const F32 WEIGHTS[STEP_COUNT + 1u] = {0.250301, 0.221461, 0.153388};
 #elif KERNEL_SIZE == 7
-const uint STEP_COUNT = 3u;
-const float WEIGHTS[STEP_COUNT + 1u] = {0.214607, 0.189879, 0.131514, 0.071303};
+const U32 STEP_COUNT = 3u;
+const F32 WEIGHTS[STEP_COUNT + 1u] = {0.214607, 0.189879, 0.131514, 0.071303};
 #elif KERNEL_SIZE == 9
-const uint STEP_COUNT = 4u;
-const float WEIGHTS[STEP_COUNT + 1u] = {0.20236, 0.179044, 0.124009, 0.067234, 0.028532};
+const U32 STEP_COUNT = 4u;
+const F32 WEIGHTS[STEP_COUNT + 1u] = {0.20236, 0.179044, 0.124009, 0.067234, 0.028532};
 #elif KERNEL_SIZE == 11
-const uint STEP_COUNT = 5u;
-const float WEIGHTS[STEP_COUNT + 1u] = {0.198596, 0.175713, 0.121703, 0.065984, 0.028002, 0.0093};
+const U32 STEP_COUNT = 5u;
+const F32 WEIGHTS[STEP_COUNT + 1u] = {0.198596, 0.175713, 0.121703, 0.065984, 0.028002, 0.0093};
 #endif
 
 // Imagine you are sampling a 3x3 area:
@@ -35,6 +35,6 @@ const float WEIGHTS[STEP_COUNT + 1u] = {0.198596, 0.175713, 0.121703, 0.065984,
 // +-+-+-+
 // It's BOX_WEIGHTS[0] for the a texels. BOX_WEIGHTS[1] for the b texels. BOX_WEIGHTS[2] for the c texels.
 // Note: BOX_WEIGHTS[0] + BOX_WEIGHTS[1] * 4 + BOX_WEIGHTS[2] * 4 == 1.0
-const vec3 BOX_WEIGHTS = vec3(0.25, 0.125, 0.0625);
+const Vec3 BOX_WEIGHTS = Vec3(0.25, 0.125, 0.0625);
 
 #endif

+ 3 - 3
programs/GaussianBlurCompute.ankiprog → shaders/GaussianBlurCompute.ankiprog

@@ -14,8 +14,8 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="comp">
 			<inputs>
-				<input name="TEXTURE_SIZE" type="uvec2" const="1"/>
-                <input name="WORKGROUP_SIZE" type="uvec2" const="1"/>
+				<input name="TEXTURE_SIZE" type="UVec2" const="1"/>
+                <input name="WORKGROUP_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
@@ -27,7 +27,7 @@ http://www.anki3d.org/LICENSE
 #	define BOX 1
 #endif
 
-#include "shaders/GaussianBlur.glsl"
+#include <shaders/GaussianBlur.glsl>
 			]]></source>
 		</shader>
 	</shaders>

+ 19 - 19
programs/Irradiance.ankiprog → shaders/Irradiance.ankiprog

@@ -8,14 +8,14 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="ENV_TEX_TILE_SIZE" type="uint" const="1"/>
-				<input name="ENV_TEX_MIP" type="float" const="1"/>
+				<input name="ENV_TEX_TILE_SIZE" type="U32" const="1"/>
+				<input name="ENV_TEX_MIP" type="F32" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
@@ -23,10 +23,10 @@ http://www.anki3d.org/LICENSE
 // It's almost the same as http://www.codinglabs.net/article_physically_based_rendering.aspx
 // It's more bright though
 
-#include "shaders/Functions.glsl"
+#include <shaders/Functions.glsl>
 
-layout(location = 0) in vec2 in_uv;
-layout(location = 0) out vec3 out_color;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 0) out Vec3 out_color;
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform samplerCubeArray u_envTex;
 
@@ -34,35 +34,35 @@ layout(ANKI_UBO_BINDING(0, 0)) uniform u0_
 {
 	// x: The face index to render to
 	// y: The array index to read from the u_envTex
-	uvec4 u_faceIdxArrayIdxPad2;
+	UVec4 u_faceIdxArrayIdxPad2;
 };
 
 // Integrate the environment map to compute the irradiance for a single fragment
 void main()
 {
-	uint face = u_faceIdxArrayIdxPad2.x;
-	float texArrIdx = float(u_faceIdxArrayIdxPad2.y);
+	U32 face = u_faceIdxArrayIdxPad2.x;
+	F32 texArrIdx = F32(u_faceIdxArrayIdxPad2.y);
 
 	// Get the r coordinate of the current face and fragment
-	vec3 ri = getCubemapDirection(UV_TO_NDC(in_uv), face);
+	Vec3 ri = getCubemapDirection(UV_TO_NDC(in_uv), face);
 
-	vec3 outCol = vec3(0.0);
-	float weight = EPSILON;
+	Vec3 outCol = Vec3(0.0);
+	F32 weight = EPSILON;
 
 	// For all the faces and texels of the environment map calculate a color sum
-	for(uint f = 0u; f < 6u; ++f)
+	for(U32 f = 0u; f < 6u; ++f)
 	{
-		for(uint i = 0u; i < ENV_TEX_TILE_SIZE; ++i)
+		for(U32 i = 0u; i < ENV_TEX_TILE_SIZE; ++i)
 		{
-			for(uint j = 0u; j < ENV_TEX_TILE_SIZE; ++j)
+			for(U32 j = 0u; j < ENV_TEX_TILE_SIZE; ++j)
 			{
-				vec2 uv = vec2(j, i) / float(ENV_TEX_TILE_SIZE);
-				vec3 r = getCubemapDirection(UV_TO_NDC(uv), f);
+				Vec2 uv = Vec2(j, i) / F32(ENV_TEX_TILE_SIZE);
+				Vec3 r = getCubemapDirection(UV_TO_NDC(uv), f);
 
-				float lambert = dot(r, ri);
+				F32 lambert = dot(r, ri);
 				if(lambert > 0.0)
 				{
-					vec3 col = textureLod(u_envTex, vec4(r, texArrIdx), ENV_TEX_MIP).rgb;
+					Vec3 col = textureLod(u_envTex, Vec4(r, texArrIdx), ENV_TEX_MIP).rgb;
 
 					outCol += col * lambert;
 					weight += lambert;

+ 68 - 0
shaders/LensFlareSprite.ankiprog

@@ -0,0 +1,68 @@
+<!-- 
+Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+<shaderProgram>
+	<shaders>
+		<shader type="vert">
+			<inputs>
+				<input name="MAX_SPRITES" type="U32" const="1"/>
+			</inputs>
+
+			<source><![CDATA[
+#include <shaders/Common.glsl>
+#include <shaders/glsl_cpp_common/LensFlareSprite.h>
+
+// The block contains data for all flares
+layout(std140, ANKI_UBO_BINDING(0, 0)) uniform _blk
+{
+	LensFlareSprite u_sprites[MAX_SPRITES];
+};
+
+layout(location = 0) out Vec3 out_uv;
+layout(location = 1) flat out Vec4 out_color;
+
+out gl_PerVertex
+{
+	Vec4 gl_Position;
+};
+
+void main()
+{
+	Vec2 position = UV_TO_NDC(Vec2(gl_VertexID & 1, gl_VertexID >> 1));
+
+	LensFlareSprite sprite = u_sprites[gl_InstanceID];
+
+	// Write tex coords of the 2D array texture
+	out_uv = Vec3((position * 0.5) + 0.5, sprite.m_depthPad3.x);
+
+	Vec4 posScale = sprite.m_posScale;
+	gl_Position = Vec4(position * posScale.zw + posScale.xy, 0.0, 1.0);
+
+	out_color = sprite.m_color;
+}
+			]]></source>
+		</shader>
+
+		<shader type="frag">
+			<source><![CDATA[
+#include <shaders/Common.glsl>
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2DArray u_tex;
+
+layout(location = 0) in Vec3 in_uv;
+layout(location = 1) flat in Vec4 in_color;
+
+layout(location = 0) out Vec4 out_color;
+
+void main()
+{
+	Vec4 col = texture(u_tex, in_uv);
+	out_color = col * in_color;
+}
+			]]></source>
+		</shader>
+	</shaders>
+</shaderProgram>

+ 20 - 20
programs/LensFlareUpdateIndirectInfo.ankiprog → shaders/LensFlareUpdateIndirectInfo.ankiprog

@@ -6,29 +6,29 @@ http://www.anki3d.org/LICENSE
 -->
 <shaderProgram>
 	<inputs>
-		<input name="IN_DEPTH_MAP_SIZE" type="vec2" const="1"/>
+		<input name="IN_DEPTH_MAP_SIZE" type="Vec2" const="1"/>
 	</inputs>
 
 	<shaders>
 		<shader type="comp">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
-const uint WORKGROUP_SIZE = 8;
+const U32 WORKGROUP_SIZE = 8;
 layout(local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;
 
 struct DrawArraysIndirectInfo
 {
-	uint count;
-	uint instanceCount;
-	uint first;
-	uint baseInstance;
+	U32 count;
+	U32 instanceCount;
+	U32 first;
+	U32 baseInstance;
 };
 
 layout(ANKI_SS_BINDING(0, 0), std430, row_major) readonly buffer ss0_
 {
-	mat4 u_mvp;
-	vec4 u_flarePositions[];
+	Mat4 u_mvp;
+	Vec4 u_flarePositions[];
 };
 
 layout(ANKI_SS_BINDING(0, 1), std430) writeonly buffer ss1_
@@ -38,7 +38,7 @@ layout(ANKI_SS_BINDING(0, 1), std430) writeonly buffer ss1_
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthMap;
 
-shared uint s_maxDepth;
+shared U32 s_maxDepth;
 
 void main()
 {
@@ -51,19 +51,19 @@ void main()
 	barrier();
 	
 	// Project the flare
-	uint flareIdx = gl_WorkGroupID.x;
-	vec4 posClip =  u_mvp * u_flarePositions[flareIdx];
-	vec3 posNdc = posClip.xyz / posClip.w;
-	float depth = posNdc.z;
+	U32 flareIdx = gl_WorkGroupID.x;
+	Vec4 posClip =  u_mvp * u_flarePositions[flareIdx];
+	Vec3 posNdc = posClip.xyz / posClip.w;
+	F32 depth = posNdc.z;
 
 	// Compute the UVs to sample the depth map
-	vec2 displacement = vec2(gl_LocalInvocationID.xy) - vec2(WORKGROUP_SIZE / 2u); // [-WORKGROUP_SIZE, WORKGROUP_SIZE]
-	const vec2 TEXEL_SIZE = 1.0 / IN_DEPTH_MAP_SIZE;
-	vec2 uv = NDC_TO_UV(posNdc.xy) + displacement * TEXEL_SIZE;
+	Vec2 displacement = Vec2(gl_LocalInvocationID.xy) - Vec2(WORKGROUP_SIZE / 2u); // [-WORKGROUP_SIZE, WORKGROUP_SIZE]
+	const Vec2 TEXEL_SIZE = 1.0 / IN_DEPTH_MAP_SIZE;
+	Vec2 uv = NDC_TO_UV(posNdc.xy) + displacement * TEXEL_SIZE;
 
 	// Sample and store depth
-	float refDepth = textureLod(u_depthMap, uv, 0.0).r;
-	atomicMax(s_maxDepth, uint(refDepth * float(MAX_U32)));
+	F32 refDepth = textureLod(u_depthMap, uv, 0.0).r;
+	atomicMax(s_maxDepth, U32(refDepth * F32(MAX_U32)));
 
 	// Sync
 	memoryBarrierShared();
@@ -71,7 +71,7 @@ void main()
 
 	if(gl_LocalInvocationIndex == 0)
 	{
-		float refDepth = float(s_maxDepth) / float(MAX_U32);
+		F32 refDepth = F32(s_maxDepth) / F32(MAX_U32);
 		u_indirectInfo[flareIdx].count = (depth > refDepth) ? 0u : 4u;
 
 		u_indirectInfo[flareIdx].instanceCount = 1u;

+ 70 - 70
shaders/LightFunctions.glsl

@@ -8,145 +8,145 @@
 #ifndef ANKI_SHADERS_LIGHT_FUNCTIONS_GLSL
 #define ANKI_SHADERS_LIGHT_FUNCTIONS_GLSL
 
-#include "shaders/Functions.glsl"
-#include "shaders/Pack.glsl"
+#include <shaders/Functions.glsl>
+#include <shaders/Pack.glsl>
 
-const float LIGHT_FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
-const uint SHADOW_SAMPLE_COUNT = 16;
-const float ESM_CONSTANT = 40.0;
+const F32 LIGHT_FRUSTUM_NEAR_PLANE = 0.1 / 4.0;
+const U32 SHADOW_SAMPLE_COUNT = 16;
+const F32 ESM_CONSTANT = 40.0;
 
 // Fresnel term unreal
-vec3 F_Unreal(vec3 specular, float VoH)
+Vec3 F_Unreal(Vec3 specular, F32 VoH)
 {
 	return specular + (1.0 - specular) * pow(2.0, (-5.55473 * VoH - 6.98316) * VoH);
 }
 
 // Fresnel Schlick: "An Inexpensive BRDF Model for Physically-Based Rendering"
 // It has lower VGRPs than F_Unreal
-vec3 F_Schlick(vec3 specular, float VoH)
+Vec3 F_Schlick(Vec3 specular, F32 VoH)
 {
-	float a = 1.0 - VoH;
-	float a2 = a * a;
-	float a5 = a2 * a2 * a; // a5 = a^5
+	F32 a = 1.0 - VoH;
+	F32 a2 = a * a;
+	F32 a5 = a2 * a2 * a; // a5 = a^5
 	return /*saturate(50.0 * specular.g) */ a5 + (1.0 - a5) * specular;
 }
 
 // D(n,h) aka NDF: GGX Trowbridge-Reitz
-float D_GGX(float roughness, float NoH)
+F32 D_GGX(F32 roughness, F32 NoH)
 {
-	float a = roughness * roughness;
-	float a2 = a * a;
+	F32 a = roughness * roughness;
+	F32 a2 = a * a;
 
-	float D = (NoH * a2 - NoH) * NoH + 1.0;
+	F32 D = (NoH * a2 - NoH) * NoH + 1.0;
 	return a2 / (PI * D * D);
 }
 
 // Visibility term: Geometric shadowing divided by BRDF denominator
-float V_Schlick(float roughness, float NoV, float NoL)
+F32 V_Schlick(F32 roughness, F32 NoV, F32 NoL)
 {
-	float k = (roughness * roughness) * 0.5;
-	float Vis_SchlickV = NoV * (1.0 - k) + k;
-	float Vis_SchlickL = NoL * (1.0 - k) + k;
+	F32 k = (roughness * roughness) * 0.5;
+	F32 Vis_SchlickV = NoV * (1.0 - k) + k;
+	F32 Vis_SchlickL = NoL * (1.0 - k) + k;
 	return 0.25 / (Vis_SchlickV * Vis_SchlickL);
 }
 
-vec3 envBRDF(vec3 specular, float roughness, sampler2D integrationLut, float NoV)
+Vec3 envBRDF(Vec3 specular, F32 roughness, sampler2D integrationLut, F32 NoV)
 {
-	float a = roughness * roughness;
-	float a2 = a * a;
-	vec2 envBRDF = textureLod(integrationLut, vec2(a2, NoV), 0.0).xy;
+	F32 a = roughness * roughness;
+	F32 a2 = a * a;
+	Vec2 envBRDF = textureLod(integrationLut, Vec2(a2, NoV), 0.0).xy;
 	return specular * envBRDF.x + /*min(1.0, 50.0 * specular.g) */ envBRDF.y;
 }
 
-vec3 diffuseLambert(vec3 diffuse)
+Vec3 diffuseLambert(Vec3 diffuse)
 {
 	return diffuse * (1.0 / PI);
 }
 
 // Performs BRDF specular lighting
-vec3 computeSpecularColorBrdf(GbufferInfo gbuffer, vec3 viewDir, vec3 frag2Light)
+Vec3 computeSpecularColorBrdf(GbufferInfo gbuffer, Vec3 viewDir, Vec3 frag2Light)
 {
-	vec3 H = normalize(frag2Light + viewDir);
+	Vec3 H = normalize(frag2Light + viewDir);
 
-	float NoL = max(EPSILON, dot(gbuffer.normal, frag2Light));
-	float VoH = max(EPSILON, dot(viewDir, H));
-	float NoH = max(EPSILON, dot(gbuffer.normal, H));
-	float NoV = max(EPSILON, dot(gbuffer.normal, viewDir));
+	F32 NoL = max(EPSILON, dot(gbuffer.m_normal, frag2Light));
+	F32 VoH = max(EPSILON, dot(viewDir, H));
+	F32 NoH = max(EPSILON, dot(gbuffer.m_normal, H));
+	F32 NoV = max(EPSILON, dot(gbuffer.m_normal, viewDir));
 
 	// F
 #if 0
-	vec3 F = F_Unreal(gbuffer.specular, VoH);
+	Vec3 F = F_Unreal(gbuffer.m_specular, VoH);
 #else
-	vec3 F = F_Schlick(gbuffer.specular, VoH);
+	Vec3 F = F_Schlick(gbuffer.m_specular, VoH);
 #endif
 
 	// D
-	float D = D_GGX(gbuffer.roughness, NoH);
+	F32 D = D_GGX(gbuffer.m_roughness, NoH);
 
 	// Vis
-	float V = V_Schlick(gbuffer.roughness, NoV, NoL);
+	F32 V = V_Schlick(gbuffer.m_roughness, NoV, NoL);
 
 	return F * (V * D);
 }
 
-float computeSpotFactor(vec3 l, float outerCos, float innerCos, vec3 spotDir)
+F32 computeSpotFactor(Vec3 l, F32 outerCos, F32 innerCos, Vec3 spotDir)
 {
-	float costheta = -dot(l, spotDir);
-	float spotFactor = smoothstep(outerCos, innerCos, costheta);
+	F32 costheta = -dot(l, spotDir);
+	F32 spotFactor = smoothstep(outerCos, innerCos, costheta);
 	return spotFactor;
 }
 
-uint computeShadowSampleCount(const uint COUNT, float zVSpace)
+U32 computeShadowSampleCount(const U32 COUNT, F32 zVSpace)
 {
-	const float MAX_DISTANCE = 5.0;
+	const F32 MAX_DISTANCE = 5.0;
 
-	float z = max(zVSpace, -MAX_DISTANCE);
-	float sampleCountf = float(COUNT) + z * (float(COUNT) / MAX_DISTANCE);
+	F32 z = max(zVSpace, -MAX_DISTANCE);
+	F32 sampleCountf = F32(COUNT) + z * (F32(COUNT) / MAX_DISTANCE);
 	sampleCountf = max(sampleCountf, 1.0);
-	uint sampleCount = uint(sampleCountf);
+	U32 sampleCount = U32(sampleCountf);
 
 	return sampleCount;
 }
 
-float computeShadowFactorSpot(mat4 lightProjectionMat, vec3 worldPos, float distance, sampler2D spotMapArr)
+F32 computeShadowFactorSpot(Mat4 lightProjectionMat, Vec3 worldPos, F32 distance, sampler2D spotMapArr)
 {
-	vec4 texCoords4 = lightProjectionMat * vec4(worldPos, 1.0);
-	vec3 texCoords3 = texCoords4.xyz / texCoords4.w;
+	Vec4 texCoords4 = lightProjectionMat * Vec4(worldPos, 1.0);
+	Vec3 texCoords3 = texCoords4.xyz / texCoords4.w;
 
-	const float near = LIGHT_FRUSTUM_NEAR_PLANE;
-	const float far = distance;
+	const F32 near = LIGHT_FRUSTUM_NEAR_PLANE;
+	const F32 far = distance;
 
-	float linearDepth = linearizeDepth(texCoords3.z, near, far);
+	F32 linearDepth = linearizeDepth(texCoords3.z, near, far);
 
-	float shadowFactor = textureLod(spotMapArr, texCoords3.xy, 0.0).r;
+	F32 shadowFactor = textureLod(spotMapArr, texCoords3.xy, 0.0).r;
 
 	return saturate(exp(ESM_CONSTANT * (shadowFactor - linearDepth)));
 }
 
-float computeShadowFactorOmni(vec3 frag2Light, float radius, uvec2 atlasTiles, float tileSize, sampler2D shadowMap)
+F32 computeShadowFactorOmni(Vec3 frag2Light, F32 radius, UVec2 atlasTiles, F32 tileSize, sampler2D shadowMap)
 {
-	vec3 dir = -frag2Light;
-	vec3 dirabs = abs(dir);
-	float dist = max(dirabs.x, max(dirabs.y, dirabs.z));
+	Vec3 dir = -frag2Light;
+	Vec3 dirabs = abs(dir);
+	F32 dist = max(dirabs.x, max(dirabs.y, dirabs.z));
 
-	const float near = LIGHT_FRUSTUM_NEAR_PLANE;
-	const float far = radius;
+	const F32 near = LIGHT_FRUSTUM_NEAR_PLANE;
+	const F32 far = radius;
 
-	float linearDepth = (dist - near) / (far - near);
+	F32 linearDepth = (dist - near) / (far - near);
 
 	// Read tex
-	float shadowFactor;
+	F32 shadowFactor;
 	{
 		// Convert cube coords
-		uint faceIdxu;
-		vec2 uv = convertCubeUvsu(dir, faceIdxu);
+		U32 faceIdxu;
+		Vec2 uv = convertCubeUvsu(dir, faceIdxu);
 
 		// Compute atlas tile
-		atlasTiles >>= uvec2(faceIdxu * 5u);
-		atlasTiles &= uvec2(31u);
+		atlasTiles >>= UVec2(faceIdxu * 5u);
+		atlasTiles &= UVec2(31u);
 
 		// Compute UV
-		uv = (uv + vec2(atlasTiles)) * tileSize;
+		uv = (uv + Vec2(atlasTiles)) * tileSize;
 
 		// Sample
 		shadowFactor = textureLod(shadowMap, uv, 0.0).r;
@@ -157,36 +157,36 @@ float computeShadowFactorOmni(vec3 frag2Light, float radius, uvec2 atlasTiles, f
 
 // Compute the cubemap texture lookup vector given the reflection vector (r) the radius squared of the probe (R2) and
 // the frag pos in sphere space (f)
-vec3 computeCubemapVecAccurate(in vec3 r, in float R2, in vec3 f)
+Vec3 computeCubemapVecAccurate(in Vec3 r, in F32 R2, in Vec3 f)
 {
 	// Compute the collision of the r to the inner part of the sphere
 	// From now on we work on the sphere's space
 
 	// Project the center of the sphere (it's zero now since we are in sphere space) in ray "f,r"
-	vec3 p = f - r * dot(f, r);
+	Vec3 p = f - r * dot(f, r);
 
 	// The collision to the sphere is point x where x = p + T * r
 	// Because of the pythagorean theorem: R^2 = dot(p, p) + dot(T * r, T * r)
 	// solving for T, T = R / |p|
 	// then x becomes x = sqrt(R^2 - dot(p, p)) * r + p;
-	float pp = dot(p, p);
+	F32 pp = dot(p, p);
 	pp = min(pp, R2);
-	float sq = sqrt(R2 - pp);
-	vec3 x = p + sq * r;
+	F32 sq = sqrt(R2 - pp);
+	Vec3 x = p + sq * r;
 
 	return x;
 }
 
 // Cheap version of computeCubemapVecAccurate
-vec3 computeCubemapVecCheap(in vec3 r, in float R2, in vec3 f)
+Vec3 computeCubemapVecCheap(in Vec3 r, in F32 R2, in Vec3 f)
 {
 	return r;
 }
 
-float computeAttenuationFactor(float lightRadius, vec3 frag2Light)
+F32 computeAttenuationFactor(F32 lightRadius, Vec3 frag2Light)
 {
-	float fragLightDist = dot(frag2Light, frag2Light);
-	float att = 1.0 - fragLightDist * lightRadius;
+	F32 fragLightDist = dot(frag2Light, frag2Light);
+	F32 att = 1.0 - fragLightDist * lightRadius;
 	att = max(0.0, att);
 	return att * att;
 }

+ 186 - 0
shaders/LightShading.ankiprog

@@ -0,0 +1,186 @@
+<!-- 
+Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+<shaderProgram>
+	<inputs>
+		<input name="CLUSTER_COUNT_X" type="U32" const="1"/>
+		<input name="CLUSTER_COUNT_Y" type="U32" const="1"/>
+		<input name="CLUSTER_COUNT_Z" type="U32" const="1"/>
+		<input name="CLUSTER_COUNT" type="U32" const="1"/>
+		<input name="IR_MIPMAP_COUNT" type="U32" const="1"/>
+	</inputs>
+
+	<shaders>
+		<shader type="vert">
+			<source><![CDATA[
+#include <shaders/Common.glsl>
+
+layout(location = 0) out Vec2 out_uv;
+layout(location = 1) out Vec2 out_clusterIJ;
+
+out gl_PerVertex
+{
+	Vec4 gl_Position;
+};
+
+void main()
+{
+	out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
+	Vec2 pos = out_uv * 2.0 - 1.0;
+	gl_Position = Vec4(pos, 0.0, 1.0);
+
+	out_clusterIJ = Vec2(CLUSTER_COUNT_X, CLUSTER_COUNT_Y) * out_uv;
+}
+			]]></source>
+		</shader>
+
+		<shader type="frag">
+			<source><![CDATA[
+#include <shaders/Pack.glsl>
+#include <shaders/glsl_cpp_common/Clusterer.h>
+#include <shaders/Functions.glsl>
+
+#define LIGHT_SET 0
+#define LIGHT_SS_BINDING 0
+#define LIGHT_UBO_BINDING 0
+#define LIGHT_TEX_BINDING 5
+#define LIGHT_LIGHTS
+#define LIGHT_COMMON_UNIS
+#include <shaders/ClusterLightCommon.glsl>
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msRt0;
+layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_msRt1;
+layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_msRt2;
+layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_msDepthRt;
+layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_indirectRt;
+
+layout(location = 0) in Vec2 in_uv;
+layout(location = 1) in Vec2 in_clusterIJ;
+
+layout(location = 0) out Vec3 out_color;
+
+const F32 SUBSURFACE_MIN = 0.05;
+
+// Common code for lighting
+#define LIGHTING_COMMON_BRDF() \
+	Vec3 frag2Light = light.m_posRadius.xyz - worldPos; \
+	Vec3 l = normalize(frag2Light); \
+	Vec3 specC = computeSpecularColorBrdf(gbuffer, viewDir, l); \
+	Vec3 diffC = diffuseLambert(gbuffer.m_diffuse); \
+	F32 att = computeAttenuationFactor(light.m_posRadius.w, frag2Light); \
+	F32 lambert = max(0.0, dot(gbuffer.m_normal, l));
+
+void main()
+{
+	F32 depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
+	Vec2 ndc = UV_TO_NDC(in_uv);
+
+	// Get world position
+	Vec4 worldPos4 = u_invViewProjMat * Vec4(ndc, depth, 1.0);
+	Vec3 worldPos = worldPos4.xyz / worldPos4.w;
+
+	// Get first light index
+	U32 idxOffset;
+	{
+		U32 k = computeClusterK(u_clustererMagic, worldPos);
+		U32 clusterIdx = 
+			k * (CLUSTER_COUNT_X * CLUSTER_COUNT_Y) + U32(in_clusterIJ.y) * CLUSTER_COUNT_X + U32(in_clusterIJ.x);
+
+		idxOffset = u_clusters[clusterIdx];
+	}
+
+	// Decode GBuffer
+	GbufferInfo gbuffer;
+	readGBuffer(u_msRt0, u_msRt1, u_msRt2, in_uv, 0.0, gbuffer);
+	gbuffer.m_subsurface = max(gbuffer.m_subsurface, SUBSURFACE_MIN);
+
+	// Ambient and emissive color
+	out_color = gbuffer.m_diffuse * gbuffer.m_emission;
+
+	// Indirect
+	out_color += textureLod(u_indirectRt, in_uv, 0.0).rgb;
+
+	// Skip decals
+	U32 count = u_lightIndices[idxOffset];
+	idxOffset += count + 1u;
+
+	// Point lights
+	Vec3 viewDir = normalize(u_cameraPos - worldPos);
+	count = u_lightIndices[idxOffset++];
+	U32 idxOffsetEnd = idxOffset + count;
+	ANKI_LOOP while(idxOffset < idxOffsetEnd)
+	{
+		PointLight light = u_pointLights[u_lightIndices[idxOffset++]];
+
+		LIGHTING_COMMON_BRDF();
+
+		if(light.m_diffuseColorTileSize.w >= 0.0)
+		{
+			F32 shadow = computeShadowFactorOmni(frag2Light, 
+				light.m_radiusPad1.x, 
+				light.m_atlasTiles, 
+				light.m_diffuseColorTileSize.w,
+				u_shadowTex);
+			lambert *= shadow;
+		}
+
+		out_color += (diffC + specC) * light.m_diffuseColorTileSize.rgb * (att * max(gbuffer.m_subsurface, lambert));
+	}
+
+	// Spot lights
+	count = u_lightIndices[idxOffset++];
+	idxOffsetEnd = idxOffset + count;
+	ANKI_LOOP while(idxOffset < idxOffsetEnd)
+	{
+		SpotLight light = u_spotLights[u_lightIndices[idxOffset++]];
+
+		LIGHTING_COMMON_BRDF();
+
+		F32 spot = computeSpotFactor(
+			l, light.m_outerCosInnerCos.x, light.m_outerCosInnerCos.y, light.m_lightDirRadius.xyz);
+
+		F32 shadowmapLayerIdx = light.m_diffuseColorShadowmapId.w;
+		if(shadowmapLayerIdx >= 0.0)
+		{
+			F32 shadow = computeShadowFactorSpot(
+				light.m_texProjectionMat, worldPos, light.m_lightDirRadius.w, u_shadowTex);
+			lambert *= shadow;
+		}
+
+		out_color += 
+			(diffC + specC) * light.m_diffuseColorShadowmapId.rgb * (att * spot * max(gbuffer.m_subsurface, lambert));
+	}
+
+#if 0
+	count = scount;
+	if(count == 0)
+	{
+		out_color = Vec3(0.0, 0.0, 0.0);
+	}
+	else if(count == 1)
+	{
+		out_color = Vec3(1.0, 0.0, 0.0);
+	}
+	else if(count == 2)
+	{
+		out_color = Vec3(0.0, 1.0, 0.0);
+	}
+	else if(count == 3)
+	{
+		out_color = Vec3(0.0, 0.0, 1.0);
+	}
+	else
+	{
+		out_color = Vec3(1.0, 1.0, 1.0);
+	}
+#endif
+}
+			]]></source>
+		</shader>
+	</shaders>
+
+</shaderProgram>
+

+ 19 - 19
programs/LumaAwareBlur.ankiprog → shaders/LumaAwareBlur.ankiprog

@@ -14,42 +14,42 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="TEXTURE_SIZE" type="uvec2" const="1"/>
+				<input name="TEXTURE_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/GaussianBlurCommon.glsl"
-#include "shaders/Tonemapping.glsl"
+#include <shaders/GaussianBlurCommon.glsl>
+#include <shaders/Tonemapping.glsl>
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex; ///< Input FAI
 
-layout(location = 0) in vec2 in_uv;
+layout(location = 0) in Vec2 in_uv;
 
 // Determine color type
 #if COLOR_COMPONENTS == 4
-#	define COL_TYPE vec4
+#	define COL_TYPE Vec4
 #	define TEX_FETCH rgba
 #elif COLOR_COMPONENTS == 3
-#	define COL_TYPE vec3
+#	define COL_TYPE Vec3
 #	define TEX_FETCH rgb
 #elif COLOR_COMPONENTS == 1
-#	define COL_TYPE float
+#	define COL_TYPE F32
 #	define TEX_FETCH r
 #else
 #	error See file
 #endif
 
-float computeLumaWeight(float refLuma, COL_TYPE col)
+F32 computeLumaWeight(F32 refLuma, COL_TYPE col)
 {
-	float l = computeLuminance(col);
-	float diff = abs(refLuma - l);
-	float weight = 1.0 / (EPSILON + diff);
+	F32 l = computeLuminance(col);
+	F32 diff = abs(refLuma - l);
+	F32 weight = 1.0 / (EPSILON + diff);
 	return weight;
 }
 
@@ -59,21 +59,21 @@ layout(location = 0) out COL_TYPE out_color;
 void main()
 {
 #if HORIZONTAL
-	const vec2 TEXEL_SIZE = vec2(1.0 / float(TEXTURE_SIZE.x), 0.0);
+	const Vec2 TEXEL_SIZE = Vec2(1.0 / F32(TEXTURE_SIZE.x), 0.0);
 #else
-	const vec2 TEXEL_SIZE = vec2(0.0, 1.0 / float(TEXTURE_SIZE.y));
+	const Vec2 TEXEL_SIZE = Vec2(0.0, 1.0 / F32(TEXTURE_SIZE.y));
 #endif
 
 	COL_TYPE col = texture(u_tex, in_uv).TEX_FETCH;
 	out_color = col;
-	float refLuma = computeLuminance(col);
-	float weight = 1.0;
-	vec2 texCoordOffset = 1.5 * TEXEL_SIZE;
+	F32 refLuma = computeLuminance(col);
+	F32 weight = 1.0;
+	Vec2 texCoordOffset = 1.5 * TEXEL_SIZE;
 
-	for(uint i = 0u; i < STEP_COUNT; ++i)
+	for(U32 i = 0u; i < STEP_COUNT; ++i)
 	{
 		COL_TYPE col = texture(u_tex, in_uv + texCoordOffset).TEX_FETCH;
-		float w = computeLumaWeight(refLuma, col);
+		F32 w = computeLumaWeight(refLuma, col);
 		out_color += col * w;
 		weight += w;
 

+ 75 - 75
shaders/Pack.glsl

@@ -6,24 +6,24 @@
 #ifndef ANKI_SHADERS_PACK_GLSL
 #define ANKI_SHADERS_PACK_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 /// Pack 3D normal to 2D vector
 /// See the clean code in comments in revision < r467
-vec2 packNormal(in vec3 normal)
+Vec2 packNormal(in Vec3 normal)
 {
-	const float SCALE = 1.7777;
-	float scalar1 = (normal.z + 1.0) * (SCALE * 2.0);
+	const F32 SCALE = 1.7777;
+	F32 scalar1 = (normal.z + 1.0) * (SCALE * 2.0);
 	return normal.xy / scalar1 + 0.5;
 }
 
 /// Reverse the packNormal
-vec3 unpackNormal(in vec2 enc)
+Vec3 unpackNormal(in Vec2 enc)
 {
-	const float SCALE = 1.7777;
-	vec2 nn = enc * (2.0 * SCALE) - SCALE;
-	float g = 2.0 / (dot(nn.xy, nn.xy) + 1.0);
-	vec3 normal;
+	const F32 SCALE = 1.7777;
+	Vec2 nn = enc * (2.0 * SCALE) - SCALE;
+	F32 g = 2.0 / (dot(nn.xy, nn.xy) + 1.0);
+	Vec3 normal;
 	normal.xy = g * nn.xy;
 	normal.z = g - 1.0;
 	return normalize(normal);
@@ -31,11 +31,11 @@ vec3 unpackNormal(in vec2 enc)
 
 // See http://johnwhite3d.blogspot.no/2017/10/signed-octahedron-normal-encoding.html
 // Result in [0.0, 1.0]
-vec3 signedOctEncode(vec3 n)
+Vec3 signedOctEncode(Vec3 n)
 {
-	vec3 outn;
+	Vec3 outn;
 
-	vec3 nabs = abs(n);
+	Vec3 nabs = abs(n);
 	n /= nabs.x + nabs.y + nabs.z;
 
 	outn.y = n.y * 0.5 + 0.5;
@@ -47,9 +47,9 @@ vec3 signedOctEncode(vec3 n)
 }
 
 // See http://johnwhite3d.blogspot.no/2017/10/signed-octahedron-normal-encoding.html
-vec3 signedOctDecode(vec3 n)
+Vec3 signedOctDecode(Vec3 n)
 {
-	vec3 outn;
+	Vec3 outn;
 
 	outn.x = n.x - n.y;
 	outn.y = n.x + n.y - 1.0;
@@ -63,20 +63,20 @@ vec3 signedOctDecode(vec3 n)
 #if GL_ES || __VERSION__ < 400
 
 // Vectorized version. See clean one at <= r1048
-uint packUnorm4x8(in vec4 v)
+U32 packUnorm4x8(in Vec4 v)
 {
-	vec4 a = clamp(v, 0.0, 1.0) * 255.0;
-	uvec4 b = uvec4(a) << uvec4(0U, 8U, 16U, 24U);
-	uvec2 c = b.xy | b.zw;
+	Vec4 a = clamp(v, 0.0, 1.0) * 255.0;
+	UVec4 b = UVec4(a) << UVec4(0U, 8U, 16U, 24U);
+	UVec2 c = b.xy | b.zw;
 	return c.x | c.y;
 }
 
 // Vectorized version. See clean one at <= r1048
-vec4 unpackUnorm4x8(in highp uint u)
+Vec4 unpackUnorm4x8(in highp U32 u)
 {
-	uvec4 a = uvec4(u) >> uvec4(0U, 8U, 16U, 24U);
-	uvec4 b = a & uvec4(0xFFU);
-	vec4 c = vec4(b);
+	UVec4 a = UVec4(u) >> UVec4(0U, 8U, 16U, 24U);
+	UVec4 b = a & UVec4(0xFFU);
+	Vec4 c = Vec4(b);
 
 	return c * (1.0 / 255.0);
 }
@@ -84,105 +84,105 @@ vec4 unpackUnorm4x8(in highp uint u)
 
 // Convert from RGB to YCbCr.
 // The RGB should be in [0, 1] and the output YCbCr will be in [0, 1] as well.
-vec3 rgbToYCbCr(in vec3 rgb)
+Vec3 rgbToYCbCr(in Vec3 rgb)
 {
-	float y = dot(rgb, vec3(0.299, 0.587, 0.114));
-	float cb = 0.5 + dot(rgb, vec3(-0.168736, -0.331264, 0.5));
-	float cr = 0.5 + dot(rgb, vec3(0.5, -0.418688, -0.081312));
-	return vec3(y, cb, cr);
+	F32 y = dot(rgb, Vec3(0.299, 0.587, 0.114));
+	F32 cb = 0.5 + dot(rgb, Vec3(-0.168736, -0.331264, 0.5));
+	F32 cr = 0.5 + dot(rgb, Vec3(0.5, -0.418688, -0.081312));
+	return Vec3(y, cb, cr);
 }
 
 // Convert the output of rgbToYCbCr back to RGB.
-vec3 yCbCrToRgb(in vec3 ycbcr)
+Vec3 yCbCrToRgb(in Vec3 ycbcr)
 {
-	float cb = ycbcr.y - 0.5;
-	float cr = ycbcr.z - 0.5;
-	float y = ycbcr.x;
-	float r = 1.402 * cr;
-	float g = -0.344 * cb - 0.714 * cr;
-	float b = 1.772 * cb;
-	return vec3(r, g, b) + y;
+	F32 cb = ycbcr.y - 0.5;
+	F32 cr = ycbcr.z - 0.5;
+	F32 y = ycbcr.x;
+	F32 r = 1.402 * cr;
+	F32 g = -0.344 * cb - 0.714 * cr;
+	F32 b = 1.772 * cb;
+	return Vec3(r, g, b) + y;
 }
 
-// Pack a vec2 to a single float.
+// Pack a Vec2 to a single F32.
 // comp should be in [0, 1] and the output will be in [0, 1].
-float packUnorm2ToUnorm1(in vec2 comp)
+F32 packUnorm2ToUnorm1(in Vec2 comp)
 {
-	return dot(round(comp * 15.0), vec2(1.0 / (255.0 / 16.0), 1.0 / 255.0));
+	return dot(round(comp * 15.0), Vec2(1.0 / (255.0 / 16.0), 1.0 / 255.0));
 }
 
-// Unpack a single float to vec2. Does the oposite of packUnorm2ToUnorm1.
-vec2 unpackUnorm1ToUnorm2(in float c)
+// Unpack a single F32 to Vec2. Does the oposite of packUnorm2ToUnorm1.
+Vec2 unpackUnorm1ToUnorm2(in F32 c)
 {
 #if 1
-	float temp = c * (255.0 / 16.0);
-	float a = floor(temp);
-	float b = temp - a; // b = fract(temp)
-	return vec2(a, b) * vec2(1.0 / 15.0, 16.0 / 15.0);
+	F32 temp = c * (255.0 / 16.0);
+	F32 a = floor(temp);
+	F32 b = temp - a; // b = fract(temp)
+	return Vec2(a, b) * Vec2(1.0 / 15.0, 16.0 / 15.0);
 #else
-	uint temp = uint(c * 255.0);
-	uint a = temp >> 4;
-	uint b = temp & 0xF;
-	return vec2(a, b) / 15.0;
+	U32 temp = U32(c * 255.0);
+	U32 a = temp >> 4;
+	U32 b = temp & 0xF;
+	return Vec2(a, b) / 15.0;
 #endif
 }
 
 // Max emission. Keep as low as possible
-const float MAX_EMISSION = 20.0;
+const F32 MAX_EMISSION = 20.0;
 
 // G-Buffer structure
 struct GbufferInfo
 {
-	vec3 diffuse;
-	vec3 specular;
-	vec3 normal;
-	float roughness;
-	float metallic;
-	float subsurface;
-	float emission;
+	Vec3 m_diffuse;
+	Vec3 m_specular;
+	Vec3 m_normal;
+	F32 m_roughness;
+	F32 m_metallic;
+	F32 m_subsurface;
+	F32 m_emission;
 };
 
 // Populate the G buffer
-void writeGBuffer(in GbufferInfo g, out vec4 rt0, out vec4 rt1, out vec4 rt2)
+void writeGBuffer(in GbufferInfo g, out Vec4 rt0, out Vec4 rt1, out Vec4 rt2)
 {
-	rt0 = vec4(g.diffuse, g.subsurface);
-	rt1 = vec4(g.roughness, g.metallic, g.specular.x, 0.0);
+	rt0 = Vec4(g.m_diffuse, g.m_subsurface);
+	rt1 = Vec4(g.m_roughness, g.m_metallic, g.m_specular.x, 0.0);
 
-	vec3 encNorm = signedOctEncode(g.normal);
-	rt2 = vec4(encNorm.xy, g.emission / MAX_EMISSION, encNorm.z);
+	Vec3 encNorm = signedOctEncode(g.m_normal);
+	rt2 = Vec4(encNorm.xy, g.m_emission / MAX_EMISSION, encNorm.z);
 }
 
 // Read from G-buffer
-void readNormalFromGBuffer(in sampler2D rt2, in vec2 uv, out vec3 normal)
+void readNormalFromGBuffer(in sampler2D rt2, in Vec2 uv, out Vec3 normal)
 {
 	normal = signedOctDecode(texture(rt2, uv).rga);
 }
 
 // Read from the G buffer
-void readGBuffer(in sampler2D rt0, in sampler2D rt1, in sampler2D rt2, in vec2 uv, in float lod, out GbufferInfo g)
+void readGBuffer(in sampler2D rt0, in sampler2D rt1, in sampler2D rt2, in Vec2 uv, in F32 lod, out GbufferInfo g)
 {
-	vec4 comp = textureLod(rt0, uv, 0.0);
-	g.diffuse = comp.xyz;
-	g.subsurface = comp.w;
+	Vec4 comp = textureLod(rt0, uv, 0.0);
+	g.m_diffuse = comp.xyz;
+	g.m_subsurface = comp.w;
 
 	comp = textureLod(rt1, uv, 0.0);
-	g.roughness = comp.x;
-	g.metallic = comp.y;
-	g.specular = vec3(comp.z);
+	g.m_roughness = comp.x;
+	g.m_metallic = comp.y;
+	g.m_specular = Vec3(comp.z);
 
 	comp = textureLod(rt2, uv, 0.0);
-	g.normal = signedOctDecode(comp.xyw);
-	g.emission = comp.z * MAX_EMISSION;
+	g.m_normal = signedOctDecode(comp.xyw);
+	g.m_emission = comp.z * MAX_EMISSION;
 
 	// Fix roughness
-	const float MIN_ROUGHNESS = 0.05;
-	g.roughness = g.roughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS;
+	const F32 MIN_ROUGHNESS = 0.05;
+	g.m_roughness = g.m_roughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS;
 
 	// Compute reflectance
-	g.specular = mix(g.specular, g.diffuse, g.metallic);
+	g.m_specular = mix(g.m_specular, g.m_diffuse, g.m_metallic);
 
 	// Compute diffuse
-	g.diffuse = g.diffuse - g.diffuse * g.metallic;
+	g.m_diffuse = g.m_diffuse - g.m_diffuse * g.m_metallic;
 }
 
 #endif

+ 6 - 6
shaders/QuadVert.glsl

@@ -3,19 +3,19 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
-layout(location = 0) out vec2 out_uv;
+layout(location = 0) out Vec2 out_uv;
 
 void main()
 {
-	out_uv = vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
-	vec2 pos = out_uv * 2.0 - 1.0;
+	out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
+	Vec2 pos = out_uv * 2.0 - 1.0;
 
-	gl_Position = vec4(pos, 0.0, 1.0);
+	gl_Position = Vec4(pos, 0.0, 1.0);
 }

+ 332 - 0
shaders/Reflections.ankiprog

@@ -0,0 +1,332 @@
+<!-- 
+Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+<shaderProgram>
+	<mutators>
+		<mutator name="VARIANT" values="0 1"/>
+	</mutators>
+
+	<shaders>
+		<shader type="comp">
+			<inputs>
+				<input name="FB_SIZE" type="UVec2" const="1"/>
+				<input name="WORKGROUP_SIZE" type="UVec2" const="1"/>
+				<input name="MAX_STEPS" type="U32" const="1"/>
+				<input name="LIGHT_BUFFER_MIP_COUNT" type="U32" const="1"/>
+				<input name="HIZ_MIP_COUNT" type="U32" const="1"/>
+				<input name="CLUSTER_COUNT_X" type="U32" const="1"/>
+				<input name="CLUSTER_COUNT_Y" type="U32" const="1"/>
+				<input name="CLUSTER_COUNT_Z" type="U32" const="1"/>
+				<input name="IR_MIPMAP_COUNT" type="U32" const="1"/>
+			</inputs>
+
+			<source><![CDATA[
+// if VARIANT==0 then the checkerboard pattern is (render on 'v'):
+// -----
+// |v| |
+// | |v|
+// -----
+
+
+#include <shaders/Functions.glsl>
+#include <shaders/Pack.glsl>
+#include <shaders/glsl_cpp_common/Clusterer.h>
+
+#define LIGHT_SET 0
+#define LIGHT_SS_BINDING 0
+#define LIGHT_UBO_BINDING 0
+#define LIGHT_TEX_BINDING 6
+#define LIGHT_INDIRECT
+#define LIGHT_COMMON_UNIS
+#include <shaders/ClusterLightCommon.glsl>
+
+const IVec2 HIZ_SIZE = IVec2(FB_SIZE) >> 1;
+
+layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_gbufferRt0;
+layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_gbufferRt1;
+layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_gbufferRt2;
+layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_depthRt;
+layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_hizRt;
+layout(ANKI_TEX_BINDING(0, 5)) uniform sampler2D u_lightBufferRt;
+
+layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D out_reflAndIndirect;
+
+// Temp buffer to hold the indirect color
+shared Vec3 s_pixels[WORKGROUP_SIZE.y][WORKGROUP_SIZE.x];
+
+#define u_normalMat Mat3(u_viewMat)
+
+Vec4 returnSslrColor(Vec3 raySample, F32 factor, F32 roughness)
+{
+	// Re-project previous frame
+	Vec4 v4 = u_prevViewProjMatMulInvViewProjMat * Vec4(UV_TO_NDC(raySample.xy), raySample.z, 1.0);
+	raySample.xy = NDC_TO_UV(v4.xy / v4.w);
+	raySample.xy = saturate(raySample.xy);
+
+	Vec2 ndc = abs(UV_TO_NDC(raySample.xy));
+	F32 contribution = max(ndc.x, ndc.y);
+	contribution = 1.0 - contribution * contribution;
+	contribution *= factor;
+
+	F32 lod = F32(LIGHT_BUFFER_MIP_COUNT - 1u) * roughness;
+	Vec3 color = textureLod(u_lightBufferRt, raySample.xy, lod).rgb;
+	return Vec4(color, contribution);
+}
+
+// Note: All calculations in view space
+Vec4 doSslr(Vec3 r, Vec3 n, Vec3 viewPos, Vec2 uv, F32 depth, F32 roughness)
+{
+	Vec3 p0 = viewPos;
+
+	// Check for view facing reflections [sakibsaikia]
+	Vec3 viewDir = normalize(viewPos);
+	F32 cameraFacingReflectionAttenuation = 1.0 - smoothstep(0.25, 0.5, dot(-viewDir, r));
+	if(cameraFacingReflectionAttenuation <= 0.0)
+	{
+		return Vec4(0.0);
+	}
+
+	// Compute an end point p1. This point is supposed to fall in front of the near plane. Add a small padding to near
+	// to avoid having p1 touching the near plane.
+	Vec3 p1 = p0 + r * (-p0.z - (u_near + 0.1));
+
+	// Start point
+	Vec3 start = Vec3(uv, depth);
+
+	// Project end point
+	Vec4 end4 = u_projMat * Vec4(p1, 1.0);
+	Vec3 end = end4.xyz / end4.w;
+	end.xy = NDC_TO_UV(end.xy);
+
+	// Compute the ray and step size
+	Vec3 ray = end - start;
+	Vec2 texelDims = abs(ray.xy) * Vec2(HIZ_SIZE);
+	F32 stepSize = length(ray.xy) / max(texelDims.x, texelDims.y);
+	ray = normalize(ray);
+
+	// Compute step
+	const U32 BIG_STEP_SKIP = 32u;
+	U32 stepSkip = BIG_STEP_SKIP;
+
+	U32 l = gl_GlobalInvocationID.x & 1u;
+	U32 j = gl_GlobalInvocationID.y & 1u;
+	const U32 STEPS_ARR[4] = U32[](6u, 25u, 13u, 18u);
+	U32 step = STEPS_ARR[l * 2u + j];
+	
+	// Iterate
+	bool found = false;
+	Vec3 raySample;
+	ANKI_LOOP for(U32 iterations = 0u; iterations < MAX_STEPS; ++iterations)
+	{
+		raySample = start + ray * (F32(step) * stepSize);
+
+		// Check if it's out of the view
+		if(raySample.x <= 0.0 || raySample.y <= 0.0 || raySample.x >= 1.0 || raySample.y >= 1.0)
+		{
+			break;
+		}
+
+		F32 depth = textureLod(u_hizRt, raySample.xy, 0.0).r;
+
+		bool hit = raySample.z - depth >= 0.0;
+		if(!hit)
+		{
+			step += stepSkip;
+		}
+		else if(stepSkip > 1)
+		{
+			step -= BIG_STEP_SKIP - 1u;
+			stepSkip = 1u;
+		}
+		else
+		{
+			found = true;
+			break;
+		}
+	}
+
+	//return Vec4(heatmap(F32(iterations) / F32(MAX_STEPS)), 1.0);
+
+	if(found)
+	{
+		return returnSslrColor(raySample, cameraFacingReflectionAttenuation, roughness);
+	}
+	else
+	{
+		return Vec4(0.0);
+	}
+}
+
+// Note: All calculations in world space
+void readReflectionsAndIrradianceFromProbes(
+	U32 idxOffset, Vec3 worldPos, Vec3 normal, F32 roughness, out Vec3 specIndirect, out Vec3 diffIndirect)
+{
+	specIndirect = Vec3(0.0);
+	diffIndirect = Vec3(0.0);
+
+	Vec3 viewDir = normalize(worldPos - u_cameraPos);
+	Vec3 reflDir = reflect(viewDir, normal);
+
+	F32 reflLod = F32(IR_MIPMAP_COUNT - 1u) * roughness;
+
+	// Check proxy
+	U32 count = u_lightIndices[idxOffset++];
+	ANKI_LOOP while(count-- != 0)
+	{
+		ReflectionProbe probe = u_reflectionProbes[u_lightIndices[idxOffset++]];
+
+		F32 R2 = probe.m_positionRadiusSq.w;
+		Vec3 center = probe.m_positionRadiusSq.xyz;
+
+		// Get distance from the center of the probe
+		Vec3 f = worldPos - center;
+
+		// Cubemap UV in view space
+		Vec3 uv = computeCubemapVecAccurate(reflDir, R2, f);
+
+		// Read!
+		F32 cubemapIndex = probe.m_cubemapIndexPad3.x;
+		Vec3 c = textureLod(u_reflectionsTex, Vec4(uv, cubemapIndex), reflLod).rgb;
+
+		// Combine (lerp) with previous color
+		F32 d = dot(f, f);
+		F32 factor = d / R2;
+		factor = min(factor, 1.0);
+		specIndirect = mix(c, specIndirect, factor);
+
+		// Do the same for diffuse
+		uv = computeCubemapVecAccurate(normal, R2, f);
+		Vec3 id = textureLod(u_irradianceTex, Vec4(uv, cubemapIndex), 0.0).rgb;
+		diffIndirect = mix(id, diffIndirect, factor);
+	}
+}
+
+void main()
+{
+	// Compute a global invocation ID that takes the checkerboard pattern into account
+	IVec2 fixedInvocationId = IVec2(gl_GlobalInvocationID.xy);
+	fixedInvocationId.x *= 2;
+#if VARIANT == 0
+	fixedInvocationId.x += ((fixedInvocationId.y + 1) & 1);
+#else
+	fixedInvocationId.x += ((fixedInvocationId.y + 0) & 1);
+#endif
+
+	if(fixedInvocationId.x >= I32(FB_SIZE.x) || fixedInvocationId.y >= I32(FB_SIZE.y))
+	{
+		// Skip threads outside the writable image
+		return;
+	}
+
+	Vec2 uv = (Vec2(fixedInvocationId) + 0.5) / Vec2(FB_SIZE);
+	Vec2 ndc = UV_TO_NDC(uv);
+
+	// Read gbuffer
+	GbufferInfo gbuffer;
+	readGBuffer(u_gbufferRt0, u_gbufferRt1, u_gbufferRt2, uv, 0.0, gbuffer);
+
+	// Get depth
+	F32 depth = textureLod(u_depthRt, uv, 0.0).r;
+
+	// Get world position
+	Vec4 worldPos4 = u_invViewProjMat * Vec4(ndc, depth, 1.0);
+	Vec3 worldPos = worldPos4.xyz / worldPos4.w;
+
+	// Compute env BRDF
+	Vec3 env;
+	{
+		Vec3 viewDir = normalize(u_cameraPos - worldPos);
+		F32 NoV = max(EPSILON, dot(gbuffer.m_normal, viewDir));
+		env = envBRDF(gbuffer.m_specular, gbuffer.m_roughness, u_integrationLut, NoV);
+	}
+
+	// Try SSR
+	F32 sslrFactor = 0.0;
+	Vec3 sslrCol = Vec3(0.0);
+	if(env.g > 0.05)
+	{
+		// Get view pos
+		Vec4 viewPos4 = u_invProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
+		Vec3 viewPos = viewPos4.xyz / viewPos4.w;
+
+		// Do SSLR
+		Vec3 viewDir = normalize(viewPos);
+		Vec3 viewNormal = u_normalMat * gbuffer.m_normal;
+		Vec3 reflVec = reflect(viewDir, viewNormal);
+
+		Vec4 sslr = doSslr(reflVec, viewNormal, viewPos, uv, depth, gbuffer.m_roughness);
+		sslrFactor = sslr.w;
+		sslrCol = sslr.xyz;
+		sslrCol = clamp(sslrCol, 0.0, FLT_MAX); // Fix the value just in case
+	}
+
+	// Read probes
+	Vec3 probeCol = Vec3(0.0);
+	Vec3 indirectCol = Vec3(0.0);
+	{
+		// Get first light index
+		U32 clusterIdx = computeClusterIndex(u_clustererMagic, uv, worldPos, CLUSTER_COUNT_X, CLUSTER_COUNT_Y);
+		U32 idxOffset = u_clusters[clusterIdx];
+
+		// Skip decals
+		U32 count = u_lightIndices[idxOffset++];
+		idxOffset += count;
+		
+		// Skip point lights
+		count = u_lightIndices[idxOffset++];
+		idxOffset += count;
+
+		// Skip spot lights
+		count = u_lightIndices[idxOffset++];
+		idxOffset += count;
+
+		// Do the probe read
+		readReflectionsAndIrradianceFromProbes(
+			idxOffset, worldPos, gbuffer.m_normal, gbuffer.m_roughness, probeCol, indirectCol);
+	}
+
+	// Combine the SSR and probe reflections and write the result
+	Vec3 finalRefl = mix(probeCol, sslrCol, sslrFactor);
+
+	// Compute the final color
+	Vec3 outColor = indirectCol * gbuffer.m_diffuse + finalRefl * env;
+
+	// Store the color for the resolve
+	s_pixels[gl_LocalInvocationID.y][gl_LocalInvocationID.x] = outColor;
+
+	// Wait for all the threads to store their stuff
+	memoryBarrierShared();
+	barrier();
+
+	// Compute the missing pixel by resolving with the right or left neighbour
+	IVec2 readPixel, storePixel;
+	readPixel.y = I32(gl_LocalInvocationID.y);
+	storePixel.y = fixedInvocationId.y;
+
+#if VARIANT == 0
+	bool pickRightNeighbour = (fixedInvocationId.y & 1) == 1;
+#else
+	bool pickRightNeighbour = (fixedInvocationId.y & 1) == 0;
+#endif
+	I32 xOffset = (pickRightNeighbour) ? 1 : -1;
+	
+	readPixel.x = I32(gl_LocalInvocationID.x) + xOffset;
+	readPixel.x = clamp(readPixel.x, 0, I32(WORKGROUP_SIZE.x - 1));
+
+	storePixel.x = fixedInvocationId.x + xOffset;
+
+	Vec3 missingColor = (outColor + s_pixels[readPixel.y][readPixel.x]) * 0.5; // average
+
+	// Store both the pixels
+	imageStore(out_reflAndIndirect, fixedInvocationId, Vec4(outColor, 0.0));
+	imageStore(out_reflAndIndirect, storePixel, Vec4(missingColor, 0.0));
+}
+			]]></source>
+		</shader>
+	</shaders>
+</shaderProgram>

+ 17 - 17
programs/SceneDebug.ankiprog → shaders/SceneDebug.ankiprog

@@ -11,29 +11,29 @@ http://www.anki3d.org/LICENSE
 	</mutators>
 
 	<inputs>
-		<input name="INSTANCE_COUNT" type="uint" const="1"/>
+		<input name="INSTANCE_COUNT" type="U32" const="1"/>
 	</inputs>
 
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
-layout(location = 0) in vec3 in_position;
+layout(location = 0) in Vec3 in_position;
 #if COLOR_TEXTURE == 1
-layout(location = 1) in vec2 in_uv;
-layout(location = 0) out vec2 out_uv;
+layout(location = 1) in Vec2 in_uv;
+layout(location = 0) out Vec2 out_uv;
 #endif
 
 layout(ANKI_UBO_BINDING(1, 0), row_major) uniform u0_
 {
-	mat4 u_mvp[INSTANCE_COUNT];
-	vec4 u_color;
+	Mat4 u_mvp[INSTANCE_COUNT];
+	Vec4 u_color;
 };
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
 void main()
@@ -41,24 +41,24 @@ void main()
 #if COLOR_TEXTURE == 1
 	out_uv = in_uv;
 #endif
-	gl_Position = u_mvp[gl_InstanceID] * vec4(in_position, 1.0);
+	gl_Position = u_mvp[gl_InstanceID] * Vec4(in_position, 1.0);
 }
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #if COLOR_TEXTURE == 1
-layout(location = 0) in vec2 in_uv;
+layout(location = 0) in Vec2 in_uv;
 layout(ANKI_TEX_BINDING(1, 0)) uniform sampler2D u_tex;
 #endif
 
 layout(ANKI_UBO_BINDING(1, 0), row_major) uniform u0_
 {
-	mat4 u_mvp[INSTANCE_COUNT];
-	vec4 u_color;
+	Mat4 u_mvp[INSTANCE_COUNT];
+	Vec4 u_color;
 };
 
 // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
@@ -66,16 +66,16 @@ layout(ANKI_UBO_BINDING(1, 0), row_major) uniform u0_
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
 #endif
 
-layout(location = 0) out vec4 out_color;
+layout(location = 0) out Vec4 out_color;
 
 void main()
 {
 	// Check if we should skip the frag
 #if DITHERED_DEPTH_TEST == 1
-	vec2 uv = gl_FragCoord.xy / vec2(textureSize(u_depthRt, 0));
-	float depthRef = textureLod(u_depthRt, uv, 0.0).r;
+	Vec2 uv = gl_FragCoord.xy / Vec2(textureSize(u_depthRt, 0));
+	F32 depthRef = textureLod(u_depthRt, uv, 0.0).r;
 	bool depthTestFailed = gl_FragCoord.z >= depthRef;
-	ivec2 fragCoordi = ivec2(gl_FragCoord.xy);
+	IVec2 fragCoordi = IVec2(gl_FragCoord.xy);
 	if(depthTestFailed && ((fragCoordi.x + fragCoordi.y) % 8) != 0)
 	{
 		discard;

+ 22 - 22
programs/ScreenSpaceLensFlare.ankiprog → shaders/ScreenSpaceLensFlare.ankiprog

@@ -14,17 +14,17 @@ http://john-chapman-graphics.blogspot.no/2013/02/pseudo-lens-flare.html
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="INPUT_TEX_SIZE" type="uvec2" const="1"/>
+				<input name="INPUT_TEX_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #define MAX_GHOSTS 4
 #define GHOST_DISPERSAL (0.7)
@@ -34,20 +34,20 @@ http://john-chapman-graphics.blogspot.no/2013/02/pseudo-lens-flare.html
 #define ENABLE_HALO 1
 #define HALO_OPACITY 0.5
 
-layout(location = 0) in vec2 in_texCoord;
+layout(location = 0) in Vec2 in_texCoord;
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_rt;
 layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_lensDirtTex;
 
-layout(location = 0) out vec3 out_color;
+layout(location = 0) out Vec3 out_color;
 
-vec3 textureDistorted(in sampler2D tex,
-	in vec2 texcoord,
-	in vec2 direction, // direction of distortion
-	in vec3 distortion) // per-channel distortion factor
+Vec3 textureDistorted(in sampler2D tex,
+	in Vec2 texcoord,
+	in Vec2 direction, // direction of distortion
+	in Vec3 distortion) // per-channel distortion factor
 {
 #if ENABLE_CHROMATIC_DISTORTION
-	return vec3(texture(tex, texcoord + direction * distortion.r).r,
+	return Vec3(texture(tex, texcoord + direction * distortion.r).r,
 		texture(tex, texcoord + direction * distortion.g).g,
 		texture(tex, texcoord + direction * distortion.b).b);
 #else
@@ -57,26 +57,26 @@ vec3 textureDistorted(in sampler2D tex,
 
 void main()
 {
-	vec2 texcoord = vec2(1.0) - in_texCoord;
+	Vec2 texcoord = Vec2(1.0) - in_texCoord;
 
-	vec2 ghostVec = (vec2(0.5) - texcoord) * GHOST_DISPERSAL;
+	Vec2 ghostVec = (Vec2(0.5) - texcoord) * GHOST_DISPERSAL;
 
-	const vec2 texelSize = 1.0 / vec2(INPUT_TEX_SIZE);
+	const Vec2 texelSize = 1.0 / Vec2(INPUT_TEX_SIZE);
 
-	const vec3 distortion = vec3(-texelSize.x * CHROMATIC_DISTORTION, 0.0, texelSize.x * CHROMATIC_DISTORTION);
+	const Vec3 distortion = Vec3(-texelSize.x * CHROMATIC_DISTORTION, 0.0, texelSize.x * CHROMATIC_DISTORTION);
 
-	const float lenOfHalf = length(vec2(0.5));
+	const F32 lenOfHalf = length(Vec2(0.5));
 
-	vec2 direction = normalize(ghostVec);
+	Vec2 direction = normalize(ghostVec);
 
-	vec3 result = vec3(0.0);
+	Vec3 result = Vec3(0.0);
 
 	// sample ghosts:
-	for(int i = 0; i < MAX_GHOSTS; ++i)
+	for(I32 i = 0; i < MAX_GHOSTS; ++i)
 	{
-		vec2 offset = fract(texcoord + ghostVec * float(i));
+		Vec2 offset = fract(texcoord + ghostVec * F32(i));
 
-		float weight = length(vec2(0.5) - offset) / lenOfHalf;
+		F32 weight = length(Vec2(0.5) - offset) / lenOfHalf;
 		weight = pow(1.0 - weight, 10.0);
 
 		result += textureDistorted(u_rt, offset, direction, distortion) * weight;
@@ -84,8 +84,8 @@ void main()
 
 // sample halo
 #if ENABLE_HALO
-	vec2 haloVec = normalize(ghostVec) * HALO_WIDTH;
-	float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / lenOfHalf;
+	Vec2 haloVec = normalize(ghostVec) * HALO_WIDTH;
+	F32 weight = length(Vec2(0.5) - fract(texcoord + haloVec)) / lenOfHalf;
 	weight = pow(1.0 - weight, 20.0);
 	result += textureDistorted(u_rt, texcoord + haloVec, direction, distortion) * (weight * HALO_OPACITY);
 #endif

+ 9 - 9
programs/Ssao.ankiprog → shaders/Ssao.ankiprog

@@ -13,23 +13,23 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/QuadVert.glsl"
+#include <shaders/QuadVert.glsl>
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<inputs>
-				<input name="NOISE_MAP_SIZE" type="uint" const="1"/>
-				<input name="FB_SIZE" type="uvec2" const="1"/>
-				<input name="RADIUS" type="float" const="1"/>
-				<input name="BIAS" type="float" const="1"/>
-				<input name="STRENGTH" type="float" const="1"/>
-				<input name="SAMPLE_COUNT" type="uint" const="1"/>
-				<input name="WORKGROUP_SIZE" type="uvec2" const="1"/>
+				<input name="NOISE_MAP_SIZE" type="U32" const="1"/>
+				<input name="FB_SIZE" type="UVec2" const="1"/>
+				<input name="RADIUS" type="F32" const="1"/>
+				<input name="BIAS" type="F32" const="1"/>
+				<input name="STRENGTH" type="F32" const="1"/>
+				<input name="SAMPLE_COUNT" type="U32" const="1"/>
+				<input name="WORKGROUP_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Ssao.glsl"
+#include <shaders/Ssao.glsl>
 			]]></source>
 		</shader>
 	</shaders>

+ 56 - 56
shaders/Ssao.glsl

@@ -8,11 +8,11 @@
 #ifndef ANKI_SHADERS_SSAO_GLSL
 #define ANKI_SHADERS_SSAO_GLSL
 
-#include "shaders/Common.glsl"
-#include "shaders/Pack.glsl"
-#include "shaders/Functions.glsl"
+#include <shaders/Common.glsl>
+#include <shaders/Pack.glsl>
+#include <shaders/Functions.glsl>
 #define KERNEL_SIZE 3
-#include "shaders/GaussianBlurCommon.glsl"
+#include <shaders/GaussianBlurCommon.glsl>
 
 #if defined(ANKI_FRAGMENT_SHADER)
 #	define USE_COMPUTE 0
@@ -24,8 +24,8 @@
 #define DO_SOFT_BLUR (USE_COMPUTE && SOFT_BLUR)
 
 #if !USE_COMPUTE
-layout(location = 0) in vec2 in_uv;
-layout(location = 0) out float out_color;
+layout(location = 0) in Vec2 in_uv;
+layout(location = 0) out F32 out_color;
 #else
 layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
 
@@ -34,9 +34,9 @@ layout(ANKI_IMAGE_BINDING(0, 0)) writeonly uniform image2D out_img;
 
 layout(ANKI_UBO_BINDING(0, 0), std140, row_major) uniform _blk
 {
-	vec4 u_unprojectionParams;
-	vec4 u_projectionMat;
-	mat3 u_viewRotMat;
+	Vec4 u_unprojectionParams;
+	Vec4 u_projectionMat;
+	Mat3 u_viewRotMat;
 };
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_mMsDepthRt;
@@ -48,14 +48,14 @@ layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_msRt;
 // To compute the normals we need some extra work on compute
 #define COMPLEX_NORMALS (!USE_NORMAL && USE_COMPUTE)
 #if COMPLEX_NORMALS || DO_SOFT_BLUR
-shared vec3 s_scratch[WORKGROUP_SIZE.y][WORKGROUP_SIZE.x];
+shared Vec3 s_scratch[WORKGROUP_SIZE.y][WORKGROUP_SIZE.x];
 #endif
 
 #if USE_NORMAL
 // Get normal
-vec3 readNormal(in vec2 uv)
+Vec3 readNormal(in Vec2 uv)
 {
-	vec3 normal;
+	Vec3 normal;
 	readNormalFromGBuffer(u_msRt, uv, normal);
 	normal = u_viewRotMat * normal;
 	return normal;
@@ -63,43 +63,43 @@ vec3 readNormal(in vec2 uv)
 #endif
 
 // Read the noise tex
-vec3 readRandom(vec2 uv, float layer)
+Vec3 readRandom(Vec2 uv, F32 layer)
 {
-	const vec2 tmp = vec2(float(FB_SIZE.x) / float(NOISE_MAP_SIZE), float(FB_SIZE.y) / float(NOISE_MAP_SIZE));
-	vec3 r = texture(u_noiseMap, vec3(tmp * uv, layer)).rgb;
+	const Vec2 tmp = Vec2(F32(FB_SIZE.x) / F32(NOISE_MAP_SIZE), F32(FB_SIZE.y) / F32(NOISE_MAP_SIZE));
+	Vec3 r = texture(u_noiseMap, Vec3(tmp * uv, layer)).rgb;
 	return r;
 }
 
 // Returns the Z of the position in view space
-float readZ(in vec2 uv)
+F32 readZ(in Vec2 uv)
 {
-	float depth = textureLod(u_mMsDepthRt, uv, 0.0).r;
-	float z = u_unprojectionParams.z / (u_unprojectionParams.w + depth);
+	F32 depth = textureLod(u_mMsDepthRt, uv, 0.0).r;
+	F32 z = u_unprojectionParams.z / (u_unprojectionParams.w + depth);
 	return z;
 }
 
 // Read position in view space
-vec3 readPosition(in vec2 uv)
+Vec3 readPosition(in Vec2 uv)
 {
-	vec3 fragPosVspace;
+	Vec3 fragPosVspace;
 	fragPosVspace.z = readZ(uv);
 	fragPosVspace.xy = UV_TO_NDC(uv) * u_unprojectionParams.xy * fragPosVspace.z;
 
 	return fragPosVspace;
 }
 
-vec4 project(vec4 point)
+Vec4 project(Vec4 point)
 {
 	return projectPerspective(point, u_projectionMat.x, u_projectionMat.y, u_projectionMat.z, u_projectionMat.w);
 }
 
 // Compute the normal depending on some defines
-vec3 computeNormal(vec2 uv, vec3 origin)
+Vec3 computeNormal(Vec2 uv, Vec3 origin)
 {
 #if USE_NORMAL
-	vec3 normal = readNormal(uv);
+	Vec3 normal = readNormal(uv);
 #elif !COMPLEX_NORMALS
-	vec3 normal = normalize(cross(dFdx(origin), dFdy(origin)));
+	Vec3 normal = normalize(cross(dFdx(origin), dFdy(origin)));
 #else
 	// Every thread stores its position
 	s_scratch[gl_LocalInvocationID.y][gl_LocalInvocationID.x] = origin;
@@ -112,12 +112,12 @@ vec3 computeNormal(vec2 uv, vec3 origin)
 	{
 		// It's the bottom left pixel of the quad
 
-		vec3 center, right, top;
+		Vec3 center, right, top;
 		center = origin;
 		right = s_scratch[gl_LocalInvocationID.y][gl_LocalInvocationID.x + 1u];
 		top = s_scratch[gl_LocalInvocationID.y + 1u][gl_LocalInvocationID.x];
 
-		vec3 normal = normalize(cross(right - center, top - center));
+		Vec3 normal = normalize(cross(right - center, top - center));
 
 		// Broadcast the normal
 		s_scratch[gl_LocalInvocationID.y + 0u][gl_LocalInvocationID.x + 0u] = normal;
@@ -129,7 +129,7 @@ vec3 computeNormal(vec2 uv, vec3 origin)
 	memoryBarrierShared();
 	barrier();
 
-	vec3 normal = s_scratch[gl_LocalInvocationID.y][gl_LocalInvocationID.x];
+	Vec3 normal = s_scratch[gl_LocalInvocationID.y][gl_LocalInvocationID.x];
 #endif
 
 	return normal;
@@ -142,60 +142,60 @@ void main(void)
 	{
 #	if DO_SOFT_BLUR
 		// Store something anyway because alive threads might read it when SOFT_BLUR is enabled
-		s_scratch[gl_LocalInvocationID.y][gl_LocalInvocationID.x] = vec3(1.0);
+		s_scratch[gl_LocalInvocationID.y][gl_LocalInvocationID.x] = Vec3(1.0);
 #	endif
 
 		// Skip if it's out of bounds
 		return;
 	}
 
-	vec2 uv = (vec2(gl_GlobalInvocationID.xy) + 0.5) / vec2(FB_SIZE);
+	Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(FB_SIZE);
 #else
-	vec2 uv = in_uv;
+	Vec2 uv = in_uv;
 #endif
 
-	vec2 ndc = UV_TO_NDC(uv);
+	Vec2 ndc = UV_TO_NDC(uv);
 
 	// Compute origin
-	vec3 origin = readPosition(uv);
+	Vec3 origin = readPosition(uv);
 
 	// Get normal
-	vec3 normal = computeNormal(uv, origin);
+	Vec3 normal = computeNormal(uv, origin);
 
 	// Find the projected radius
-	vec3 sphereLimit = origin + vec3(RADIUS, 0.0, 0.0);
-	vec4 projSphereLimit = project(vec4(sphereLimit, 1.0));
-	vec2 projSphereLimit2 = projSphereLimit.xy / projSphereLimit.w;
-	float projRadius = length(projSphereLimit2 - ndc);
+	Vec3 sphereLimit = origin + Vec3(RADIUS, 0.0, 0.0);
+	Vec4 projSphereLimit = project(Vec4(sphereLimit, 1.0));
+	Vec2 projSphereLimit2 = projSphereLimit.xy / projSphereLimit.w;
+	F32 projRadius = length(projSphereLimit2 - ndc);
 
 	// Loop to compute
-	float randFactor = readRandom(uv, 0.0).r;
-	float ssao = 0.0;
-	const float SAMPLE_COUNTF = float(SAMPLE_COUNT);
-	ANKI_UNROLL for(uint i = 0; i < SAMPLE_COUNT; ++i)
+	F32 randFactor = readRandom(uv, 0.0).r;
+	F32 ssao = 0.0;
+	const F32 SAMPLE_COUNTF = F32(SAMPLE_COUNT);
+	ANKI_UNROLL for(U32 i = 0; i < SAMPLE_COUNT; ++i)
 	{
 		// Compute disk. Basically calculate a point in a spiral. See how it looks here
 		// https://shadertoy.com/view/Md3fDr
-		float fi = float(i);
-		const float TURNS = float(SAMPLE_COUNT) / 2.0; // Calculate the number of the spiral turns
-		const float ANG = (PI * 2.0 * TURNS) / (SAMPLE_COUNTF - 1.0); // The angle distance between samples
-		float ang = ANG * fi;
+		F32 fi = F32(i);
+		const F32 TURNS = F32(SAMPLE_COUNT) / 2.0; // Calculate the number of the spiral turns
+		const F32 ANG = (PI * 2.0 * TURNS) / (SAMPLE_COUNTF - 1.0); // The angle distance between samples
+		F32 ang = ANG * fi;
 		ang += randFactor * PI; // Turn the angle a bit
 
-		float radius = (1.0 / SAMPLE_COUNTF) * (fi + 1.0);
+		F32 radius = (1.0 / SAMPLE_COUNTF) * (fi + 1.0);
 		radius = sqrt(radius); // Move the points a bit away from the center of the spiral
 
-		vec2 point = vec2(cos(ang), sin(ang)) * radius; // In NDC
+		Vec2 point = Vec2(cos(ang), sin(ang)) * radius; // In NDC
 
-		vec2 finalDiskPoint = ndc + point * projRadius;
+		Vec2 finalDiskPoint = ndc + point * projRadius;
 
 		// Compute factor
-		vec3 s = readPosition(NDC_TO_UV(finalDiskPoint));
-		vec3 u = s - origin;
+		Vec3 s = readPosition(NDC_TO_UV(finalDiskPoint));
+		Vec3 u = s - origin;
 		ssao += max(dot(normal, u) + BIAS, EPSILON) / max(dot(u, u), EPSILON);
 	}
 
-	ssao *= (1.0 / float(SAMPLE_COUNT));
+	ssao *= (1.0 / F32(SAMPLE_COUNT));
 	ssao = 1.0 - ssao * STRENGTH;
 
 	// Maybe do soft blur
@@ -204,11 +204,11 @@ void main(void)
 	s_scratch[gl_LocalInvocationID.y][gl_LocalInvocationID.x].x = ssao;
 
 	// Do some pre-work to find out the neighbours
-	uint left = (gl_LocalInvocationID.x != 0u) ? (gl_LocalInvocationID.x - 1u) : 0u;
-	uint right =
+	U32 left = (gl_LocalInvocationID.x != 0u) ? (gl_LocalInvocationID.x - 1u) : 0u;
+	U32 right =
 		(gl_LocalInvocationID.x != WORKGROUP_SIZE.x - 1u) ? (gl_LocalInvocationID.x + 1u) : (WORKGROUP_SIZE.x - 1u);
-	uint bottom = (gl_LocalInvocationID.y != 0u) ? (gl_LocalInvocationID.y - 1u) : 0u;
-	uint top =
+	U32 bottom = (gl_LocalInvocationID.y != 0u) ? (gl_LocalInvocationID.y - 1u) : 0u;
+	U32 top =
 		(gl_LocalInvocationID.y != WORKGROUP_SIZE.y - 1u) ? (gl_LocalInvocationID.y + 1u) : (WORKGROUP_SIZE.y - 1u);
 
 	// Wait for all threads
@@ -231,7 +231,7 @@ void main(void)
 
 	// Store the result
 #if USE_COMPUTE
-	imageStore(out_img, ivec2(gl_GlobalInvocationID.xy), vec4(ssao));
+	imageStore(out_img, IVec2(gl_GlobalInvocationID.xy), Vec4(ssao));
 #else
 	out_color = ssao;
 #endif

+ 8 - 10
programs/SsaoCompute.ankiprog → shaders/SsaoCompute.ankiprog

@@ -13,20 +13,18 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="comp">
 			<inputs>
-				<input name="NOISE_MAP_SIZE" type="uint" const="1"/>
-				<input name="FB_SIZE" type="uvec2" const="1"/>
-				<input name="RADIUS" type="float" const="1"/>
-				<input name="BIAS" type="float" const="1"/>
-				<input name="STRENGTH" type="float" const="1"/>
-				<input name="SAMPLE_COUNT" type="uint" const="1"/>
-				<input name="WORKGROUP_SIZE" type="uvec2" const="1"/>
+				<input name="NOISE_MAP_SIZE" type="U32" const="1"/>
+				<input name="FB_SIZE" type="UVec2" const="1"/>
+				<input name="RADIUS" type="F32" const="1"/>
+				<input name="BIAS" type="F32" const="1"/>
+				<input name="STRENGTH" type="F32" const="1"/>
+				<input name="SAMPLE_COUNT" type="U32" const="1"/>
+				<input name="WORKGROUP_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
-#include "shaders/Ssao.glsl"
+#include <shaders/Ssao.glsl>
 			]]></source>
 		</shader>
 	</shaders>
 </shaderProgram>
-
-

+ 0 - 120
shaders/Sslr.glsl

@@ -1,120 +0,0 @@
-// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-// SSLR functions and data
-#include "shaders/Common.glsl"
-#include "shaders/Functions.glsl"
-#include "shaders/Pack.glsl"
-
-const float ONE = 0.9;
-
-// Returns the Z of the position in view space
-float readZ(in vec2 uv)
-{
-	float depth = textureLod(u_depthRt, uv, 1.0).r;
-	float z = u_projectionParams.z / (u_projectionParams.w + depth);
-	return z;
-}
-
-vec2 projectXy(in vec3 p)
-{
-	vec4 a = u_projectionMat * vec4(p, 1.0);
-	return a.xy / a.w;
-}
-
-vec3 doSslr(in vec3 r, in vec3 posVSpace, in vec2 uv, out float contribution)
-{
-	contribution = 0.5;
-	return vec3(1.0, 0.0, 1.0);
-#if 0
-	vec3 color = vec3(0.0);
-	vec3 p0 = posVSpace;
-	contribution = 1.0;
-
-	// Let p1 be the intersection of p0+r to the near plane, then
-	// p1 = p0 + t*r or
-	// p1.x = p0.x + t*r.x (1)
-	// p1.y = p0.y + t*r.y (2) and
-	// p1.z = p0.z + t*r.z (3)
-	// p1.z is known to be something ~0.0 so if we solve (3) t becomes:
-	float t = -p0.z / (r.z + 0.0000001);
-	vec3 p1 = p0 + r * t;
-
-	vec2 pp0 = uv * 2.0 - 1.0;
-	vec2 pp1 = projectXy(p1);
-
-	// Calculate the ray from p0 to p1 in 2D space and get the number of
-	// steps
-	vec2 dir = pp1 - pp0;
-	vec2 path = dir * 0.5; // (pp1/2+1/2)-(pp0.xy/2+1/2)
-	path *= vec2(float(WIDTH), float(HEIGHT));
-	path = abs(path);
-	float steps = max(path.x, path.y);
-
-	// Calculate the step increase
-	float len = length(dir);
-	float stepInc =  len / steps;
-	dir /= len; // Normalize dir at last
-
-	steps = min(steps, 300.0);
-
-	for(float i = 0.0; i < steps; i += 1.0)
-	{
-		vec2 ndc = pp0 + dir * (i * stepInc);
-
-		// Check if it's out of the view
-		vec2 comp = abs(ndc);
-		if(comp.x > ONE || comp.y > ONE)
-		{
-			//color = vec3(1, 0.0, 1);
-			return color;
-		}
-
-		// 'a' is ray that passes through the eye and into ndc
-		vec3 a;
-		a.z = -1.0;
-		a.xy = ndc * u_projectionParams.xy * a.z; // Unproject
-		a = normalize(a);
-
-		// Compute the intersection between 'a' (before normalization) and r 'k' is the value to multiply to 'a' to get 
-		// the intersection
-		// c0 = cross(a, r);
-		// c1 = cross(p0, r);
-		// k = c1.x / c0.x; and the optimized:
-		vec2 tmpv2 = a.yz * r.zy;
-		float c0x = tmpv2.x - tmpv2.y;
-		tmpv2 = p0.yz * r.zy;
-		float c1x = tmpv2.x - tmpv2.y;
-		float k = c1x / c0x;
-
-		float intersectionZ = a.z * k; // intersectionXYZ = a * k;
-
-		vec2 texCoord = ndc * 0.5 + 0.5;
-		float depth = readZ(u_depthRt, texCoord);
-
-		float diffDepth = depth - intersectionZ;
-
-		if(diffDepth > 0.0)
-		{
-			if(diffDepth > 0.7)
-			{
-				return;
-			}
-
-			float factor = sin(length(ndc) * PI);
-			factor *= 1.0 - length(pp0);
-			//factor *= specColor;
-
-			color = textureLod(u_isRt, texCoord, 0.0).rgb * factor;
-
-			//color = vec3(1.0, 0.0, 1.0);
-			//color = vec3(1.0 - abs(pp0.xy), 0.0);
-			return color;
-		}
-	}
-
-	return color;
-#endif
-}

+ 142 - 0
shaders/TemporalAAResolve.ankiprog

@@ -0,0 +1,142 @@
+<!-- 
+Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+<shaderProgram>
+	<mutators>
+		<mutator name="SHARPEN" values="0 1 2"/> <!-- 0: disabled, 1: vertical, 2: horizontal -->
+		<mutator name="VARIANCE_CLIPPING" values="0 1"/>
+		<mutator name="TONEMAP_FIX" values="0 1"/>
+		<mutator name="YCBCR" values="0 1"/>
+	</mutators>
+
+	<inputs>
+		<input name="VARIANCE_CLIPPING_GAMMA" type="F32" const="1"/>
+		<input name="BLEND_FACTOR" type="F32" const="1"/>
+	</inputs>
+
+	<shaders>
+		<shader type="vert">
+			<source><![CDATA[
+#include <shaders/QuadVert.glsl>
+			]]></source>
+		</shader>
+
+		<shader type="frag">
+			<source><![CDATA[
+#include <shaders/Functions.glsl>
+#include <shaders/Pack.glsl>
+#include <shaders/Tonemapping.glsl>
+
+layout(location = 0) in Vec2 in_uv;
+
+layout(location = 0) out Vec3 out_color;
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
+layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_inputRt;
+layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_historyRt;
+
+layout(ANKI_UBO_BINDING(0, 0), std140, row_major) uniform u0_
+{
+	Mat4 u_prevViewProjMatMulInvViewProjMat;
+};
+
+#if TONEMAP_FIX
+#define TONEMAPPING_SET 0
+#define TONEMAPPING_BINDING 1
+#include <shaders/TonemappingResources.glsl>
+#endif
+
+#if YCBCR
+#define sample(s, uv) rgbToYCbCr(textureLod(s, uv, 0.0).rgb)
+#define sampleOffset(s, uv, x, y) rgbToYCbCr(textureLodOffset(s, uv, 0.0, IVec2(x, y)).rgb)
+#else
+#define sample(s, uv) textureLod(s, uv, 0.0).rgb
+#define sampleOffset(s, uv, x, y) textureLodOffset(s, uv, 0.0, IVec2(x, y)).rgb
+#endif
+
+Vec3 sharpen()
+{
+	Vec3 center = sample(u_inputRt, in_uv);
+#if SHARPEN == 1
+	Vec3 near = sampleOffset(u_inputRt, in_uv, 1, 0) + sampleOffset(u_inputRt, in_uv, -1, 0);
+#else
+	Vec3 near = sampleOffset(u_inputRt, in_uv, 0, 1) + sampleOffset(u_inputRt, in_uv, 0, -1);
+#endif
+	near *= 0.5;
+	F32 sharpness = 1.0;
+	return center + (center - near) * sharpness;
+}
+
+void main()
+{
+	F32 depth = textureLod(u_depthRt, in_uv, 0.0).r;
+
+	// Get prev uv coords
+	Vec4 v4 = u_prevViewProjMatMulInvViewProjMat * Vec4(UV_TO_NDC(in_uv), depth, 1.0);
+	Vec2 oldUv = NDC_TO_UV(v4.xy / v4.w);
+
+	// Read textures
+	Vec3 historyCol = sample(u_historyRt, oldUv);
+#if SHARPEN > 0
+	Vec3 crntCol = sharpen();
+#else
+	Vec3 crntCol = sample(u_inputRt, in_uv);
+#endif
+
+	// Remove ghosting by clamping the history color to neighbour's AABB
+	Vec3 near0 = sampleOffset(u_inputRt, in_uv, 1, 0);
+	Vec3 near1 = sampleOffset(u_inputRt, in_uv, 0, 1);
+	Vec3 near2 = sampleOffset(u_inputRt, in_uv, -1, 0);
+	Vec3 near3 = sampleOffset(u_inputRt, in_uv, 0, -1);
+
+#if VARIANCE_CLIPPING
+	Vec3 m1 = crntCol + near0 + near1 + near2 + near3;
+	Vec3 m2 = crntCol * crntCol + near0 * near0 + near1 * near1 + near2 * near2 + near3 * near3;
+
+	Vec3 mu = m1 / 5.0;
+	Vec3 sigma = sqrt(m2 / 5.0 - mu * mu);
+
+	Vec3 boxMin = mu - VARIANCE_CLIPPING_GAMMA * sigma;
+	Vec3 boxMax = mu + VARIANCE_CLIPPING_GAMMA * sigma;
+#else
+	Vec3 boxMin = min(crntCol, min(near0, min(near1, min(near2, near3))));
+	Vec3 boxMax = max(crntCol, max(near0, max(near1, max(near2, near3))));
+#endif
+
+	historyCol = clamp(historyCol, boxMin, boxMax);
+
+	// Remove jitter (T. Lottes)
+#if YCBCR
+	F32 lum0 = crntCol.r;
+	F32 lum1 = historyCol.r;
+	F32 maxLum = boxMax.r;
+#elif TONEMAP_FIX
+	F32 lum0 = computeLuminance(tonemap(crntCol, u_exposureThreshold0));
+	F32 lum1 = computeLuminance(tonemap(historyCol, u_exposureThreshold0));
+	//F32 maxLum = computeLuminance(tonemap(boxMax, u_exposureThreshold0));
+	F32 maxLum = 1.0;
+#else
+	F32 lum0 = computeLuminance(crntCol);
+	F32 lum1 = computeLuminance(historyCol);
+	F32 maxLum = computeLuminance(boxMax);
+#endif
+
+	F32 diff = abs(lum0 - lum1) / max(lum0, max(lum1, maxLum + EPSILON));
+	diff = 1.0 - diff;
+	diff = diff * diff;
+	F32 feedback = mix(0.0, BLEND_FACTOR, diff);
+
+	// Write result
+#if YCBCR
+	out_color = yCbCrToRgb(mix(historyCol, crntCol, feedback));
+#else
+	out_color = mix(historyCol, crntCol, feedback);
+#endif
+}
+			]]></source>
+		</shader>
+	</shaders>
+</shaderProgram>

+ 24 - 24
shaders/Tonemapping.glsl

@@ -6,65 +6,65 @@
 #ifndef ANKI_SHADERS_TONEMAP_GLSL
 #define ANKI_SHADERS_TONEMAP_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 // A tick to compute log of base 10
-float log10(in float x)
+F32 log10(in F32 x)
 {
 	return log(x) / log(10.0);
 }
 
-float computeLuminance(in vec3 color)
+F32 computeLuminance(in Vec3 color)
 {
-	return max(dot(vec3(0.30, 0.59, 0.11), color), EPSILON);
+	return max(dot(Vec3(0.30, 0.59, 0.11), color), EPSILON);
 }
 
-float computeExposure(float avgLum, float threshold)
+F32 computeExposure(F32 avgLum, F32 threshold)
 {
-	float keyValue = 1.03 - (2.0 / (2.0 + log10(avgLum + 1.0)));
-	float linearExposure = (keyValue / avgLum);
-	float exposure = log2(linearExposure);
+	F32 keyValue = 1.03 - (2.0 / (2.0 + log10(avgLum + 1.0)));
+	F32 linearExposure = (keyValue / avgLum);
+	F32 exposure = log2(linearExposure);
 
 	exposure -= threshold;
 	return exp2(exposure);
 }
 
-vec3 computeExposedColor(in vec3 color, in float avgLum, in float threshold)
+Vec3 computeExposedColor(in Vec3 color, in F32 avgLum, in F32 threshold)
 {
 	return computeExposure(avgLum, threshold) * color;
 }
 
 // Reinhard operator
-vec3 tonemapReinhard(in vec3 color, in float saturation)
+Vec3 tonemapReinhard(in Vec3 color, in F32 saturation)
 {
-	float lum = computeLuminance(color);
-	float toneMappedLuminance = lum / (lum + 1.0);
-	return toneMappedLuminance * pow(color / lum, vec3(saturation));
+	F32 lum = computeLuminance(color);
+	F32 toneMappedLuminance = lum / (lum + 1.0);
+	return toneMappedLuminance * pow(color / lum, Vec3(saturation));
 }
 
 // Uncharted 2 operator
-vec3 tonemapUncharted2(in vec3 color)
+Vec3 tonemapUncharted2(in Vec3 color)
 {
-	const float A = 0.15;
-	const float B = 0.50;
-	const float C = 0.10;
-	const float D = 0.20;
-	const float E = 0.02;
-	const float F = 0.30;
+	const F32 A = 0.15;
+	const F32 B = 0.50;
+	const F32 C = 0.10;
+	const F32 D = 0.20;
+	const F32 E = 0.02;
+	const F32 F = 0.30;
 
 	return ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F;
 }
 
-vec3 tonemap(vec3 color, float exposure)
+Vec3 tonemap(Vec3 color, F32 exposure)
 {
 	color *= exposure;
-	float saturation = 1.0;
+	F32 saturation = 1.0;
 	return tonemapReinhard(color, saturation);
 }
 
-vec3 tonemap(vec3 color, float avgLum, float threshold)
+Vec3 tonemap(Vec3 color, F32 avgLum, F32 threshold)
 {
-	float exposure = computeExposure(avgLum, threshold);
+	F32 exposure = computeExposure(avgLum, threshold);
 	return tonemap(color, exposure);
 }
 #endif

+ 25 - 25
programs/TonemappingAverageLuminance.ankiprog → shaders/TonemappingAverageLuminance.ankiprog

@@ -8,44 +8,44 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="comp">
 			<inputs>
-				<input name="INPUT_TEX_SIZE" type="uvec2" const="1"/>
+				<input name="INPUT_TEX_SIZE" type="UVec2" const="1"/>
 			</inputs>
 
 			<source><![CDATA[
 #define LOG_AVG 0
 
-#include "shaders/Common.glsl"
-#include "shaders/Tonemapping.glsl"
+#include <shaders/Common.glsl>
+#include <shaders/Tonemapping.glsl>
 
-const uint WORKGROUP_SIZE_X = 16u;
-const uint WORKGROUP_SIZE_Y = 16u;
-const uint WORKGROUP_SIZE = WORKGROUP_SIZE_X * WORKGROUP_SIZE_Y;
+const U32 WORKGROUP_SIZE_X = 16u;
+const U32 WORKGROUP_SIZE_Y = 16u;
+const U32 WORKGROUP_SIZE = WORKGROUP_SIZE_X * WORKGROUP_SIZE_Y;
 
 layout(local_size_x = WORKGROUP_SIZE_X, local_size_y = WORKGROUP_SIZE_Y, local_size_z = 1) in;
 
-const uint PIXEL_READ_X = INPUT_TEX_SIZE.x / WORKGROUP_SIZE_X;
-const uint PIXEL_READ_Y = INPUT_TEX_SIZE.y / WORKGROUP_SIZE_Y;
+const U32 PIXEL_READ_X = INPUT_TEX_SIZE.x / WORKGROUP_SIZE_X;
+const U32 PIXEL_READ_Y = INPUT_TEX_SIZE.y / WORKGROUP_SIZE_Y;
 
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex;
 
 #define TONEMAPPING_RESOURCE_AS_BUFFER 1
-#include "shaders/TonemappingResources.glsl"
+#include <shaders/TonemappingResources.glsl>
 
-shared float s_avgLum[WORKGROUP_SIZE];
+shared F32 s_avgLum[WORKGROUP_SIZE];
 
 void main()
 {
 	// Gather the log-average luminance of a tile
-	float avgLum = 0.0;
-	uint yStart = gl_LocalInvocationID.y * PIXEL_READ_Y;
-	uint xStart = gl_LocalInvocationID.x * PIXEL_READ_X;
-	ANKI_LOOP for(uint y = 0; y < PIXEL_READ_Y; ++y)
+	F32 avgLum = 0.0;
+	U32 yStart = gl_LocalInvocationID.y * PIXEL_READ_Y;
+	U32 xStart = gl_LocalInvocationID.x * PIXEL_READ_X;
+	ANKI_LOOP for(U32 y = 0; y < PIXEL_READ_Y; ++y)
 	{
-		ANKI_UNROLL for(uint x = 0; x < PIXEL_READ_X; ++x)
+		ANKI_UNROLL for(U32 x = 0; x < PIXEL_READ_X; ++x)
 		{
-			ivec2 uv = ivec2(xStart, yStart) + ivec2(x, y);
-			vec3 color = texelFetch(u_tex, uv, 0).rgb;
-			float lum = computeLuminance(color);
+			IVec2 uv = IVec2(xStart, yStart) + IVec2(x, y);
+			Vec3 color = texelFetch(u_tex, uv, 0).rgb;
+			F32 lum = computeLuminance(color);
 #if LOG_AVG
 			avgLum += log(max(EPSILON, lum));
 #else
@@ -60,7 +60,7 @@ void main()
 	barrier();
 
 	// Gather the results into one
-	ANKI_LOOP for(uint s = WORKGROUP_SIZE / 2u; s > 0u; s >>= 1u)
+	ANKI_LOOP for(U32 s = WORKGROUP_SIZE / 2u; s > 0u; s >>= 1u)
 	{
 		if(gl_LocalInvocationIndex < s)
 		{
@@ -75,19 +75,19 @@ void main()
 	ANKI_BRANCH if(gl_LocalInvocationIndex == 0)
 	{
 #if LOG_AVG
-		float crntLum = exp(s_avgLum[0] * (1.0 / float(INPUT_TEX_SIZE.x * INPUT_TEX_SIZE.y)));
+		F32 crntLum = exp(s_avgLum[0] * (1.0 / F32(INPUT_TEX_SIZE.x * INPUT_TEX_SIZE.y)));
 #else
-		float crntLum = s_avgLum[0] * (1.0 / float(INPUT_TEX_SIZE.x * INPUT_TEX_SIZE.y));
+		F32 crntLum = s_avgLum[0] * (1.0 / F32(INPUT_TEX_SIZE.x * INPUT_TEX_SIZE.y));
 #endif
 
 #if 1
-		float prevLum = u_averageLuminance;
+		F32 prevLum = u_averageLuminance;
 
 		// Lerp between previous and new L value
-		const float INTERPOLATION_FACTOR = 0.05;
-		float finalAvgLum = mix(prevLum, crntLum, INTERPOLATION_FACTOR);
+		const F32 INTERPOLATION_FACTOR = 0.05;
+		F32 finalAvgLum = mix(prevLum, crntLum, INTERPOLATION_FACTOR);
 #else
-		float finalAvgLum = crntLum;
+		F32 finalAvgLum = crntLum;
 #endif
 
 		// This is a workaround because sometimes the avg lum becomes nan

+ 2 - 2
shaders/TonemappingResources.glsl

@@ -8,7 +8,7 @@
 #ifndef ANKI_SHADERS_TONEMAPPING_RESOURCES_GLSL
 #define ANKI_SHADERS_TONEMAPPING_RESOURCES_GLSL
 
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #ifndef TONEMAPPING_SET
 #	define TONEMAPPING_SET 0
@@ -28,7 +28,7 @@ layout(std140, ANKI_SS_BINDING(TONEMAPPING_SET, TONEMAPPING_BINDING)) buffer tms
 layout(std140, ANKI_UBO_BINDING(TONEMAPPING_SET, TONEMAPPING_BINDING)) uniform tmu0_
 #endif
 {
-	vec4 u_averageLuminanceExposurePad2;
+	Vec4 u_averageLuminanceExposurePad2;
 };
 
 #define u_averageLuminance u_averageLuminanceExposurePad2.x

+ 127 - 0
shaders/TraditionalDeferredShading.ankiprog

@@ -0,0 +1,127 @@
+<!-- 
+Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+
+<!-- Classic deferred lighting shader -->
+
+<shaderProgram>
+	<mutators>
+		<mutator name="LIGHT_TYPE" values="0 1"/>
+	</mutators>
+
+	<shaders>
+		<shader type="vert">
+			<source><![CDATA[
+#include <shaders/Common.glsl>
+
+layout(location = 0) in Vec3 in_position;
+
+out gl_PerVertex
+{
+	Vec4 gl_Position;
+};
+
+layout(ANKI_UBO_BINDING(0, 0), row_major) uniform u0_
+{
+	Mat4 u_mvp;
+};
+
+void main()
+{
+	gl_Position = u_mvp * Vec4(in_position, 1.0);
+}
+			]]></source>
+		</shader>
+
+		<shader type="frag">
+			<inputs>
+				<input name="FB_SIZE" type="UVec2" const="1"/>
+			</inputs>
+
+			<source><![CDATA[
+#include <shaders/Pack.glsl>
+#include <shaders/LightFunctions.glsl>
+#include <shaders/glsl_cpp_common/TraditionalDeferredShading.h>
+
+#define POINT_LIGHT_TYPE 0
+#define SPOT_LIGHT_TYPE 1
+
+layout(location = 0) out Vec3 out_color;
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msRt0;
+layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_msRt1;
+layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_msRt2;
+layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_msDepthRt;
+
+layout(ANKI_UBO_BINDING(0, 1), row_major) uniform u1_
+{
+#if LIGHT_TYPE == POINT_LIGHT_TYPE
+	DeferredPointLightUniforms u_unis;
+#elif LIGHT_TYPE == SPOT_LIGHT_TYPE
+	DeferredSpotLightUniforms u_unis;
+#else
+#	error See file
+#endif
+};
+
+#if LIGHT_TYPE == POINT_LIGHT_TYPE
+#	define u_ldiff u_unis.m_diffuseColorPad1.xyz
+#else
+#	define u_ldiff u_unis.m_diffuseColorOuterCos.xyz
+#	define u_lightDir u_unis.m_lightDirInnerCos.xyz
+#	define u_outerCos u_unis.m_diffuseColorOuterCos.w
+#	define u_innerCos u_unis.m_lightDirInnerCos.w
+#endif
+
+#define u_pos u_unis.m_posRadius.xyz
+#define u_radius u_unis.m_posRadius.w
+#define u_camPos u_unis.m_camPosPad1.xyz
+#define u_inputTexUvScaleAndOffset u_unis.m_inputTexUvScaleAndOffset
+#define u_invViewProjMat u_unis.m_invViewProjMat
+
+void main()
+{
+	// Compute UV coordinates
+	Vec2 uv = Vec2(gl_FragCoord.xy) / Vec2(FB_SIZE.x, FB_SIZE.y);
+	Vec2 uvToRead = fma(uv, u_inputTexUvScaleAndOffset.xy, u_inputTexUvScaleAndOffset.zw);
+
+	// Do manual depth test
+	F32 depth = texture(u_msDepthRt, uvToRead).r;
+	if(gl_FragCoord.z < depth)
+	{
+		discard;
+	}
+
+	// Decode and process gbuffer
+	GbufferInfo gbuffer;
+	readGBuffer(u_msRt0, u_msRt1, u_msRt2, uvToRead, 0.0, gbuffer);
+
+	Vec4 worldPos4 = u_invViewProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
+	Vec3 worldPos = worldPos4.xyz / worldPos4.w;
+
+	// Calculate the light color
+	Vec3 viewDir = normalize(u_camPos - worldPos);
+	Vec3 frag2Light = u_pos - worldPos;
+	Vec3 l = normalize(frag2Light);
+	F32 nol = max(0.0, dot(gbuffer.m_normal, l));
+
+	Vec3 specC = computeSpecularColorBrdf(gbuffer, viewDir, l);
+	Vec3 diffC = diffuseLambert(gbuffer.m_diffuse);
+
+	F32 att = computeAttenuationFactor(u_radius, frag2Light);
+	F32 lambert = nol;
+
+#if LIGHT_TYPE == POINT_LIGHT_TYPE
+	out_color = (specC + diffC) * u_ldiff * (att * max(lambert, gbuffer.m_subsurface));
+#else
+	F32 spot = computeSpotFactor(l, u_outerCos, u_innerCos, u_lightDir);
+	out_color = (diffC + specC) * u_ldiff * (att * spot * max(lambert, gbuffer.m_subsurface));
+#endif
+}
+			]]></source>
+		</shader>
+	</shaders>
+</shaderProgram>

+ 14 - 14
programs/Ui.ankiprog → shaders/Ui.ankiprog

@@ -12,27 +12,27 @@ http://www.anki3d.org/LICENSE
 	<shaders>
 		<shader type="vert">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
-layout(location = 0) in vec2 in_pos;
-layout(location = 1) in vec4 in_col;
+layout(location = 0) in Vec2 in_pos;
+layout(location = 1) in Vec4 in_col;
 #if TEXTURE_TYPE > 0
-layout(location = 2) in vec2 in_uv;
+layout(location = 2) in Vec2 in_uv;
 #endif
 
 #if TEXTURE_TYPE > 0
-layout(location = 0) out vec2 out_uv;
+layout(location = 0) out Vec2 out_uv;
 #endif
-layout(location = 1) out vec4 out_col;
+layout(location = 1) out Vec4 out_col;
 
 out gl_PerVertex
 {
-	vec4 gl_Position;
+	Vec4 gl_Position;
 };
 
 layout(ANKI_UBO_BINDING(0, 0)) uniform u_
 {
-	vec4 u_transform; // x: x scale, y: y scale, z: x transl, w: y transl
+	Vec4 u_transform; // x: x scale, y: y scale, z: x transl, w: y transl
 };
 
 void main()
@@ -42,22 +42,22 @@ void main()
 #endif
 	out_col = in_col;
 
-	vec2 pos = u_transform.xy * in_pos + u_transform.zw;
-	gl_Position = vec4(pos, 0.0, 1.0);
+	Vec2 pos = u_transform.xy * in_pos + u_transform.zw;
+	gl_Position = Vec4(pos, 0.0, 1.0);
 }
 			]]></source>
 		</shader>
 
 		<shader type="frag">
 			<source><![CDATA[
-#include "shaders/Common.glsl"
+#include <shaders/Common.glsl>
 
 #if TEXTURE_TYPE > 0
-layout(location = 0) in vec2 in_uv;
+layout(location = 0) in Vec2 in_uv;
 #endif
-layout(location = 1) in vec4 in_col;
+layout(location = 1) in Vec4 in_col;
 
-layout(location = 0) out vec4 out_col;
+layout(location = 0) out Vec4 out_col;
 
 #if TEXTURE_TYPE > 0
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex;

+ 223 - 0
shaders/VolumetricFog.ankiprog

@@ -0,0 +1,223 @@
+<!-- 
+Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+<shaderProgram>
+	<mutators>
+		<mutator name="ENABLE_SHADOWS" values="0 1"/>
+	</mutators>
+
+	<shaders>
+		<shader type="vert">
+			<source><![CDATA[
+#include <shaders/QuadVert.glsl>
+			]]></source>
+		</shader>
+
+		<shader type="frag">
+			<inputs>
+				<input name="FB_SIZE" type="UVec2" const="1"/>
+				<input name="CLUSTER_COUNT" type="UVec3" const="1"/>
+				<input name="NOISE_MAP_SIZE" type="U32" const="1"/>
+			</inputs>
+
+			<source><![CDATA[
+#include <shaders/Common.glsl>
+#include <shaders/Functions.glsl>
+#include <shaders/glsl_cpp_common/Clusterer.h>
+
+#define LIGHT_TEX_BINDING 3
+#define LIGHT_UBO_BINDING 0
+#define LIGHT_SS_BINDING 0
+#define LIGHT_SET 0
+#define LIGHT_LIGHTS
+#define LIGHT_COMMON_UNIS
+#include <shaders/ClusterLightCommon.glsl>
+
+layout(location = 0) in Vec2 in_uv;
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_msDepthRt;
+layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2DArray u_noiseTex;
+layout(ANKI_TEX_BINDING(0, 2)) uniform sampler2D u_historyRt;
+
+layout(std140, ANKI_UBO_BINDING(0, 3), row_major) uniform ubo0_
+{
+	Vec4 u_linearizeNoiseTexOffsetLayer;
+	Vec4 u_fogParticleColorPad1;
+	Mat4 u_prevViewProjMatMulInvViewProjMat2; // TODO Light common ubo has that. Maybe remove it
+};
+
+#define u_linearize UNIFORM(u_linearizeNoiseTexOffsetLayer.xy)
+#define u_noiseYOffset UNIFORM(u_linearizeNoiseTexOffsetLayer.z)
+#define u_noiseLayer UNIFORM(u_linearizeNoiseTexOffsetLayer.w)
+#define u_fogParticleColor UNIFORM(u_fogParticleColorPad1.rgb)
+
+layout(location = 0) out Vec3 out_color;
+
+const U32 MAX_SAMPLES_PER_CLUSTER = 4u;
+const F32 DIST_BETWEEN_SAMPLES = 0.25;
+const F32 HISTORY_FEEDBACK = 1.0 / 16.0;
+
+// Return the diffuse color without taking into account the diffuse term of the particles.
+Vec3 computeLightColor(Vec3 fragPos, U32 plightCount, U32 plightIdx, U32 slightCount, U32 slightIdx)
+{
+	Vec3 outColor = Vec3(0.0);
+
+	// Point lights
+	ANKI_LOOP while(plightCount-- != 0)
+	{
+		PointLight light = u_pointLights[u_lightIndices[plightIdx++]];
+		Vec3 frag2Light = light.m_posRadius.xyz - fragPos;
+		F32 factor = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
+
+#if ENABLE_SHADOWS
+		if(light.m_diffuseColorTileSize.w >= 0.0)
+		{
+			factor *= computeShadowFactorOmni(frag2Light, 
+				light.m_radiusPad1.x, 
+				light.m_atlasTiles,
+				light.m_diffuseColorTileSize.w,
+				u_shadowTex);
+		}
+#endif
+
+		outColor += light.m_diffuseColorTileSize.rgb * factor;
+	}
+
+	// Spot lights
+	ANKI_LOOP while(slightCount-- != 0)
+	{
+		SpotLight light = u_spotLights[u_lightIndices[slightIdx++]];
+		Vec3 frag2Light = light.m_posRadius.xyz - fragPos;
+		F32 factor = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
+
+		Vec3 l = normalize(frag2Light);
+
+		factor *= computeSpotFactor(
+			l, light.m_outerCosInnerCos.x, light.m_outerCosInnerCos.y, light.m_lightDirRadius.xyz);
+
+#if ENABLE_SHADOWS
+		F32 shadowmapLayerIdx = light.m_diffuseColorShadowmapId.w;
+		if(shadowmapLayerIdx >= 0.0)
+		{
+			factor *= computeShadowFactorSpot(
+				light.m_texProjectionMat, fragPos, light.m_lightDirRadius.w, u_shadowTex);
+		}
+#endif
+
+		outColor += light.m_diffuseColorShadowmapId.rgb * factor;
+	}
+
+	return outColor;
+}
+
+Vec3 readHistory(Vec3 ndc, out F32 historyFeedback)
+{
+	Vec4 v4 = u_prevViewProjMatMulInvViewProjMat2 * Vec4(ndc, 1.0);
+	v4.xy /= v4.w;
+
+	Vec2 oldUv = NDC_TO_UV(v4.xy);
+	Vec3 history = textureLod(u_historyRt, oldUv, 0.0).rgb;
+
+	// Compute the history blend. If clip falls outside NDC then it's 1.0 (use only current fog term) and if it's
+	// inside NDC then use the HISTORY_FEEDBACK value
+	Vec2 posNdc = abs(v4.xy);
+	historyFeedback = max(posNdc.x, posNdc.y);
+	historyFeedback = min(floor(historyFeedback), 1.0 - HISTORY_FEEDBACK);
+	historyFeedback += HISTORY_FEEDBACK;
+
+	return history;
+}
+
+void main()
+{
+	F32 depth = textureLod(u_msDepthRt, in_uv, 0.0).r;
+
+	Vec3 ndc = Vec3(UV_TO_NDC(in_uv), depth);
+
+	Vec3 farPos;
+	farPos.z = u_unprojectionParams.z / (u_unprojectionParams.w + depth);
+	farPos.xy = ndc.xy * u_unprojectionParams.xy * farPos.z;
+	Vec3 viewDir = normalize(farPos);
+
+	U32 i = U32(in_uv.x * F32(CLUSTER_COUNT.x));
+	U32 j = U32(in_uv.y * F32(CLUSTER_COUNT.y));
+	U32 ij = j * CLUSTER_COUNT.x + i;
+
+	Vec3 noiseTexUv = Vec3(Vec2(FB_SIZE) / Vec2(NOISE_MAP_SIZE) * in_uv + Vec2(0.0, u_noiseYOffset), u_noiseLayer);
+	F32 randFactor = clamp(texture(u_noiseTex, noiseTexUv).r, EPSILON, 1.0 - EPSILON);
+
+	F32 kNear = -u_near;
+	Vec3 newCol = Vec3(0.0);
+	ANKI_LOOP for(U32 k = 0u; k < CLUSTER_COUNT.z; ++k)
+	{
+		F32 kFar = -computeClusterFar(u_clustererMagic, k);
+
+		//
+		// Compute sample count
+		//
+		F32 diff = kNear - kFar;
+		F32 samplesf = clamp(diff / DIST_BETWEEN_SAMPLES, 1.0, F32(MAX_SAMPLES_PER_CLUSTER));
+		F32 dist = 1.0 / samplesf;
+		F32 start = dist * randFactor;
+
+		//
+		// Find index ranges
+		//
+		U32 clusterIdx = k * (CLUSTER_COUNT.x * CLUSTER_COUNT.y) + ij;
+		U32 idxOffset = u_clusters[clusterIdx];
+
+		// Skip decals
+		U32 count = u_lightIndices[idxOffset];
+		idxOffset += count + 1;
+
+		U32 plightCount = u_lightIndices[idxOffset++];
+		U32 plightIdx = idxOffset;
+		idxOffset += plightCount;
+
+		U32 slightCount = u_lightIndices[idxOffset++];
+		U32 slightIdx = idxOffset;
+
+		ANKI_LOOP for(F32 factor = start; factor <= 1.0; factor += dist)
+		{
+			F32 zMedian = mix(kNear, kFar, factor);
+
+			ANKI_BRANCH if(zMedian < farPos.z)
+			{
+				k = CLUSTER_COUNT.z; // Break the outer loop
+				break;
+			}
+
+			Vec3 fragPos = viewDir * (zMedian / viewDir.z);
+
+			// Move to world space
+			Vec4 newWorldPos4 = u_invViewMat * Vec4(fragPos, 1.0);
+
+			newCol += computeLightColor(newWorldPos4.xyz, plightCount, plightIdx, slightCount, slightIdx);
+		}
+
+		kNear = kFar;
+	}
+
+	newCol *= diffuseLambert(u_fogParticleColor);
+
+	// Read history
+	F32 historyFeedback;
+	Vec3 history = readHistory(ndc, historyFeedback);
+	
+	// Fix ghosting
+	history = max(history, newCol);
+
+	// Blend
+	out_color = mix(history, newCol, historyFeedback);
+}
+			]]></source>
+		</shader>
+	</shaders>
+
+</shaderProgram>
+
+
+

+ 75 - 0
shaders/glsl_cpp_common/ClusteredShading.h

@@ -0,0 +1,75 @@
+// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_SHADERS_GLSL_CPP_COMMON_CLUSTERED_SHADING_H
+#define ANKI_SHADERS_GLSL_CPP_COMMON_CLUSTERED_SHADING_H
+
+#include <shaders/glsl_cpp_common/Clusterer.h>
+
+ANKI_BEGIN_NAMESPACE
+
+// Common uniforms between lights
+struct LightingUniforms
+{
+	Vec4 m_unprojectionParams;
+	Vec4 m_rendererSizeTimeNear;
+	Vec4 m_cameraPosFar;
+	ClustererMagicValues m_clustererMagicValues;
+	UVec4 m_tileCount;
+	Mat4 m_viewMat;
+	Mat4 m_invViewMat;
+	Mat4 m_projMat;
+	Mat4 m_invProjMat;
+	Mat4 m_viewProjMat;
+	Mat4 m_invViewProjMat;
+	Mat4 m_prevViewProjMat;
+	Mat4 m_prevViewProjMatMulInvViewProjMat; // Used to re-project previous frames
+};
+
+// Point light
+struct PointLight
+{
+	Vec4 m_posRadius; // xyz: Light pos in world space. w: The 1/(radius^2)
+	Vec4 m_diffuseColorTileSize; // xyz: diff color, w: tile size in the shadow atlas
+	Vec2 m_radiusPad1; // x: radius
+	UVec2 m_atlasTiles; // x: encodes 6 uints with atlas tile indices in the x dir. y: same for y dir.
+};
+const U32 SIZEOF_POINT_LIGHT = 3 * SIZEOF_VEC4;
+
+// Spot light
+struct SpotLight
+{
+	Vec4 m_posRadius; // xyz: Light pos in world space. w: The 1/(radius^2)
+	Vec4 m_diffuseColorShadowmapId; // xyz: diff color, w: shadowmap tex ID
+	Vec4 m_lightDirRadius; // xyz: light direction, w: radius
+	Vec4 m_outerCosInnerCos;
+	Mat4 m_texProjectionMat;
+};
+const U32 SIZEOF_SPOT_LIGHT = 4 * SIZEOF_VEC4 + SIZEOF_MAT4;
+
+// Representation of a reflection probe
+struct ReflectionProbe
+{
+	// Position of the prove in view space. Radius of probe squared
+	Vec4 m_positionRadiusSq;
+
+	// Slice in u_reflectionsTex vector.
+	Vec4 m_cubemapIndexPad3;
+};
+const U32 SIZEOF_REFLECTION_PROBE = 2 * SIZEOF_VEC4;
+
+// Decal
+struct Decal
+{
+	Vec4 m_diffUv;
+	Vec4 m_normRoughnessUv;
+	Mat4 m_texProjectionMat;
+	Vec4 m_blendFactors;
+};
+const U32 SIZEOF_DECAL = 3 * SIZEOF_VEC4 + SIZEOF_MAT4;
+
+ANKI_END_NAMESPACE
+
+#endif

+ 50 - 0
shaders/glsl_cpp_common/Clusterer.h

@@ -0,0 +1,50 @@
+// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_SHADERS_GLSL_CPP_COMMON_CLUSTERER_H
+#define ANKI_SHADERS_GLSL_CPP_COMMON_CLUSTERER_H
+
+#include <shaders/glsl_cpp_common/Common.h>
+
+ANKI_BEGIN_NAMESPACE
+
+// See the documentation in the Clusterer class.
+struct ClustererMagicValues
+{
+	Vec4 m_val0;
+	Vec4 m_val1;
+};
+
+ANKI_SHADER_FUNC_INLINE U32 computeClusterK(ClustererMagicValues magic, Vec3 worldPos)
+{
+	F32 fz = sqrt(dot(magic.m_val0.xyz(), worldPos) - magic.m_val0.w());
+	U32 z = U32(fz);
+	return z;
+}
+
+// Compute cluster index
+ANKI_SHADER_FUNC_INLINE U32 computeClusterIndex(
+	ClustererMagicValues magic, Vec2 uv, Vec3 worldPos, U32 clusterCountX, U32 clusterCountY)
+{
+	UVec2 xy = UVec2(uv * Vec2(clusterCountX, clusterCountY));
+
+	return computeClusterK(magic, worldPos) * (clusterCountX * clusterCountY) + xy.y() * clusterCountX + xy.x();
+}
+
+// Compute the Z of the near plane given a cluster idx
+ANKI_SHADER_FUNC_INLINE F32 computeClusterNear(ClustererMagicValues magic, U32 k)
+{
+	F32 fk = F32(k);
+	return magic.m_val1.x() * fk * fk + magic.m_val1.y();
+}
+
+ANKI_SHADER_FUNC_INLINE F32 computeClusterFar(ClustererMagicValues magic, U32 k)
+{
+	return computeClusterNear(magic, k + 1u);
+}
+
+ANKI_END_NAMESPACE
+
+#endif

+ 50 - 0
shaders/glsl_cpp_common/Common.h

@@ -0,0 +1,50 @@
+// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_SHADERS_GLSL_CPP_COMMON_COMMON_H
+#define ANKI_SHADERS_GLSL_CPP_COMMON_COMMON_H
+
+//
+// Macros & functions
+//
+#if defined(__cplusplus)
+#	define ANKI_BEGIN_NAMESPACE \
+		namespace anki \
+		{
+#	define ANKI_END_NAMESPACE }
+#	define ANKI_SHADER_FUNC_INLINE inline
+
+ANKI_BEGIN_NAMESPACE
+template<typename T>
+inline F32 dot(const T& a, const T& b)
+{
+	return a.dot(b);
+}
+ANKI_END_NAMESPACE
+
+#else
+#	define x() x
+#	define y() y
+#	define z() z
+#	define w() w
+
+#	define xyz() xyz
+
+#	define ANKI_BEGIN_NAMESPACE
+#	define ANKI_END_NAMESPACE
+#	define ANKI_SHADER_FUNC_INLINE
+#endif
+
+//
+// Consts
+//
+ANKI_BEGIN_NAMESPACE
+
+const U32 SIZEOF_VEC4 = 4u * 4u;
+const U32 SIZEOF_MAT4 = 4u * SIZEOF_VEC4;
+
+ANKI_END_NAMESPACE
+
+#endif

+ 23 - 0
shaders/glsl_cpp_common/LensFlareSprite.h

@@ -0,0 +1,23 @@
+// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_SHADERS_GLSL_CPP_COMMON_LENS_FLARE_SPRITE_H
+#define ANKI_SHADERS_GLSL_CPP_COMMON_LENS_FLARE_SPRITE_H
+
+#include <shaders/glsl_cpp_common/Common.h>
+
+ANKI_BEGIN_NAMESPACE
+
+// Per flare information
+struct LensFlareSprite
+{
+	Vec4 m_posScale; // xy: Position, zw: Scale
+	Vec4 m_color;
+	Vec4 m_depthPad3;
+};
+
+ANKI_END_NAMESPACE
+
+#endif

+ 38 - 0
shaders/glsl_cpp_common/TraditionalDeferredShading.h

@@ -0,0 +1,38 @@
+// Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_SHADERS_GLSL_CPP_COMMON_TRADITIONAL_DEFERRED_SHADING_H
+#define ANKI_SHADERS_GLSL_CPP_COMMON_TRADITIONAL_DEFERRED_SHADING_H
+
+#include <shaders/glsl_cpp_common/Common.h>
+
+ANKI_BEGIN_NAMESPACE
+
+struct DeferredPointLightUniforms
+{
+	Vec4 m_inputTexUvScaleAndOffset; // Use this to get the correct face UVs
+	Mat4 m_invViewProjMat;
+	Vec4 m_camPosPad1;
+
+	// Light props
+	Vec4 m_posRadius; // xyz: Light pos in world space. w: The -1/radius
+	Vec4 m_diffuseColorPad1; // xyz: diff color
+};
+
+struct DeferredSpotLightUniforms
+{
+	Vec4 m_inputTexUvScaleAndOffset; // Use this to get the correct face UVs
+	Mat4 m_invViewProjMat;
+	Vec4 m_camPosPad1;
+
+	// Light props
+	Vec4 m_posRadius; // xyz: Light pos in world space. w: The -1/radius
+	Vec4 m_diffuseColorOuterCos; // xyz: diff color, w: outer cosine of spot
+	Vec4 m_lightDirInnerCos; // xyz: light dir, w: inner cosine of spot
+};
+
+ANKI_END_NAMESPACE
+
+#endif

+ 19 - 0
src/anki/gr/ShaderCompiler.cpp

@@ -70,6 +70,25 @@ static const char* SHADER_HEADER = R"(#version 450 core
 #	endif
 #endif
 
+#define F32 float
+#define Vec2 vec2
+#define Vec3 vec3
+#define Vec4 vec4
+
+#define U32 uint
+#define UVec2 uvec2
+#define UVec3 uvec3
+#define UVec4 uvec4
+
+#define I32 int
+#define IVec2 ivec2
+#define IVec3 ivec3
+#define IVec4 ivec4
+
+#define Mat3 mat3
+#define Mat4 mat4
+#define Mat3x4 mat3x4
+
 %s)";
 
 static EShLanguage ankiToGlslangShaderType(ShaderType shaderType)

+ 9 - 19
src/anki/gr/vulkan/DescriptorSet.cpp

@@ -390,30 +390,20 @@ Error DSLayoutCacheEntry::init(const DescriptorBinding* bindings, U bindingCount
 		if(j == poolSizeCount)
 		{
 			m_poolSizesCreateInf[poolSizeCount].type = convertDescriptorType(bindings[i].m_type);
-
-			switch(m_poolSizesCreateInf[poolSizeCount].type)
-			{
-			case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-				m_poolSizesCreateInf[poolSizeCount].descriptorCount = MAX_TEXTURE_BINDINGS;
-				break;
-			case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
-				m_poolSizesCreateInf[poolSizeCount].descriptorCount = MAX_UNIFORM_BUFFER_BINDINGS;
-				break;
-			case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
-				m_poolSizesCreateInf[poolSizeCount].descriptorCount = MAX_STORAGE_BUFFER_BINDINGS;
-				break;
-			case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
-				m_poolSizesCreateInf[poolSizeCount].descriptorCount = MAX_IMAGE_BINDINGS;
-				break;
-			default:
-				ANKI_ASSERT(0);
-			}
-
 			m_poolSizesCreateInf[poolSizeCount].descriptorCount = 1;
 			++poolSizeCount;
 		}
 	}
 
+	if(poolSizeCount == 0)
+	{
+		// If the poolSizeCount it means that the DS layout has 0 descriptors. Since the pool sizes can't be zero put
+		// something in them
+		m_poolSizesCreateInf[0].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
+		m_poolSizesCreateInf[0].descriptorCount = 1;
+		++poolSizeCount;
+	}
+
 	ANKI_ASSERT(poolSizeCount > 0);
 
 	m_poolCreateInf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;

+ 6 - 0
src/anki/math/Vec2.h

@@ -59,6 +59,12 @@ public:
 		: Base(arr)
 	{
 	}
+
+	template<typename Y>
+	TVec2(const TVec2<Y>& b)
+		: Base(b.x(), b.y())
+	{
+	}
 	/// @}
 };
 

+ 3 - 3
src/anki/renderer/Bloom.cpp

@@ -41,7 +41,7 @@ Error Bloom::initExposure(const ConfigSet& config)
 	m_exposure.m_fbDescr.bake();
 
 	// init shaders
-	ANKI_CHECK(getResourceManager().loadResource("programs/Bloom.ankiprog", m_exposure.m_prog));
+	ANKI_CHECK(getResourceManager().loadResource("shaders/Bloom.ankiprog", m_exposure.m_prog));
 
 	ShaderProgramResourceConstantValueInitList<1> consts(m_exposure.m_prog);
 	consts.add(
@@ -70,7 +70,7 @@ Error Bloom::initUpscale(const ConfigSet& config)
 	m_upscale.m_fbDescr.bake();
 
 	// init shaders
-	ANKI_CHECK(getResourceManager().loadResource("programs/BloomUpscale.ankiprog", m_upscale.m_prog));
+	ANKI_CHECK(getResourceManager().loadResource("shaders/BloomUpscale.ankiprog", m_upscale.m_prog));
 
 	ShaderProgramResourceConstantValueInitList<1> consts(m_upscale.m_prog);
 	consts.add("TEX_SIZE", Vec2(m_upscale.m_width, m_upscale.m_height));
@@ -85,7 +85,7 @@ Error Bloom::initUpscale(const ConfigSet& config)
 Error Bloom::initSslf(const ConfigSet& cfg)
 {
 	ANKI_CHECK(getResourceManager().loadResource("engine_data/LensDirt.ankitex", m_sslf.m_lensDirtTex));
-	ANKI_CHECK(getResourceManager().loadResource("programs/ScreenSpaceLensFlare.ankiprog", m_sslf.m_prog));
+	ANKI_CHECK(getResourceManager().loadResource("shaders/ScreenSpaceLensFlare.ankiprog", m_sslf.m_prog));
 
 	ShaderProgramResourceConstantValueInitList<1> consts(m_sslf.m_prog);
 	consts.add("INPUT_TEX_SIZE", UVec2(m_exposure.m_width, m_exposure.m_height));

+ 3 - 9
src/anki/renderer/Clusterer.h

@@ -8,6 +8,7 @@
 #include <anki/renderer/Common.h>
 #include <anki/Math.h>
 #include <anki/collision/Aabb.h>
+#include <shaders/glsl_cpp_common/Clusterer.h>
 
 namespace anki
 {
@@ -129,13 +130,6 @@ public:
 	F32 m_far;
 };
 
-/// Some transparent valued used by shaders.
-struct ClustererShaderMagicValues
-{
-	Vec4 m_val0;
-	Vec4 m_val1;
-};
-
 /// Collection of clusters for visibility tests.
 class Clusterer
 {
@@ -163,7 +157,7 @@ public:
 
 	/// A value that will be used in shaders to calculate the cluster index. See the code that calculates it for info
 	/// on what it is.
-	const ClustererShaderMagicValues& getShaderMagicValues() const
+	const ClustererMagicValues& getShaderMagicValues() const
 	{
 		return m_shaderMagicVals;
 	}
@@ -218,7 +212,7 @@ private:
 	F32 m_near = 0.0;
 	F32 m_far = 0.0;
 	F32 m_calcNearOpt = 0.0f;
-	ClustererShaderMagicValues m_shaderMagicVals = {Vec4(0.0f), Vec4(0.0f)};
+	ClustererMagicValues m_shaderMagicVals = {Vec4(0.0f), Vec4(0.0f)};
 
 	F32 calcNear(U k) const;
 

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff