diff options
Diffstat (limited to 'tests/playground')
-rw-r--r-- | tests/playground/array.frag | 49 | ||||
-rw-r--r-- | tests/playground/cbuf.frag | 21 | ||||
-rw-r--r-- | tests/playground/color.frag | 10 | ||||
-rw-r--r-- | tests/playground/color.vert | 18 | ||||
-rw-r--r-- | tests/playground/color_pc.frag | 12 | ||||
-rw-r--r-- | tests/playground/color_pc.vert | 14 | ||||
-rw-r--r-- | tests/playground/color_phong.frag | 39 | ||||
-rw-r--r-- | tests/playground/color_phong.vert | 32 | ||||
-rw-r--r-- | tests/playground/fragcolor.inc | 1 | ||||
-rw-r--r-- | tests/playground/hlsl_cbuf_error.frag | 47 | ||||
-rw-r--r-- | tests/playground/includetest.frag | 10 | ||||
-rw-r--r-- | tests/playground/texture.frag | 12 | ||||
-rw-r--r-- | tests/playground/texture.vert | 18 |
13 files changed, 283 insertions, 0 deletions
diff --git a/tests/playground/array.frag b/tests/playground/array.frag new file mode 100644 index 0000000..ef3df3d --- /dev/null +++ b/tests/playground/array.frag @@ -0,0 +1,49 @@ +#version 440 + +layout(location = 0) in vec3 vECVertNormal; +layout(location = 1) in vec3 vECVertPos; +layout(location = 2) flat in vec3 vDiffuseAdjust; + +#define MAX_LIGHTS 10 + +struct Light { + vec3 ECLightPosition; + vec3 attenuation; + vec3 color; + float intensity; + float specularExp; + // two dummies so that it stays translatable to HLSL with packoffset in the top-level block + float __dummy0; + float __dummy1; +}; + +layout(std140, binding = 1) uniform buf { + vec3 ECCameraPosition; + vec3 ka; + vec3 kd; + vec3 ks; + Light lights[MAX_LIGHTS]; + int numLights; + layout(row_major) mat3 mm; +} ubuf; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + vec3 unnormL = ubuf.lights[0].ECLightPosition - vECVertPos; + float dist = length(unnormL); + float att = 1.0 / (ubuf.lights[0].attenuation.x + ubuf.lights[0].attenuation.y * dist + ubuf.lights[0].attenuation.z * dist * dist); + + vec3 N = normalize(vECVertNormal); + vec3 L = normalize(unnormL); + float NL = max(0.0, dot(N, L)); + vec3 dColor = att * ubuf.lights[0].intensity * ubuf.lights[0].color * NL; + + vec3 R = reflect(-L, N); + vec3 V = normalize(ubuf.ECCameraPosition - vECVertPos); + float RV = max(0.0, dot(R, V)); + vec3 sColor = att * ubuf.lights[0].intensity * ubuf.lights[0].color * pow(RV, ubuf.lights[0].specularExp); + + fragColor = vec4(ubuf.ka + (ubuf.kd + vDiffuseAdjust) * dColor + ubuf.ks * sColor, 1.0); +} diff --git a/tests/playground/cbuf.frag b/tests/playground/cbuf.frag new file mode 100644 index 0000000..0091443 --- /dev/null +++ b/tests/playground/cbuf.frag @@ -0,0 +1,21 @@ +#version 440 + +layout(location = 0) in vec3 vECVertNormal; +layout(location = 1) in vec3 vECVertPos; + +layout(std140, binding = 1) uniform buf { + vec3 v; + float f; +} ubuf; + +layout(std140, binding = 2) uniform buf2 { + float f; + vec3 v; +} ubuf2; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + fragColor = vec4(ubuf.v, ubuf.f); +} diff --git a/tests/playground/color.frag b/tests/playground/color.frag new file mode 100644 index 0000000..3755876 --- /dev/null +++ b/tests/playground/color.frag @@ -0,0 +1,10 @@ +#version 440 + +layout(location = 0) in vec3 v_color; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + fragColor = vec4(v_color, 1.0); +} diff --git a/tests/playground/color.vert b/tests/playground/color.vert new file mode 100644 index 0000000..02492c0 --- /dev/null +++ b/tests/playground/color.vert @@ -0,0 +1,18 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec3 color; + +layout(location = 0) out vec3 v_color; + +layout(std140, binding = 0) uniform buf { + mat4 mvp; +} ubuf; + +out gl_PerVertex { vec4 gl_Position; }; + +void main() +{ + v_color = color; + gl_Position = ubuf.mvp * position; +} diff --git a/tests/playground/color_pc.frag b/tests/playground/color_pc.frag new file mode 100644 index 0000000..3b04955 --- /dev/null +++ b/tests/playground/color_pc.frag @@ -0,0 +1,12 @@ +#version 440 + +layout(push_constant) uniform PC { + layout(offset = 64) vec3 color; +} pc; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + fragColor = vec4(pc.color, 1.0); +} diff --git a/tests/playground/color_pc.vert b/tests/playground/color_pc.vert new file mode 100644 index 0000000..19bf815 --- /dev/null +++ b/tests/playground/color_pc.vert @@ -0,0 +1,14 @@ +#version 440 + +layout(location = 0) in vec4 position; + +out gl_PerVertex { vec4 gl_Position; }; + +layout(push_constant) uniform PC { + mat4 mvp; +} pc; + +void main() +{ + gl_Position = pc.mvp * position; +} diff --git a/tests/playground/color_phong.frag b/tests/playground/color_phong.frag new file mode 100644 index 0000000..8b0c715 --- /dev/null +++ b/tests/playground/color_phong.frag @@ -0,0 +1,39 @@ +#version 440 + +layout(location = 0) in vec3 vECVertNormal; +layout(location = 1) in vec3 vECVertPos; +layout(location = 2) flat in vec3 vDiffuseAdjust; + +layout(std140, binding = 1) uniform buf { + vec3 ECCameraPosition; + vec3 ka; + vec3 kd; + vec3 ks; + // Have one light only for now. + vec3 ECLightPosition; + vec3 attenuation; + vec3 color; + float intensity; + float specularExp; +} ubuf; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + vec3 unnormL = ubuf.ECLightPosition - vECVertPos; + float dist = length(unnormL); + float att = 1.0 / (ubuf.attenuation.x + ubuf.attenuation.y * dist + ubuf.attenuation.z * dist * dist); + + vec3 N = normalize(vECVertNormal); + vec3 L = normalize(unnormL); + float NL = max(0.0, dot(N, L)); + vec3 dColor = att * ubuf.intensity * ubuf.color * NL; + + vec3 R = reflect(-L, N); + vec3 V = normalize(ubuf.ECCameraPosition - vECVertPos); + float RV = max(0.0, dot(R, V)); + vec3 sColor = att * ubuf.intensity * ubuf.color * pow(RV, ubuf.specularExp); + + fragColor = vec4(ubuf.ka + (ubuf.kd + vDiffuseAdjust) * dColor + ubuf.ks * sColor, 1.0); +} diff --git a/tests/playground/color_phong.vert b/tests/playground/color_phong.vert new file mode 100644 index 0000000..a1d1552 --- /dev/null +++ b/tests/playground/color_phong.vert @@ -0,0 +1,32 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec3 normal; + +// Instanced attributes to variate the translation of the model and the diffuse +// color of the material. +layout(location = 2) in vec3 instTranslate; +layout(location = 3) in vec3 instDiffuseAdjust; + +out gl_PerVertex { vec4 gl_Position; }; +layout(location = 0) out vec3 vECVertNormal; +layout(location = 1) out vec3 vECVertPos; +layout(location = 2) flat out vec3 vDiffuseAdjust; + +layout(std140, binding = 0) uniform buf { + mat4 vp; + mat4 model; + mat3 modelNormal; +} ubuf; + +void main() +{ + vECVertNormal = normalize(ubuf.modelNormal * normal); + mat4 t = mat4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + instTranslate.x, instTranslate.y, instTranslate.z, 1); + vECVertPos = vec3(t * ubuf.model * position); + vDiffuseAdjust = instDiffuseAdjust; + gl_Position = ubuf.vp * t * ubuf.model * position; +} diff --git a/tests/playground/fragcolor.inc b/tests/playground/fragcolor.inc new file mode 100644 index 0000000..26ca216 --- /dev/null +++ b/tests/playground/fragcolor.inc @@ -0,0 +1 @@ + fragColor = vec4(v_color, 1.0); diff --git a/tests/playground/hlsl_cbuf_error.frag b/tests/playground/hlsl_cbuf_error.frag new file mode 100644 index 0000000..ba59ffa --- /dev/null +++ b/tests/playground/hlsl_cbuf_error.frag @@ -0,0 +1,47 @@ +#version 440 + +layout(location = 0) in vec3 vECVertNormal; +layout(location = 1) in vec3 vECVertPos; +layout(location = 2) flat in vec3 vDiffuseAdjust; + +#define MAX_LIGHTS 10 + +struct Light { + vec3 ECLightPosition; + vec3 attenuation; + vec3 color; + float intensity; + float specularExp; + // this is not translatable to HLSL +}; + +layout(std140, binding = 1) uniform buf { + vec3 ECCameraPosition; + vec3 ka; + vec3 kd; + vec3 ks; + Light lights[MAX_LIGHTS]; + int numLights; + layout(row_major) mat3 mm; +} ubuf; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + vec3 unnormL = ubuf.lights[0].ECLightPosition - vECVertPos; + float dist = length(unnormL); + float att = 1.0 / (ubuf.lights[0].attenuation.x + ubuf.lights[0].attenuation.y * dist + ubuf.lights[0].attenuation.z * dist * dist); + + vec3 N = normalize(vECVertNormal); + vec3 L = normalize(unnormL); + float NL = max(0.0, dot(N, L)); + vec3 dColor = att * ubuf.lights[0].intensity * ubuf.lights[0].color * NL; + + vec3 R = reflect(-L, N); + vec3 V = normalize(ubuf.ECCameraPosition - vECVertPos); + float RV = max(0.0, dot(R, V)); + vec3 sColor = att * ubuf.lights[0].intensity * ubuf.lights[0].color * pow(RV, ubuf.lights[0].specularExp); + + fragColor = vec4(ubuf.ka + (ubuf.kd + vDiffuseAdjust) * dColor + ubuf.ks * sColor, 1.0); +} diff --git a/tests/playground/includetest.frag b/tests/playground/includetest.frag new file mode 100644 index 0000000..99dceae --- /dev/null +++ b/tests/playground/includetest.frag @@ -0,0 +1,10 @@ +#version 440 +#extension GL_GOOGLE_include_directive : enable + +layout(location = 0) in vec3 v_color; +layout(location = 0) out vec4 fragColor; + +void main() +{ +#include "fragcolor.inc" +} diff --git a/tests/playground/texture.frag b/tests/playground/texture.frag new file mode 100644 index 0000000..e6021fe --- /dev/null +++ b/tests/playground/texture.frag @@ -0,0 +1,12 @@ +#version 440 + +layout(location = 0) in vec2 v_texcoord; + +layout(location = 0) out vec4 fragColor; + +layout(binding = 1) uniform sampler2D tex; + +void main() +{ + fragColor = texture(tex, v_texcoord); +} diff --git a/tests/playground/texture.vert b/tests/playground/texture.vert new file mode 100644 index 0000000..de486cb --- /dev/null +++ b/tests/playground/texture.vert @@ -0,0 +1,18 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec2 texcoord; + +layout(location = 0) out vec2 v_texcoord; + +layout(std140, binding = 0) uniform buf { + mat4 mvp; +} ubuf; + +out gl_PerVertex { vec4 gl_Position; }; + +void main() +{ + v_texcoord = texcoord; + gl_Position = ubuf.mvp * position; +} |