Added starfield backdrop to instancing example

This commit is contained in:
saschawillems 2017-01-08 12:27:03 +01:00
parent d335e7be29
commit bb9310b94a
10 changed files with 70 additions and 2 deletions

View file

@ -20,7 +20,7 @@ void main()
vec3 L = normalize(inLightVec);
vec3 V = normalize(inViewVec);
vec3 R = reflect(-L, N);
vec3 diffuse = max(dot(N, L), 0.0) * inColor;
vec3 diffuse = max(dot(N, L), 0.1) * inColor;
vec3 specular = (dot(N,L) > 0.0) ? pow(max(dot(R, V), 0.0), 16.0) * vec3(0.75) * color.r : vec3(0.0);
outFragColor = vec4(diffuse * color.rgb + specular, 1.0);
}

View file

@ -0,0 +1,34 @@
#version 450
layout (location = 0) in vec3 inUVW;
layout (location = 0) out vec4 outFragColor;
#define HASHSCALE3 vec3(443.897, 441.423, 437.195)
#define STARFREQUENCY 0.01
// Hash function by Dave Hoskins (https://www.shadertoy.com/view/4djSRW)
float hash33(vec3 p3)
{
p3 = fract(p3 * HASHSCALE3);
p3 += dot(p3, p3.yxz+vec3(19.19));
return fract((p3.x + p3.y)*p3.z + (p3.x+p3.z)*p3.y + (p3.y+p3.z)*p3.x);
}
vec3 starField(vec3 pos)
{
vec3 color = vec3(0.0);
float threshhold = (1.0 - STARFREQUENCY);
float rnd = hash33(pos);
if (rnd >= threshhold)
{
float starCol = pow((rnd - threshhold) / (1.0 - threshhold), 16.0);
color += vec3(starCol);
}
return color;
}
void main()
{
outFragColor = vec4(starField(inUVW), 1.0);
}

Binary file not shown.

View file

@ -0,0 +1,9 @@
#version 450
layout (location = 0) out vec3 outUVW;
void main()
{
outUVW = vec3((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2, gl_VertexIndex & 2);
gl_Position = vec4(outUVW.st * 2.0f - 1.0f, 0.0f, 1.0f);
}

Binary file not shown.