first commit
This commit is contained in:
141
shader/Atomsphere.frag
Normal file
141
shader/Atomsphere.frag
Normal file
@@ -0,0 +1,141 @@
|
||||
#version 450 core
|
||||
|
||||
#define PI 3.141592
|
||||
#define iSteps 16
|
||||
#define jSteps 8
|
||||
|
||||
layout(location = 0) in vec4 FragmentVertex;
|
||||
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
layout(binding = 1) uniform AtomSphere
|
||||
{
|
||||
vec3 position;
|
||||
float intensity;
|
||||
float scattering_direction;
|
||||
}sun;
|
||||
|
||||
vec2 rsi(vec3 r0, vec3 rd, float sr) {
|
||||
// ray-sphere intersection that assumes
|
||||
// the sphere is centered at the origin.
|
||||
// No intersection when result.x > result.y
|
||||
float a = dot(rd, rd);
|
||||
float b = 2.0 * dot(rd, r0);
|
||||
float c = dot(r0, r0) - (sr * sr);
|
||||
float d = (b*b) - 4.0*a*c;
|
||||
if (d < 0.0) return vec2(1e5,-1e5);
|
||||
return vec2(
|
||||
(-b - sqrt(d))/(2.0*a),
|
||||
(-b + sqrt(d))/(2.0*a)
|
||||
);
|
||||
}
|
||||
|
||||
vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g)
|
||||
{
|
||||
// Normalize the sun and view directions.
|
||||
pSun = normalize(pSun);
|
||||
r = normalize(r);
|
||||
|
||||
// Calculate the step size of the primary ray.
|
||||
vec2 p = rsi(r0, r, rAtmos);
|
||||
if (p.x > p.y) return vec3(0,0,0);
|
||||
p.y = min(p.y, rsi(r0, r, rPlanet).x);
|
||||
float iStepSize = (p.y - p.x) / float(iSteps);
|
||||
|
||||
// Initialize the primary ray time.
|
||||
float iTime = 0.0;
|
||||
|
||||
// Initialize accumulators for Rayleigh and Mie scattering.
|
||||
vec3 totalRlh = vec3(0,0,0);
|
||||
vec3 totalMie = vec3(0,0,0);
|
||||
|
||||
// Initialize optical depth accumulators for the primary ray.
|
||||
float iOdRlh = 0.0;
|
||||
float iOdMie = 0.0;
|
||||
|
||||
// Calculate the Rayleigh and Mie phases.
|
||||
float mu = dot(r, pSun);
|
||||
float mumu = mu * mu;
|
||||
float gg = g * g;
|
||||
float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);
|
||||
float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg));
|
||||
|
||||
// Sample the primary ray.
|
||||
for (int i = 0; i < iSteps; i++) {
|
||||
|
||||
// Calculate the primary ray sample position.
|
||||
vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);
|
||||
|
||||
// Calculate the height of the sample.
|
||||
float iHeight = length(iPos) - rPlanet;
|
||||
|
||||
// Calculate the optical depth of the Rayleigh and Mie scattering for this step.
|
||||
float odStepRlh = exp(-iHeight / shRlh) * iStepSize;
|
||||
float odStepMie = exp(-iHeight / shMie) * iStepSize;
|
||||
|
||||
// Accumulate optical depth.
|
||||
iOdRlh += odStepRlh;
|
||||
iOdMie += odStepMie;
|
||||
|
||||
// Calculate the step size of the secondary ray.
|
||||
float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);
|
||||
|
||||
// Initialize the secondary ray time.
|
||||
float jTime = 0.0;
|
||||
|
||||
// Initialize optical depth accumulators for the secondary ray.
|
||||
float jOdRlh = 0.0;
|
||||
float jOdMie = 0.0;
|
||||
|
||||
// Sample the secondary ray.
|
||||
for (int j = 0; j < jSteps; j++) {
|
||||
|
||||
// Calculate the secondary ray sample position.
|
||||
vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);
|
||||
|
||||
// Calculate the height of the sample.
|
||||
float jHeight = length(jPos) - rPlanet;
|
||||
|
||||
// Accumulate the optical depth.
|
||||
jOdRlh += exp(-jHeight / shRlh) * jStepSize;
|
||||
jOdMie += exp(-jHeight / shMie) * jStepSize;
|
||||
|
||||
// Increment the secondary ray time.
|
||||
jTime += jStepSize;
|
||||
}
|
||||
|
||||
// Calculate attenuation.
|
||||
vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));
|
||||
|
||||
// Accumulate scattering.
|
||||
totalRlh += odStepRlh * attn;
|
||||
totalMie += odStepMie * attn;
|
||||
|
||||
// Increment the primary ray time.
|
||||
iTime += iStepSize;
|
||||
}
|
||||
|
||||
// Calculate and return the final color.
|
||||
return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 nrd=vec3(FragmentVertex.x,-FragmentVertex.y,FragmentVertex.z); //vulkan coord to opengl(shader from opengl sample)
|
||||
|
||||
vec3 color=atmosphere(
|
||||
nrd, // normalized ray direction
|
||||
vec3(0,6372e3,0), // ray origin
|
||||
sun.position, // position of the sun
|
||||
sun.intensity, // intensity of the sun
|
||||
6371e3, // radius of the planet in meters
|
||||
6471e3, // radius of the atmosphere in meters
|
||||
vec3(5.5e-6, 13.0e-6, 22.4e-6), // Rayleigh scattering coefficient
|
||||
21e-6, // Mie scattering coefficient
|
||||
8e3, // Rayleigh scale height
|
||||
1.2e3, // Mie scale height
|
||||
sun.scattering_direction // Mie preferred scattering direction
|
||||
);
|
||||
|
||||
FragColor=vec4(1.0-exp(-color),1);
|
||||
}
|
32
shader/Atomsphere.vert
Normal file
32
shader/Atomsphere.vert
Normal file
@@ -0,0 +1,32 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 Vertex;
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
layout(location = 0) out vec4 FragmentVertex;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentVertex=vec4(Vertex,1.0)*pc.local_to_world*world.mvp;
|
||||
gl_Position=FragmentVertex;
|
||||
}
|
13
shader/FlatColor.frag
Normal file
13
shader/FlatColor.frag
Normal file
@@ -0,0 +1,13 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=1) uniform ColorMaterial
|
||||
{
|
||||
vec4 color;
|
||||
} color_material;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=color_material.color;
|
||||
}
|
0
shader/FlatColor.material
Normal file
0
shader/FlatColor.material
Normal file
30
shader/FlatColor.vert
Normal file
30
shader/FlatColor.vert
Normal file
@@ -0,0 +1,30 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
layout(location = 1) in vec3 Color;
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
||||
|
||||
layout(location = 0) out vec4 FragmentColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentColor=vec4(Color,1.0);
|
||||
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*world.ortho;
|
||||
}
|
27
shader/FlatColor3D.vert
Normal file
27
shader/FlatColor3D.vert
Normal file
@@ -0,0 +1,27 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 Vertex;
|
||||
layout(location = 1) in vec3 Color;
|
||||
layout(location = 2) in vec3 Normal;
|
||||
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
mat4 ortho;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
vec4 view_pos;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
layout(location = 0) out vec4 FragmentColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentColor=vec4(Color,1.0);
|
||||
|
||||
gl_Position=vec4(Vertex,1.0)*world.mvp;
|
||||
}
|
11
shader/FlatTexture.frag
Normal file
11
shader/FlatTexture.frag
Normal file
@@ -0,0 +1,11 @@
|
||||
#version 450 core
|
||||
|
||||
layout(binding = 2) uniform sampler2D tex;
|
||||
|
||||
layout(location = 0) in vec2 FragmentTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(tex,FragmentTexCoord);
|
||||
}
|
22
shader/FlatTexture.vert
Normal file
22
shader/FlatTexture.vert
Normal file
@@ -0,0 +1,22 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
mat4 ortho;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
vec4 view_pos;
|
||||
} world;
|
||||
|
||||
layout(location = 0) out vec2 FragmentTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentTexCoord=TexCoord;
|
||||
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*world.ortho;
|
||||
}
|
25
shader/FragCoord.frag
Normal file
25
shader/FragCoord.frag
Normal file
@@ -0,0 +1,25 @@
|
||||
#version 450 core
|
||||
|
||||
layout(binding=1) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
}fragment_world;
|
||||
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=vec4(gl_FragCoord.xy/fragment_world.resolution,0,1);
|
||||
}
|
25
shader/OnlyPosition.vert
Normal file
25
shader/OnlyPosition.vert
Normal file
@@ -0,0 +1,25 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*world.ortho;
|
||||
}
|
29
shader/OnlyPosition3D.vert
Normal file
29
shader/OnlyPosition3D.vert
Normal file
@@ -0,0 +1,29 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 Vertex;
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Vertex,1.0)*(pc.local_to_world*world.mvp);
|
||||
}
|
38
shader/PositionColor3D.vert
Normal file
38
shader/PositionColor3D.vert
Normal file
@@ -0,0 +1,38 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 Vertex;
|
||||
layout(location = 1) in vec4 Color;
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts
|
||||
{
|
||||
mat4 local_to_world;
|
||||
mat3 normal;
|
||||
vec3 object_position;
|
||||
vec3 object_size;
|
||||
}pc;
|
||||
|
||||
layout(location = 0) out vec4 FragmentColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentColor=Color;
|
||||
|
||||
gl_Position=vec4(Vertex,1.0)*(pc.local_to_world*world.mvp);
|
||||
}
|
4
shader/Random.glsl
Normal file
4
shader/Random.glsl
Normal file
@@ -0,0 +1,4 @@
|
||||
vec3 random(vec2 uv) // from Godot 3.2
|
||||
{
|
||||
return vec3(fract(sin(dot(uv,vec2(12.9898,78.233)))*43758.5453123));
|
||||
}
|
16
shader/Texture2D.vert
Normal file
16
shader/Texture2D.vert
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
|
||||
layout(location = 0) out vec2 FragmentTexCoord;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*pc.local_to_world;
|
||||
FragmentTexCoord=TexCoord;
|
||||
}
|
85
shader/ToneMapping.glsl
Normal file
85
shader/ToneMapping.glsl
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
|
||||
This shader experiments the effect of different tone mapping operators.
|
||||
This is still a work in progress.
|
||||
|
||||
More info:
|
||||
http://slideshare.net/ozlael/hable-john-uncharted2-hdr-lighting
|
||||
http://filmicgames.com/archives/75
|
||||
http://filmicgames.com/archives/183
|
||||
http://filmicgames.com/archives/190
|
||||
http://imdoingitwrong.wordpress.com/2010/08/19/why-reinhard-desaturates-my-blacks-3/
|
||||
http://mynameismjp.wordpress.com/2010/04/30/a-closer-look-at-tone-mapping/
|
||||
http://renderwonk.com/publications/s2010-color-course/
|
||||
|
||||
--
|
||||
Zavie
|
||||
|
||||
*/
|
||||
|
||||
vec3 linearToneMapping(vec3 color)
|
||||
{
|
||||
float exposure = 1.;
|
||||
color = clamp(exposure * color, 0., 1.);
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 simpleReinhardToneMapping(vec3 color)
|
||||
{
|
||||
float exposure = 1.5;
|
||||
color *= exposure/(1. + color / exposure);
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 lumaBasedReinhardToneMapping(vec3 color)
|
||||
{
|
||||
float luma = dot(color, vec3(0.2126, 0.7152, 0.0722));
|
||||
float toneMappedLuma = luma / (1. + luma);
|
||||
color *= toneMappedLuma / luma;
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 whitePreservingLumaBasedReinhardToneMapping(vec3 color)
|
||||
{
|
||||
float white = 2.;
|
||||
float luma = dot(color, vec3(0.2126, 0.7152, 0.0722));
|
||||
float toneMappedLuma = luma * (1. + luma / (white*white)) / (1. + luma);
|
||||
color *= toneMappedLuma / luma;
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 RomBinDaHouseToneMapping(vec3 color)
|
||||
{
|
||||
color = exp( -1.0 / ( 2.72*color + 0.15 ) );
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 filmicToneMapping(vec3 color)
|
||||
{
|
||||
color = max(vec3(0.), color - vec3(0.004));
|
||||
color = (color * (6.2 * color + .5)) / (color * (6.2 * color + 1.7) + 0.06);
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 Uncharted2ToneMapping(vec3 color)
|
||||
{
|
||||
float A = 0.15;
|
||||
float B = 0.50;
|
||||
float C = 0.10;
|
||||
float D = 0.20;
|
||||
float E = 0.02;
|
||||
float F = 0.30;
|
||||
float W = 11.2;
|
||||
float exposure = 2.;
|
||||
color *= exposure;
|
||||
color = ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F;
|
||||
float white = ((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F;
|
||||
color /= white;
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
return color;
|
||||
}
|
15
shader/UBO_WorldMatrix.glsl
Normal file
15
shader/UBO_WorldMatrix.glsl
Normal file
@@ -0,0 +1,15 @@
|
||||
layout(std430,binding = 0,row_major) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
} world;
|
9
shader/VertexColor.frag
Normal file
9
shader/VertexColor.frag
Normal file
@@ -0,0 +1,9 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec4 FragmentColor;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=FragmentColor;
|
||||
}
|
9
shader/VertexNormal.frag
Normal file
9
shader/VertexNormal.frag
Normal file
@@ -0,0 +1,9 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec4 FragmentNormal;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=FragmentNormal;
|
||||
}
|
16
shader/WorldMatrix.ubo
Normal file
16
shader/WorldMatrix.ubo
Normal file
@@ -0,0 +1,16 @@
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
28
shader/c_gbuffer.frag
Normal file
28
shader/c_gbuffer.frag
Normal file
@@ -0,0 +1,28 @@
|
||||
#version 450 core
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerAlbedo;
|
||||
layout (binding = 2) uniform sampler2D samplerNormalMap;
|
||||
|
||||
layout(location = 0) in vec3 FragmentColor;
|
||||
layout(location = 1) in vec3 FragmentNormal;
|
||||
layout(location = 2) in vec3 FragmentTangent;
|
||||
layout(location = 3) in vec3 FragmentWorldPos;
|
||||
layout(location = 4) in vec2 FragmentTexCoord;
|
||||
|
||||
layout (location = 0) out vec4 FragAlbedo;
|
||||
layout (location = 1) out vec4 FragNormal;
|
||||
layout (location = 2) out vec4 FragWorldPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragWorldPos=vec4(FragmentWorldPos,1.0);
|
||||
FragAlbedo =texture(samplerAlbedo,FragmentTexCoord)*vec4(FragmentColor,1.0);
|
||||
|
||||
vec3 N = normalize(FragmentNormal);
|
||||
N.y = -N.y;
|
||||
vec3 T = normalize(FragmentTangent);
|
||||
vec3 B = cross(N, T);
|
||||
mat3 TBN = mat3(T, B, N);
|
||||
vec3 tnorm = TBN * normalize(texture(samplerNormalMap, FragmentTexCoord).xyz * 2.0 - vec3(1.0));
|
||||
FragNormal = vec4(tnorm, 1.0);
|
||||
}
|
40
shader/c_gbuffer.vert
Normal file
40
shader/c_gbuffer.vert
Normal file
@@ -0,0 +1,40 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 Vertex;
|
||||
layout(location = 1) in vec3 Color;
|
||||
layout(location = 2) in vec3 Normal;
|
||||
layout(location = 3) in vec3 Tangent;
|
||||
layout(location = 4) in vec2 TexCoord;
|
||||
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
mat4 two_dim;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
mat3 normal;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
layout(location = 0) out vec3 FragmentColor;
|
||||
layout(location = 1) out vec3 FragmentNormal;
|
||||
layout(location = 2) out vec3 FragmentTangent;
|
||||
layout(location = 3) out vec3 FragmentWorldPos;
|
||||
layout(location = 4) out vec2 FragmentTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentColor=Color;
|
||||
FragmentWorldPos=vec3(vec4(Vertex,1.0)*pc.local_to_world);
|
||||
FragmentTexCoord=TexCoord;
|
||||
FragmentTexCoord.t=1.0-TexCoord.t;
|
||||
|
||||
mat3 mNormal=transpose(inverse(mat3(pc.local_to_world)));
|
||||
FragmentNormal=mNormal*normalize(Normal);
|
||||
FragmentTangent=mNormal*normalize(Tangent);
|
||||
|
||||
gl_Position=vec4(Vertex,1.0)*world.mvp;
|
||||
}
|
27
shader/cnmr.gbuffer
Normal file
27
shader/cnmr.gbuffer
Normal file
@@ -0,0 +1,27 @@
|
||||
[attribute]
|
||||
|
||||
vec3 BaseColor;
|
||||
vec3 Normal;
|
||||
float Metallic;
|
||||
float Roughness;
|
||||
|
||||
[gbuffer]
|
||||
|
||||
vec4 gb_color_metallic;
|
||||
vec4 gb_normal_roughness;
|
||||
|
||||
[attribute_to_gbuffer]
|
||||
|
||||
gb_color_metallic =vec4(BaseColor,Metallic);
|
||||
gb_normal_roughness =vec4(Normal, Roughness);
|
||||
|
||||
[gbuffer_to_attribute]
|
||||
|
||||
vec4 gb_cm=texture(gb_color_metallic,FragmentPosition);
|
||||
vec4 gb_cr=texture(gb_normal_roughness,FragmentPosition);
|
||||
|
||||
BaseColor =gb_cm.rgb;
|
||||
Metallic =gb_cm.a;
|
||||
|
||||
Normal =gb_cr.rgb;
|
||||
Roughness =gb_cr.a;
|
23
shader/cnp.gbuffer
Normal file
23
shader/cnp.gbuffer
Normal file
@@ -0,0 +1,23 @@
|
||||
[attribute]
|
||||
|
||||
vec3 BaseColor;
|
||||
vec3 Normal;
|
||||
vec3 Position;
|
||||
|
||||
[gbuffer]
|
||||
|
||||
vec3 gb_color;
|
||||
vec3 gb_normal;
|
||||
vec3 gb_position;
|
||||
|
||||
[attribute_to_gbuffer]
|
||||
|
||||
gb_color=BaseColor;
|
||||
gb_normal=Normal;
|
||||
gb_position=Position;
|
||||
|
||||
[gbuffer_to_attribute]
|
||||
|
||||
BaseColor =texture(gb_color, FragmentPosition);
|
||||
Normal =texture(gb_normal, FragmentPosition);
|
||||
Position =texture(gb_position, FragmentPosition);
|
15
shader/color.gbuffer
Normal file
15
shader/color.gbuffer
Normal file
@@ -0,0 +1,15 @@
|
||||
[attribute]
|
||||
|
||||
vec4 BaseColor;
|
||||
|
||||
[gbuffer]
|
||||
|
||||
vec4 gb_color;
|
||||
|
||||
[attribute_to_gbuffer]
|
||||
|
||||
gb_color=BaseColor;
|
||||
|
||||
[gbuffer_to_attribute]
|
||||
|
||||
BaseColor=texture(gb_color,vs_out_position);
|
16
shader/drand48.frag
Normal file
16
shader/drand48.frag
Normal file
@@ -0,0 +1,16 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
/* returns a varying number between 0 and 1 */
|
||||
float drand48(vec2 co)
|
||||
{
|
||||
return 2 * fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453) - 1;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float gray=drand48(gl_FragCoord.xy);
|
||||
|
||||
FragColor=vec4(vec3(gray),1.0);
|
||||
}
|
44
shader/gbuffer_composition.frag
Normal file
44
shader/gbuffer_composition.frag
Normal file
@@ -0,0 +1,44 @@
|
||||
#version 450 core
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
layout(binding = 0) uniform sampler2D GB_Position;
|
||||
layout(binding = 1) uniform sampler2D GB_Normal;
|
||||
layout(binding = 2) uniform sampler2D GB_Color;
|
||||
|
||||
layout(location = 0) in vec2 FragmentPosition;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 pos =texture(GB_Position, FragmentPosition).xyz;
|
||||
vec3 normal =texture(GB_Normal, FragmentPosition).xyz;
|
||||
vec3 color =texture(GB_Color, FragmentPosition).xyz;
|
||||
|
||||
vec3 sun_light_direction=vec3(1,1,1);
|
||||
|
||||
float sun_light_intensity=max(dot(normal,sun_light_direction),0.0);
|
||||
|
||||
FragColor=vec4(color*sun_light_intensity,1.0);
|
||||
}
|
12
shader/gbuffer_composition.vert
Normal file
12
shader/gbuffer_composition.vert
Normal file
@@ -0,0 +1,12 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
|
||||
layout(location = 0) out vec2 FragmentPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Vertex,0.0,1.0);
|
||||
|
||||
FragmentPosition=(Vertex+1.0)/2.0;
|
||||
}
|
29
shader/gbuffer_debug.frag
Normal file
29
shader/gbuffer_debug.frag
Normal file
@@ -0,0 +1,29 @@
|
||||
#version 450 core
|
||||
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
mat4 ortho;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
vec4 view_pos;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
layout(binding = 0) uniform sampler2D GB_Position;
|
||||
layout(binding = 1) uniform sampler2D GB_Normal;
|
||||
layout(binding = 2) uniform sampler2D GB_Color;
|
||||
|
||||
layout(location = 0) flat in uint FragmentTexID;
|
||||
layout(location = 1) in vec2 FragmentTexCoord;
|
||||
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(GB_Normal,FragmentTexCoord);
|
||||
}
|
||||
|
13
shader/gbuffer_debug.vert
Normal file
13
shader/gbuffer_debug.vert
Normal file
@@ -0,0 +1,13 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
|
||||
layout(location = 0) out uint FragmentTexID;
|
||||
layout(location = 1) out vec2 FragmentTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Vertex,0.0,1.0);
|
||||
|
||||
FragmentTexCoord=(Vertex+1.0)/2.0;
|
||||
}
|
29
shader/gbuffer_opaque.frag
Normal file
29
shader/gbuffer_opaque.frag
Normal file
@@ -0,0 +1,29 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D TextureColor;
|
||||
layout (binding = 2) uniform sampler2D TextureNormal;
|
||||
|
||||
layout(location = 0) in vec3 FragmentNormal;
|
||||
layout(location = 1) in vec3 FragmentTangent;
|
||||
layout(location = 2) in vec3 FragmentPosition;
|
||||
layout(location = 3) in vec2 FragmentTexCoord;
|
||||
|
||||
layout (location = 0) out vec4 outPosition;
|
||||
layout (location = 1) out vec4 outNormal;
|
||||
layout (location = 2) out vec4 outColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
outPosition=vec4(normalize(FragmentPosition*2.0-vec3(1.0)),1.0);
|
||||
|
||||
vec3 N = normalize(FragmentNormal);
|
||||
vec3 T = normalize(FragmentTangent);
|
||||
vec3 B = cross(N,T);
|
||||
mat3 TBN = mat3(T,B,N);
|
||||
vec3 tnorm = (texture(TextureNormal,FragmentTexCoord).xyz*2.0-vec3(1.0))*TBN;
|
||||
|
||||
outNormal=vec4(normalize(tnorm),1.0);
|
||||
//outNormal=vec4(normalize(FragmentNormal),1.0);
|
||||
|
||||
outColor=texture(TextureColor,FragmentTexCoord);
|
||||
}
|
47
shader/gbuffer_opaque.vert
Normal file
47
shader/gbuffer_opaque.vert
Normal file
@@ -0,0 +1,47 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 Vertex;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 2) in vec3 Normal;
|
||||
layout(location = 3) in vec3 Tangent;
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
} world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
|
||||
layout(location = 0) out vec3 FragmentNormal;
|
||||
layout(location = 1) out vec3 FragmentTangent;
|
||||
layout(location = 2) out vec3 FragmentPosition;
|
||||
layout(location = 3) out vec2 FragmentTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pos=vec4(Vertex,1.0)*pc.local_to_world;
|
||||
|
||||
gl_Position=pos*world.mvp;
|
||||
|
||||
FragmentPosition=(pos*world.modelview).xyz;
|
||||
FragmentTexCoord=TexCoord;
|
||||
|
||||
mat3 n=mat3(pc.local_to_world*world.modelview);
|
||||
|
||||
FragmentNormal=normalize(Normal)*n;
|
||||
FragmentTangent=normalize(Tangent)*n;
|
||||
}
|
1
shader/header_desktop.glsl
Normal file
1
shader/header_desktop.glsl
Normal file
@@ -0,0 +1 @@
|
||||
#version 460 core
|
1
shader/header_mobile.glsl
Normal file
1
shader/header_mobile.glsl
Normal file
@@ -0,0 +1 @@
|
||||
#version 320 es
|
34
shader/hqfilter.frag
Normal file
34
shader/hqfilter.frag
Normal file
@@ -0,0 +1,34 @@
|
||||
#version 450 core
|
||||
|
||||
layout(binding = 2) uniform sampler2D tex;
|
||||
|
||||
layout(location = 0) in vec2 FragmentTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
vec4 hqfilter(sampler2D samp, vec2 tc)
|
||||
{
|
||||
// Get the size of the texture we'll be sampling from
|
||||
vec2 texSize = textureSize(samp, 0);
|
||||
|
||||
// Scale our input texture coordinates up, move to center of texel
|
||||
vec2 uvScaled = tc * texSize + 0.5;
|
||||
|
||||
// Find integer and fractional parts of texture coordinate
|
||||
vec2 uvInt = floor(uvScaled);
|
||||
vec2 uvFrac = fract(uvScaled);
|
||||
|
||||
// Replace fractional part of texture coordinate
|
||||
uvFrac = smoothstep(0.0, 1.0, uvFrac);
|
||||
|
||||
// Reassemble texture coordinate, remove bias, and
|
||||
// scale back to 0.0 - 1.0 ranage
|
||||
vec2 uv = (uvInt + uvFrac - 0.5) / texSize;
|
||||
|
||||
// Regular texture lookup
|
||||
return texture(samp, uv);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=hqfilter(tex,FragmentTexCoord);
|
||||
}
|
4
shader/push_constant_3d.glsl
Normal file
4
shader/push_constant_3d.glsl
Normal file
@@ -0,0 +1,4 @@
|
||||
layout(std430,push_constant,row_major) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
mat3 normal;
|
||||
} pc;
|
1
shader/sc.bat
Normal file
1
shader/sc.bat
Normal file
@@ -0,0 +1 @@
|
||||
glslangValidator -V -o %1.spv %1
|
33
shader/shader_compile.bat
Normal file
33
shader/shader_compile.bat
Normal file
@@ -0,0 +1,33 @@
|
||||
glslangValidator -V -o FlatColor.vert.spv FlatColor.vert
|
||||
glslangValidator -V -o FlatColor3D.vert.spv FlatColor3D.vert
|
||||
glslangValidator -V -o OnlyPosition.vert.spv OnlyPosition.vert
|
||||
glslangValidator -V -o FlatColor.frag.spv FlatColor.frag
|
||||
glslangValidator -V -o VertexColor.frag.spv VertexColor.frag
|
||||
|
||||
glslangValidator -V -o FlatTexture.vert.spv FlatTexture.vert
|
||||
glslangValidator -V -o FlatTexture.frag.spv FlatTexture.frag
|
||||
|
||||
glslangValidator -V -o PositionColor3D.vert.spv PositionColor3D.vert
|
||||
glslangValidator -V -o OnlyPosition3D.vert.spv OnlyPosition3D.vert
|
||||
|
||||
glslangValidator -V -o c_gbuffer.vert.spv c_gbuffer.vert
|
||||
glslangValidator -V -o c_gbuffer.frag.spv c_gbuffer.frag
|
||||
|
||||
glslangValidator -V -o Atomsphere.vert.spv Atomsphere.vert
|
||||
glslangValidator -V -o Atomsphere.frag.spv Atomsphere.frag
|
||||
|
||||
glslangValidator -V -o gbuffer_opaque.vert.spv gbuffer_opaque.vert
|
||||
glslangValidator -V -o gbuffer_opaque.frag.spv gbuffer_opaque.frag
|
||||
|
||||
glslangValidator -V -o gbuffer_composition.vert.spv gbuffer_composition.vert
|
||||
glslangValidator -V -o gbuffer_composition.frag.spv gbuffer_composition.frag
|
||||
|
||||
glslangValidator -V -o gbuffer_debug.vert.spv gbuffer_debug.vert
|
||||
glslangValidator -V -o gbuffer_debug.frag.spv gbuffer_debug.frag
|
||||
|
||||
glslangValidator -V -o drand48.frag.spv drand48.frag
|
||||
|
||||
glslangValidator -V -o Texture2D.vert.spv Texture2D.vert
|
||||
glslangValidator -V -o hqfilter.frag.spv hqfilter.frag
|
||||
|
||||
glslangValidator -V -o FragCoord.frag.spv FragCoord.frag
|
33
shader/shader_compile.sh
Normal file
33
shader/shader_compile.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
glslangValidator -V -o FlatColor.vert.spv FlatColor.vert
|
||||
glslangValidator -V -o FlatColor3D.vert.spv FlatColor3D.vert
|
||||
glslangValidator -V -o OnlyPosition.vert.spv OnlyPosition.vert
|
||||
glslangValidator -V -o FlatColor.frag.spv FlatColor.frag
|
||||
glslangValidator -V -o VertexColor.frag.spv VertexColor.frag
|
||||
|
||||
glslangValidator -V -o FlatTexture.vert.spv FlatTexture.vert
|
||||
glslangValidator -V -o FlatTexture.frag.spv FlatTexture.frag
|
||||
|
||||
glslangValidator -V -o PositionColor3D.vert.spv PositionColor3D.vert
|
||||
glslangValidator -V -o OnlyPosition3D.vert.spv OnlyPosition3D.vert
|
||||
|
||||
glslangValidator -V -o c_gbuffer.vert.spv c_gbuffer.vert
|
||||
glslangValidator -V -o c_gbuffer.frag.spv c_gbuffer.frag
|
||||
|
||||
glslangValidator -V -o Atomsphere.vert.spv Atomsphere.vert
|
||||
glslangValidator -V -o Atomsphere.frag.spv Atomsphere.frag
|
||||
|
||||
glslangValidator -V -o gbuffer_opaque.vert.spv gbuffer_opaque.vert
|
||||
glslangValidator -V -o gbuffer_opaque.frag.spv gbuffer_opaque.frag
|
||||
|
||||
glslangValidator -V -o gbuffer_composition.vert.spv gbuffer_composition.vert
|
||||
glslangValidator -V -o gbuffer_composition.frag.spv gbuffer_composition.frag
|
||||
|
||||
glslangValidator -V -o gbuffer_debug.vert.spv gbuffer_debug.vert
|
||||
glslangValidator -V -o gbuffer_debug.frag.spv gbuffer_debug.frag
|
||||
|
||||
glslangValidator -V -o drand48.frag.spv drand48.frag
|
||||
|
||||
glslangValidator -V -o Texture2D.vert.spv Texture2D.vert
|
||||
glslangValidator -V -o hqfilter.frag.spv hqfilter.frag
|
||||
|
||||
glslangValidator -V -o FragCoord.frag.spv FragCoord.frag
|
411
shader/shaderlib.glsl
Normal file
411
shader/shaderlib.glsl
Normal file
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Copyright 2011-2019 Branimir Karadzic. All rights reserved.
|
||||
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
vec4 encodeRE8(float _r)
|
||||
{
|
||||
float exponent = ceil(log2(_r) );
|
||||
return vec4(_r / exp2(exponent)
|
||||
, 0.0
|
||||
, 0.0
|
||||
, (exponent + 128.0) / 255.0
|
||||
);
|
||||
}
|
||||
|
||||
float decodeRE8(vec4 _re8)
|
||||
{
|
||||
float exponent = _re8.w * 255.0 - 128.0;
|
||||
return _re8.x * exp2(exponent);
|
||||
}
|
||||
|
||||
vec4 encodeRGBE8(vec3 _rgb)
|
||||
{
|
||||
vec4 rgbe8;
|
||||
float maxComponent = max(max(_rgb.x, _rgb.y), _rgb.z);
|
||||
float exponent = ceil(log2(maxComponent) );
|
||||
rgbe8.xyz = _rgb / exp2(exponent);
|
||||
rgbe8.w = (exponent + 128.0) / 255.0;
|
||||
return rgbe8;
|
||||
}
|
||||
|
||||
vec3 decodeRGBE8(vec4 _rgbe8)
|
||||
{
|
||||
float exponent = _rgbe8.w * 255.0 - 128.0;
|
||||
vec3 rgb = _rgbe8.xyz * exp2(exponent);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 encodeNormalUint(vec3 _normal)
|
||||
{
|
||||
return _normal * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
vec3 decodeNormalUint(vec3 _encodedNormal)
|
||||
{
|
||||
return _encodedNormal * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
vec2 encodeNormalSphereMap(vec3 _normal)
|
||||
{
|
||||
return normalize(_normal.xy) * sqrt(_normal.z * 0.5 + 0.5);
|
||||
}
|
||||
|
||||
vec3 decodeNormalSphereMap(vec2 _encodedNormal)
|
||||
{
|
||||
float zz = dot(_encodedNormal, _encodedNormal) * 2.0 - 1.0;
|
||||
return vec3(normalize(_encodedNormal.xy) * sqrt(1.0 - zz*zz), zz);
|
||||
}
|
||||
|
||||
vec2 octahedronWrap(vec2 _val)
|
||||
{
|
||||
// Reference(s):
|
||||
// - Octahedron normal vector encoding
|
||||
// https://web.archive.org/web/20191027010600/https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/comment-page-1/
|
||||
return (1.0 - abs(_val.yx) )
|
||||
* mix(vec2_splat(-1.0), vec2_splat(1.0), vec2(greaterThanEqual(_val.xy, vec2_splat(0.0) ) ) );
|
||||
}
|
||||
|
||||
vec2 encodeNormalOctahedron(vec3 _normal)
|
||||
{
|
||||
_normal /= abs(_normal.x) + abs(_normal.y) + abs(_normal.z);
|
||||
_normal.xy = _normal.z >= 0.0 ? _normal.xy : octahedronWrap(_normal.xy);
|
||||
_normal.xy = _normal.xy * 0.5 + 0.5;
|
||||
return _normal.xy;
|
||||
}
|
||||
|
||||
vec3 decodeNormalOctahedron(vec2 _encodedNormal)
|
||||
{
|
||||
_encodedNormal = _encodedNormal * 2.0 - 1.0;
|
||||
|
||||
vec3 normal;
|
||||
normal.z = 1.0 - abs(_encodedNormal.x) - abs(_encodedNormal.y);
|
||||
normal.xy = normal.z >= 0.0 ? _encodedNormal.xy : octahedronWrap(_encodedNormal.xy);
|
||||
return normalize(normal);
|
||||
}
|
||||
|
||||
vec3 convertRGB2XYZ(vec3 _rgb)
|
||||
{
|
||||
// Reference(s):
|
||||
// - RGB/XYZ Matrices
|
||||
// https://web.archive.org/web/20191027010220/http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
||||
vec3 xyz;
|
||||
xyz.x = dot(vec3(0.4124564, 0.3575761, 0.1804375), _rgb);
|
||||
xyz.y = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
||||
xyz.z = dot(vec3(0.0193339, 0.1191920, 0.9503041), _rgb);
|
||||
return xyz;
|
||||
}
|
||||
|
||||
vec3 convertXYZ2RGB(vec3 _xyz)
|
||||
{
|
||||
vec3 rgb;
|
||||
rgb.x = dot(vec3( 3.2404542, -1.5371385, -0.4985314), _xyz);
|
||||
rgb.y = dot(vec3(-0.9692660, 1.8760108, 0.0415560), _xyz);
|
||||
rgb.z = dot(vec3( 0.0556434, -0.2040259, 1.0572252), _xyz);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 convertXYZ2Yxy(vec3 _xyz)
|
||||
{
|
||||
// Reference(s):
|
||||
// - XYZ to xyY
|
||||
// https://web.archive.org/web/20191027010144/http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_xyY.html
|
||||
float inv = 1.0/dot(_xyz, vec3(1.0, 1.0, 1.0) );
|
||||
return vec3(_xyz.y, _xyz.x*inv, _xyz.y*inv);
|
||||
}
|
||||
|
||||
vec3 convertYxy2XYZ(vec3 _Yxy)
|
||||
{
|
||||
// Reference(s):
|
||||
// - xyY to XYZ
|
||||
// https://web.archive.org/web/20191027010036/http://www.brucelindbloom.com/index.html?Eqn_xyY_to_XYZ.html
|
||||
vec3 xyz;
|
||||
xyz.x = _Yxy.x*_Yxy.y/_Yxy.z;
|
||||
xyz.y = _Yxy.x;
|
||||
xyz.z = _Yxy.x*(1.0 - _Yxy.y - _Yxy.z)/_Yxy.z;
|
||||
return xyz;
|
||||
}
|
||||
|
||||
vec3 convertRGB2Yxy(vec3 _rgb)
|
||||
{
|
||||
return convertXYZ2Yxy(convertRGB2XYZ(_rgb) );
|
||||
}
|
||||
|
||||
vec3 convertYxy2RGB(vec3 _Yxy)
|
||||
{
|
||||
return convertXYZ2RGB(convertYxy2XYZ(_Yxy) );
|
||||
}
|
||||
|
||||
vec3 convertRGB2Yuv(vec3 _rgb)
|
||||
{
|
||||
vec3 yuv;
|
||||
yuv.x = dot(_rgb, vec3(0.299, 0.587, 0.114) );
|
||||
yuv.y = (_rgb.x - yuv.x)*0.713 + 0.5;
|
||||
yuv.z = (_rgb.z - yuv.x)*0.564 + 0.5;
|
||||
return yuv;
|
||||
}
|
||||
|
||||
vec3 convertYuv2RGB(vec3 _yuv)
|
||||
{
|
||||
vec3 rgb;
|
||||
rgb.x = _yuv.x + 1.403*(_yuv.y-0.5);
|
||||
rgb.y = _yuv.x - 0.344*(_yuv.y-0.5) - 0.714*(_yuv.z-0.5);
|
||||
rgb.z = _yuv.x + 1.773*(_yuv.z-0.5);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 convertRGB2YIQ(vec3 _rgb)
|
||||
{
|
||||
vec3 yiq;
|
||||
yiq.x = dot(vec3(0.299, 0.587, 0.114 ), _rgb);
|
||||
yiq.y = dot(vec3(0.595716, -0.274453, -0.321263), _rgb);
|
||||
yiq.z = dot(vec3(0.211456, -0.522591, 0.311135), _rgb);
|
||||
return yiq;
|
||||
}
|
||||
|
||||
vec3 convertYIQ2RGB(vec3 _yiq)
|
||||
{
|
||||
vec3 rgb;
|
||||
rgb.x = dot(vec3(1.0, 0.9563, 0.6210), _yiq);
|
||||
rgb.y = dot(vec3(1.0, -0.2721, -0.6474), _yiq);
|
||||
rgb.z = dot(vec3(1.0, -1.1070, 1.7046), _yiq);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 toLinear(vec3 _rgb)
|
||||
{
|
||||
return pow(abs(_rgb), vec3_splat(2.2) );
|
||||
}
|
||||
|
||||
vec4 toLinear(vec4 _rgba)
|
||||
{
|
||||
return vec4(toLinear(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toLinearAccurate(vec3 _rgb)
|
||||
{
|
||||
vec3 lo = _rgb / 12.92;
|
||||
vec3 hi = pow( (_rgb + 0.055) / 1.055, vec3_splat(2.4) );
|
||||
vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.04045) ) ) );
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 toLinearAccurate(vec4 _rgba)
|
||||
{
|
||||
return vec4(toLinearAccurate(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
float toGamma(float _r)
|
||||
{
|
||||
return pow(abs(_r), 1.0/2.2);
|
||||
}
|
||||
|
||||
vec3 toGamma(vec3 _rgb)
|
||||
{
|
||||
return pow(abs(_rgb), vec3_splat(1.0/2.2) );
|
||||
}
|
||||
|
||||
vec4 toGamma(vec4 _rgba)
|
||||
{
|
||||
return vec4(toGamma(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toGammaAccurate(vec3 _rgb)
|
||||
{
|
||||
vec3 lo = _rgb * 12.92;
|
||||
vec3 hi = pow(abs(_rgb), vec3_splat(1.0/2.4) ) * 1.055 - 0.055;
|
||||
vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.0031308) ) ) );
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 toGammaAccurate(vec4 _rgba)
|
||||
{
|
||||
return vec4(toGammaAccurate(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toReinhard(vec3 _rgb)
|
||||
{
|
||||
return toGamma(_rgb/(_rgb+vec3_splat(1.0) ) );
|
||||
}
|
||||
|
||||
vec4 toReinhard(vec4 _rgba)
|
||||
{
|
||||
return vec4(toReinhard(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toFilmic(vec3 _rgb)
|
||||
{
|
||||
_rgb = max(vec3_splat(0.0), _rgb - 0.004);
|
||||
_rgb = (_rgb*(6.2*_rgb + 0.5) ) / (_rgb*(6.2*_rgb + 1.7) + 0.06);
|
||||
return _rgb;
|
||||
}
|
||||
|
||||
vec4 toFilmic(vec4 _rgba)
|
||||
{
|
||||
return vec4(toFilmic(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toAcesFilmic(vec3 _rgb)
|
||||
{
|
||||
// Reference(s):
|
||||
// - ACES Filmic Tone Mapping Curve
|
||||
// https://web.archive.org/web/20191027010704/https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
|
||||
float aa = 2.51f;
|
||||
float bb = 0.03f;
|
||||
float cc = 2.43f;
|
||||
float dd = 0.59f;
|
||||
float ee = 0.14f;
|
||||
return saturate( (_rgb*(aa*_rgb + bb) )/(_rgb*(cc*_rgb + dd) + ee) );
|
||||
}
|
||||
|
||||
vec4 toAcesFilmic(vec4 _rgba)
|
||||
{
|
||||
return vec4(toAcesFilmic(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 luma(vec3 _rgb)
|
||||
{
|
||||
float yy = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
||||
return vec3_splat(yy);
|
||||
}
|
||||
|
||||
vec4 luma(vec4 _rgba)
|
||||
{
|
||||
return vec4(luma(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 conSatBri(vec3 _rgb, vec3 _csb)
|
||||
{
|
||||
vec3 rgb = _rgb * _csb.z;
|
||||
rgb = mix(luma(rgb), rgb, _csb.y);
|
||||
rgb = mix(vec3_splat(0.5), rgb, _csb.x);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 conSatBri(vec4 _rgba, vec3 _csb)
|
||||
{
|
||||
return vec4(conSatBri(_rgba.xyz, _csb), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 posterize(vec3 _rgb, float _numColors)
|
||||
{
|
||||
return floor(_rgb*_numColors) / _numColors;
|
||||
}
|
||||
|
||||
vec4 posterize(vec4 _rgba, float _numColors)
|
||||
{
|
||||
return vec4(posterize(_rgba.xyz, _numColors), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 sepia(vec3 _rgb)
|
||||
{
|
||||
vec3 color;
|
||||
color.x = dot(_rgb, vec3(0.393, 0.769, 0.189) );
|
||||
color.y = dot(_rgb, vec3(0.349, 0.686, 0.168) );
|
||||
color.z = dot(_rgb, vec3(0.272, 0.534, 0.131) );
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 sepia(vec4 _rgba)
|
||||
{
|
||||
return vec4(sepia(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 blendOverlay(vec3 _base, vec3 _blend)
|
||||
{
|
||||
vec3 lt = 2.0 * _base * _blend;
|
||||
vec3 gte = 1.0 - 2.0 * (1.0 - _base) * (1.0 - _blend);
|
||||
return mix(lt, gte, step(vec3_splat(0.5), _base) );
|
||||
}
|
||||
|
||||
vec4 blendOverlay(vec4 _base, vec4 _blend)
|
||||
{
|
||||
return vec4(blendOverlay(_base.xyz, _blend.xyz), _base.w);
|
||||
}
|
||||
|
||||
vec3 adjustHue(vec3 _rgb, float _hue)
|
||||
{
|
||||
vec3 yiq = convertRGB2YIQ(_rgb);
|
||||
float angle = _hue + atan2(yiq.z, yiq.y);
|
||||
float len = length(yiq.yz);
|
||||
return convertYIQ2RGB(vec3(yiq.x, len*cos(angle), len*sin(angle) ) );
|
||||
}
|
||||
|
||||
vec4 packFloatToRgba(float _value)
|
||||
{
|
||||
const vec4 shift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);
|
||||
const vec4 mask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
|
||||
vec4 comp = fract(_value * shift);
|
||||
comp -= comp.xxyz * mask;
|
||||
return comp;
|
||||
}
|
||||
|
||||
float unpackRgbaToFloat(vec4 _rgba)
|
||||
{
|
||||
const vec4 shift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
|
||||
return dot(_rgba, shift);
|
||||
}
|
||||
|
||||
vec2 packHalfFloat(float _value)
|
||||
{
|
||||
const vec2 shift = vec2(256, 1.0);
|
||||
const vec2 mask = vec2(0, 1.0 / 256.0);
|
||||
vec2 comp = fract(_value * shift);
|
||||
comp -= comp.xx * mask;
|
||||
return comp;
|
||||
}
|
||||
|
||||
float unpackHalfFloat(vec2 _rg)
|
||||
{
|
||||
const vec2 shift = vec2(1.0 / 256.0, 1.0);
|
||||
return dot(_rg, shift);
|
||||
}
|
||||
|
||||
float random(vec2 _uv)
|
||||
{
|
||||
return fract(sin(dot(_uv.xy, vec2(12.9898, 78.233) ) ) * 43758.5453);
|
||||
}
|
||||
|
||||
vec3 fixCubeLookup(vec3 _v, float _lod, float _topLevelCubeSize)
|
||||
{
|
||||
// Reference(s):
|
||||
// - Seamless cube-map filtering
|
||||
// https://web.archive.org/web/20190411181934/http://the-witness.net/news/2012/02/seamless-cube-map-filtering/
|
||||
float ax = abs(_v.x);
|
||||
float ay = abs(_v.y);
|
||||
float az = abs(_v.z);
|
||||
float vmax = max(max(ax, ay), az);
|
||||
float scale = 1.0 - exp2(_lod) / _topLevelCubeSize;
|
||||
if (ax != vmax) { _v.x *= scale; }
|
||||
if (ay != vmax) { _v.y *= scale; }
|
||||
if (az != vmax) { _v.z *= scale; }
|
||||
return _v;
|
||||
}
|
||||
|
||||
vec2 texture2DBc5(sampler2D _sampler, vec2 _uv)
|
||||
{
|
||||
#if BGFX_SHADER_LANGUAGE_HLSL && BGFX_SHADER_LANGUAGE_HLSL <= 3
|
||||
return texture2D(_sampler, _uv).yx;
|
||||
#else
|
||||
return texture2D(_sampler, _uv).xy;
|
||||
#endif
|
||||
}
|
||||
|
||||
mat3 cofactor(mat4 _m)
|
||||
{
|
||||
// Reference:
|
||||
// Cofactor of matrix. Use to transform normals. The code assumes the last column of _m is [0,0,0,1].
|
||||
// https://www.shadertoy.com/view/3s33zj
|
||||
// https://github.com/graphitemaster/normals_revisited
|
||||
return mat3(
|
||||
_m[1][1]*_m[2][2]-_m[1][2]*_m[2][1],
|
||||
_m[1][2]*_m[2][0]-_m[1][0]*_m[2][2],
|
||||
_m[1][0]*_m[2][1]-_m[1][1]*_m[2][0],
|
||||
_m[0][2]*_m[2][1]-_m[0][1]*_m[2][2],
|
||||
_m[0][0]*_m[2][2]-_m[0][2]*_m[2][0],
|
||||
_m[0][1]*_m[2][0]-_m[0][0]*_m[2][1],
|
||||
_m[0][1]*_m[1][2]-_m[0][2]*_m[1][1],
|
||||
_m[0][2]*_m[1][0]-_m[0][0]*_m[1][2],
|
||||
_m[0][0]*_m[1][1]-_m[0][1]*_m[1][0]
|
||||
);
|
||||
}
|
15
shader/test.geom
Normal file
15
shader/test.geom
Normal file
@@ -0,0 +1,15 @@
|
||||
#version 450 core
|
||||
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
mat4 two_dim;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
mat3 normal;
|
||||
} world;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(1.0)*world.mvp;
|
||||
}
|
25
shader/vertex_shader_output_layout.glsl
Normal file
25
shader/vertex_shader_output_layout.glsl
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifdef THIS_IS_VERTEX_SHADER
|
||||
#define VS_OUTPUT_LAYOUT out
|
||||
#else
|
||||
#define VS_OUTPUT_LAYOUT in
|
||||
#endif//THIS_IS_VERTEX_SHADER
|
||||
|
||||
#ifdef FS_USE_POSITION
|
||||
layout(location = 0) VS_OUTPUT_LAYOUT vec3 v2fPosition;
|
||||
#endif//FS_USE_POSITION
|
||||
|
||||
#ifdef FS_USE_COLOR
|
||||
layout(location = 1) VS_OUTPUT_LAYOUT vec3 v2fColor;
|
||||
#endif//FS_USE_COLOR
|
||||
|
||||
#ifdef FS_USE_NORMAL
|
||||
layout(location = 2) VS_OUTPUT_LAYOUT vec3 v2fNormal;
|
||||
#endif//FS_USE_NORMAL
|
||||
|
||||
#ifdef FS_USE_TANGENT
|
||||
layout(location = 3) VS_OUTPUT_LAYOUT vec3 v2fTangent;
|
||||
#endif//FS_USE_TANGENT
|
||||
|
||||
#ifdef FS_USE_TEX_COORD
|
||||
layout(location = 4) VS_OUTPUT_LAYOUT vec2 v2fTexCoord;
|
||||
#endif//FS_USE_TEX_COORD
|
Reference in New Issue
Block a user