noise shader
This commit is contained in:
parent
7a738c0534
commit
d363d89620
@ -40,7 +40,7 @@
|
||||
<None Include="shaders\shader_pbr.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
<None Include="shaders\shader_skybox.vert" />
|
||||
<None Include="shaders\shader_smap.frag" />
|
||||
<None Include="shaders\shader_noise.frag" />
|
||||
<None Include="shaders\shader_smap.vert" />
|
||||
<None Include="shaders\shader_tex.frag" />
|
||||
<None Include="shaders\shader_tex.vert" />
|
||||
|
@ -109,7 +109,7 @@
|
||||
<None Include="shaders\shader_smap.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_smap.frag">
|
||||
<None Include="shaders\shader_noise.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_skybox.frag">
|
||||
|
@ -1,80 +0,0 @@
|
||||
#version 430 core
|
||||
|
||||
float PI = 3.14159f;
|
||||
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
uniform float exposition;
|
||||
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
in vec2 vtc;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
in vec3 viewDirTS;
|
||||
in vec3 lightDirTS;
|
||||
in vec3 sunDirTS;
|
||||
|
||||
uniform float u_time;
|
||||
float pi = 3.14159;
|
||||
// 2D Random
|
||||
float random (in vec2 st) {
|
||||
return fract(sin(dot(st.xy,
|
||||
vec2(12.9898,78.233)))
|
||||
* 43758.5453123);
|
||||
}
|
||||
|
||||
// 2D Noise based on Morgan McGuire @morgan3d
|
||||
// https://www.shadertoy.com/view/4dS3Wd
|
||||
float noise (in vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
// Four corners in 2D of a tile
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 randA = vec2(a *2.0 *pi);
|
||||
vec2 randB = vec2(b *2.0 *pi);
|
||||
vec2 randC = vec2(c *2.0 *pi);
|
||||
vec2 randD = vec2(d *2.0 *pi);
|
||||
|
||||
vec2 offsetA = a-st;
|
||||
vec2 offsetB = b-st;
|
||||
vec2 offsetC = c-st;
|
||||
vec2 offsetD = d-st;
|
||||
|
||||
offsetA = offsetA*randA;
|
||||
offsetB = offsetB*randB;
|
||||
offsetC = offsetC*randC;
|
||||
offsetD = offsetD*randD;
|
||||
|
||||
float resA = smoothstep(offsetA.x,offsetA.y, f.y);
|
||||
float resB = smoothstep(offsetB.x,offsetB.y, f.y);
|
||||
float resC = smoothstep(offsetC.x,offsetC.y, f.y);
|
||||
float resD = smoothstep(offsetD.x,offsetD.y, f.y);
|
||||
|
||||
vec2 u = smoothstep(0.,1.,f);
|
||||
|
||||
|
||||
float ab= mix(a, b, u.x);
|
||||
float cd = mix(c, d, u.x);
|
||||
return mix(ab,cd,u.y);
|
||||
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
vec2 st = vtc;
|
||||
vec2 pos = vec2(st*3.776);
|
||||
|
||||
// Use the noise function
|
||||
float n = 1.836 * 0.676*noise(pos*2.576);
|
||||
n = smoothstep(-0.096, 1.176, n);
|
||||
|
||||
outColor = vec4(vec3(n), 1);
|
||||
}
|
@ -325,12 +325,12 @@ void init(GLFWwindow* window) {
|
||||
//initDepthMap();
|
||||
initHDR();
|
||||
|
||||
programDepth = shaderLoader.CreateProgram("shaders/shader_smap.vert", "shaders/shader_smap.frag");
|
||||
//programDepth = shaderLoader.CreateProgram("shaders/shader_smap.vert", "shaders/shader_smap.frag");
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||
programPbr = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_pbr.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
|
||||
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||
programNoise = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_smap.frag");
|
||||
programNoise = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_noise.frag");
|
||||
|
||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||
loadModelToContext("./models/cube.obj", cubeContext);
|
||||
|
Loading…
Reference in New Issue
Block a user