mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-05 03:33:27 +01:00
adding David Hoskins's hasing functions to shader builtins
https://www.shadertoy.com/view/4djSRW (hash without sine)
This commit is contained in:
parent
15ab73909f
commit
631b9433c2
@ -90,6 +90,7 @@ void Shader::setUniformMat3f(const std::string& name, const glm::mat3& matrix) {
|
||||
}
|
||||
|
||||
// TODO: refactor this whole thing out
|
||||
// FIXME: hangs if trailing whitespace
|
||||
std::string Shader::parse(Engine& engine, const std::string& filePath) {
|
||||
auto& fs = engine.getService<MM::Services::FilesystemService>();
|
||||
|
||||
|
@ -84,6 +84,158 @@ vec3 tonemapReinhard(vec3 x) {
|
||||
#endif
|
||||
)")
|
||||
// ==================== tonemapping.glsl ==================== END
|
||||
|
||||
// ==================== hashing.glsl ==================== START
|
||||
FS_CONST_MOUNT_FILE("/shaders/builtin/hashing.glsl",
|
||||
R"(
|
||||
#ifndef INCLUDE_BUILTIN_HASHING
|
||||
#define INCLUDE_BUILTIN_HASHING
|
||||
|
||||
// https://www.shadertoy.com/view/4djSRW
|
||||
// Hash without Sine
|
||||
// MIT License...
|
||||
/* Copyright (c)2014 David Hoskins.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 1 out, 1 in...
|
||||
float hash11(float p)
|
||||
{
|
||||
p = fract(p * .1031);
|
||||
p *= p + 33.33;
|
||||
p *= p + p;
|
||||
return fract(p);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 1 out, 2 in...
|
||||
float hash12(vec2 p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p.xyx) * .1031);
|
||||
p3 += dot(p3, p3.yzx + 33.33);
|
||||
return fract((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 1 out, 3 in...
|
||||
float hash13(vec3 p3)
|
||||
{
|
||||
p3 = fract(p3 * .1031);
|
||||
p3 += dot(p3, p3.zyx + 31.32);
|
||||
return fract((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 2 out, 1 in...
|
||||
vec2 hash21(float p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
|
||||
p3 += dot(p3, p3.yzx + 33.33);
|
||||
return fract((p3.xx+p3.yz)*p3.zy);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 2 out, 2 in...
|
||||
vec2 hash22(vec2 p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
|
||||
p3 += dot(p3, p3.yzx+33.33);
|
||||
return fract((p3.xx+p3.yz)*p3.zy);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 2 out, 3 in...
|
||||
vec2 hash23(vec3 p3)
|
||||
{
|
||||
p3 = fract(p3 * vec3(.1031, .1030, .0973));
|
||||
p3 += dot(p3, p3.yzx+33.33);
|
||||
return fract((p3.xx+p3.yz)*p3.zy);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 3 out, 1 in...
|
||||
vec3 hash31(float p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
|
||||
p3 += dot(p3, p3.yzx+33.33);
|
||||
return fract((p3.xxy+p3.yzz)*p3.zyx);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 3 out, 2 in...
|
||||
vec3 hash32(vec2 p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
|
||||
p3 += dot(p3, p3.yxz+33.33);
|
||||
return fract((p3.xxy+p3.yzz)*p3.zyx);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 3 out, 3 in...
|
||||
vec3 hash33(vec3 p3)
|
||||
{
|
||||
p3 = fract(p3 * vec3(.1031, .1030, .0973));
|
||||
p3 += dot(p3, p3.yxz+33.33);
|
||||
return fract((p3.xxy + p3.yxx)*p3.zyx);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 4 out, 1 in...
|
||||
vec4 hash41(float p)
|
||||
{
|
||||
vec4 p4 = fract(vec4(p) * vec4(.1031, .1030, .0973, .1099));
|
||||
p4 += dot(p4, p4.wzxy+33.33);
|
||||
return fract((p4.xxyz+p4.yzzw)*p4.zywx);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 4 out, 2 in...
|
||||
vec4 hash42(vec2 p)
|
||||
{
|
||||
vec4 p4 = fract(vec4(p.xyxy) * vec4(.1031, .1030, .0973, .1099));
|
||||
p4 += dot(p4, p4.wzxy+33.33);
|
||||
return fract((p4.xxyz+p4.yzzw)*p4.zywx);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 4 out, 3 in...
|
||||
vec4 hash43(vec3 p)
|
||||
{
|
||||
vec4 p4 = fract(vec4(p.xyzx) * vec4(.1031, .1030, .0973, .1099));
|
||||
p4 += dot(p4, p4.wzxy+33.33);
|
||||
return fract((p4.xxyz+p4.yzzw)*p4.zywx);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// 4 out, 4 in...
|
||||
vec4 hash44(vec4 p4)
|
||||
{
|
||||
p4 = fract(p4 * vec4(.1031, .1030, .0973, .1099));
|
||||
p4 += dot(p4, p4.wzxy+33.33);
|
||||
return fract((p4.xxyz+p4.yzzw)*p4.zywx);
|
||||
}
|
||||
|
||||
#endif
|
||||
)")
|
||||
// ==================== hashing.glsl ==================== END
|
||||
}
|
||||
|
||||
} // MM::OpenGL
|
||||
|
@ -6,6 +6,7 @@ namespace MM::OpenGL {
|
||||
// file list:
|
||||
// - sampling.glsl
|
||||
// - tonemapping.glsl
|
||||
// - hashing.glsl
|
||||
void load_builtin_shaders_fs(void);
|
||||
|
||||
} // MM::OpenGL
|
||||
|
@ -37,6 +37,7 @@ R"(
|
||||
|
||||
#include "/shaders/builtin/sampling.glsl"
|
||||
#include "/shaders/builtin/tonemapping.glsl"
|
||||
#include "/shaders/builtin/hashing.glsl"
|
||||
|
||||
void main() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user