Skip to content

Commit

Permalink
[ADD] : add 3 shaders
Browse files Browse the repository at this point in the history
[RFR] :! a bit for refactor of main and glApi
[ADD] ! add 2 textures. noise and longlat
  • Loading branch information
aiekick committed Jul 14, 2024
1 parent 5d8484e commit a96a128
Show file tree
Hide file tree
Showing 25 changed files with 10,587 additions and 216 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "InAppGpuProfiler"]
path = InAppGpuProfiler
url = https://github.com/aiekick/InAppGpuProfiler.git
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ include_directories(
${CMAKE_SOURCE_DIR}
)

add_subdirectory(${CMAKE_SOURCE_DIR}/InAppGpuProfiler)
add_subdirectory(${CMAKE_SOURCE_DIR}/iagp)

add_executable(${PROJECT}
${MAIN_SOURCES}
Expand All @@ -78,7 +78,7 @@ else()
endif()

set_target_properties(${PROJECT} PROPERTIES CXX_STANDARD 11)
set_target_properties(InAppGpuProfiler PROPERTIES CXX_STANDARD 11)
set_target_properties(iagp PROPERTIES CXX_STANDARD 11)

set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}")
install(TARGETS ${PROJECT} DESTINATION ${CMAKE_INSTALL_PREFIX})
Expand All @@ -88,12 +88,12 @@ target_link_libraries(${PROJECT} PRIVATE
${GLFW_LIBRARIES}
${GLAD_LIBRARIES}
${IMGUI_LIBRARIES}
InAppGpuProfiler
iagp
)

set_target_properties(InAppGpuProfiler PROPERTIES FOLDER Lib)
set_target_properties(iagp PROPERTIES FOLDER Lib)

target_include_directories(InAppGpuProfiler PRIVATE
target_include_directories(iagp PRIVATE
${CMAKE_SOURCE_DIR}
)

Expand Down
1 change: 0 additions & 1 deletion InAppGpuProfiler
Submodule InAppGpuProfiler deleted from 467442
3 changes: 3 additions & 0 deletions bin/assets/longlats/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Texture in LongLat Format

found free on texturify.com
Binary file added bin/assets/longlats/texturify_pano_1_13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/assets/longlats/texturify_pano_1_8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/assets/noises/blue_noise_256_rgba.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/assets/noises/blue_noise_64_rgba.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
176 changes: 176 additions & 0 deletions bin/assets/shaders/shader31.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#version 330
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) out vec4 fragColor;
layout(location = 0) in vec2 vUV;

uniform float iTime;
uniform vec3 iResolution;

// https://www.shadertoy.com/view/XtBXRm
// Created by Stephane Cuillerdier - Aiekick/2017 (twitter:@aiekick)

#define shape(p) length(p)-2.8

const vec2 RMPrec = vec2(.2, 0.001);
const vec3 DPrec = vec3(0.005, 12., 1e-6);

// by shane
float Voronesque( in vec3 p )
{
vec3 i = floor(p + dot(p, vec3(0.333333)) ); p -= i - dot(i, vec3(0.166666)) ;
vec3 i1 = step(0., p-p.yzx), i2 = max(i1, 1.0-i1.zxy); i1 = min(i1, 1.0-i1.zxy);
vec3 p1 = p - i1 + 0.166666, p2 = p - i2 + 0.333333, p3 = p - 0.5;
vec3 rnd = vec3(7, 157, 113); // I use this combination to pay homage to Shadertoy.com. :)
vec4 v = max(0.5 - vec4(dot(p, p), dot(p1, p1), dot(p2, p2), dot(p3, p3)), 0.);
vec4 d = vec4( dot(i, rnd), dot(i + i1, rnd), dot(i + i2, rnd), dot(i + 1., rnd) );
d = fract(sin(d)*262144.)*v*2.;
v.x = max(d.x, d.y), v.y = max(d.z, d.w), v.z = max(min(d.x, d.y), min(d.z, d.w)), v.w = min(v.x, v.y);
return max(v.x, v.y) - max(v.z, v.w); // Maximum minus second order, for that beveled Voronoi look. Range [0, 1].
}

vec2 map(vec3 p)
{
vec2 res = vec2(0.);

float voro = Voronesque(p);

vec3 col = vec3(voro)*.5;

float sphere = shape(p);
float sphereOut = sphere - voro;
float sphereIn = sphere + voro * .5;

float dist = max(-sphereIn, sphereOut + .29);

res = vec2(dist, 1.);

float kernel = sphere + 2.2;

if (kernel < res.x )
res = vec2(kernel, 2.);

return res;
}

vec3 nor( vec3 pos, float prec )
{
vec2 e = vec2( prec, 0. );
vec3 n = vec3(
map(pos+e.xyy).x - map(pos-e.xyy).x,
map(pos+e.yxy).x - map(pos-e.yxy).x,
map(pos+e.yyx).x - map(pos-e.yyx).x );
return normalize(n);
}

vec3 cam(vec2 uv, vec3 ro, vec3 cu, vec3 cv)
{
vec3 rov = normalize(cv-ro);
vec3 u = normalize(cross(cu, rov));
vec3 v = normalize(cross(rov, u));
vec3 rd = normalize(rov + u*uv.x + v*uv.y);
return rd;
}

vec3 blackbody(float Temp)
{
vec3 col = vec3(255.);
col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.;
col.y = 100.04 * log(Temp) - 623.6;
if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.;
col.z = 194.18 * log(Temp) - 1448.6;
col = clamp(col, 0., 255.)/255.;
if (Temp < 1000.) col *= Temp/1000.;
return col;
}

// light
const vec3 LPos = vec3(-0.6, 0.7, -0.5);
const vec3 LAmb = vec3( 0. );
const vec3 LDif = vec3( 1. , 0.5, 0. );
const vec3 LSpe = vec3( 0.8 );

// material
const vec3 MAmb = vec3( 0. );
const vec3 MDif = vec3( 1. , 0.5, 0. );
const vec3 MSpe = vec3( 0.6, 0.6, 0.6 );
const float MShi =30.;

vec3 ads( vec3 p, vec3 n )
{
vec3 ldif = normalize( LPos - p);
vec3 vv = normalize( vec3(0.) - p );
vec3 refl = reflect( vec3(0.) - ldif, n );

vec3 amb = MAmb*LAmb+ blackbody(2000.);
vec3 dif = max(0., dot(ldif, n.xyz)) * MDif * LDif;
vec3 spe = vec3( 0. );
if( dot(ldif, vv) > 0.)
spe = pow(max(0., dot(vv,refl)),MShi)*MSpe*LSpe;

return amb*1.2 + dif*1.5 + spe*0.8;
}

vec3 nrand3( vec2 co )
{
vec3 a = fract( cos( co.x*8.3e-3 + co.y )*vec3(1.3e5, 4.7e5, 2.9e5) );
vec3 b = fract( sin( co.x*0.3e-3 + co.y )*vec3(8.1e5, 1.0e5, 0.1e5) );
vec3 c = mix(a, b, 0.5);
return c;
}

void main()
{
fragColor = vec4(0,0,0,1);
vec2 g = gl_FragCoord.xy;
vec2 si = iResolution.xy;
float t = iTime;

float ca = t*.14; // angle z
float ce = 1.; // elevation
float cd = 1.; // distance to origin axis

vec3 cu=vec3(0,1,0);//Change camere up vector here
vec3 cv=vec3(0,0,0); //Change camere view here
vec2 uv = (g+g-si)/min(si.x, si.y);
vec3 ro = vec3(sin(ca)*cd, ce+1., cos(ca)*cd); //
vec3 rd = cam(uv, ro, cu, cv);

vec3 d = vec3(0.);
vec3 p = ro+rd*d.x;
vec2 s = vec2(DPrec.y);

for(int i=0;i<200;i++)
{
if(s.x<DPrec.x||s.x>DPrec.y) break;
s = map(p);
s.x *= (s.x>DPrec.x?RMPrec.x:RMPrec.y);
d.x += s.x;
p = ro+rd*d.x;
}

if (d.x<DPrec.y)
{
float nPrec = 0.1;
vec3 n = nor(p, nPrec);

if ( s.y < 1.5) // rock
{
vec3 SSS = ads(n,n) - ads(p, rd);
SSS += blackbody(1500. * (d.x - 3.));
fragColor.rgb = SSS;
}
else if( s.y < 2.5) // kernel
{
float b = dot(n,normalize(ro-p))*0.9;
fragColor = (b*vec4(blackbody(2000.),0.8)+pow(b,0.2))*(1.0-d.x*.01);
}
}
else
{
vec3 rnd = nrand3( floor(uv * 2.0 * iResolution.x) );
fragColor = vec4(pow(rnd.y,10.0));
}
fragColor.a = 1.0;
}

122 changes: 122 additions & 0 deletions bin/assets/shaders/shader32.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#version 330
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) out vec4 fragColor;
layout(location = 0) in vec2 vUV;

uniform float iTime;
uniform int iFrame;
uniform vec3 iResolution;
uniform vec4 iMouse;
uniform sampler2D iChannel0;

// https://www.shadertoy.com/view/XlSSzV
// Created by Stephane Cuillerdier - Aiekick/2015
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// Tuned via XShade (http://www.funparadigm.com/xshade/)

/*
variation more cloudy off Another Cloudy Tunnel :
https://www.shadertoy.com/view/4lSXRK
the cloudy famous tech come from the shader of duke : https://www.shadertoy.com/view/MljXDw
Himself a Port of a demo by Las => http://www.pouet.net/topic.php?which=7920&page=29&x=14&y=9
*/

float t;

float cosPath(vec3 p, vec3 dec){return dec.x * cos(p.z * dec.y + dec.z);}
float sinPath(vec3 p, vec3 dec){return dec.x * sin(p.z * dec.y + dec.z);}

vec2 getCylinder(vec3 p, vec2 pos, float r, vec3 c, vec3 s)
{
return p.xy - pos - vec2(cosPath(p, c), sinPath(p, s));
}

/////////////////////////
// FROM Shader Cloudy spikeball from duke : https://www.shadertoy.com/view/MljXDw
float pn( in vec3 x )
{
vec3 p = floor(x);
vec3 fragColor = fract(x);
fragColor = fragColor*fragColor*(3.0-2.0*fragColor);
vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + fragColor.xy;
vec2 rg = texture(iChannel0, (uv+ 0.5)/256.0, -100.0 ).yx;
return -1.0+2.4*mix( rg.x, rg.y, fragColor.z );
}

float fpn(vec3 p)
{
p += t*5.;
return pn(p*0.02)*1.98 + pn(p*0.02)*0.62 + pn(p*0.09)*0.39;
}
/////////////////////////

float map(vec3 p)
{
float pnNoise = fpn(p*13.)*.8;
float path = sinPath(p ,vec3(6.2, .33, 0.));
float bottom = p.y + pnNoise;
float cyl = 0.;vec2 vecOld;
for (float i=0.;i<6.;i++)
{
float x = 1. * i;
float y = .88 + 0.0102*i;
float z = -0.02 -0.16*i;
float r = 4.4 + 2.45 * i;
vec2 vec = getCylinder(p, vec2(path, 3.7 * i), r , vec3(x,y,z), vec3(z,x,y));
cyl = r - min(length(vec), length(vecOld));
vecOld = vec;
}
cyl += pnNoise;
cyl = min(cyl, bottom);
return cyl;
}

vec3 cam(vec2 uv, vec3 ro, vec3 cu, vec3 cv)
{
vec3 rov = normalize(cv-ro);
vec3 u = normalize(cross(cu, rov));
vec3 v = normalize(cross(rov, u));
float fov = 3.;
vec3 rd = normalize(rov + fov*u*uv.x + fov*v*uv.y);
return rd;
}

void main()
{
t = iTime*2.5;
fragColor = vec4(0,0.15,0.32,1);
vec2 si = iResolution.xy;
vec2 g = gl_FragCoord.xy;
vec2 uv = (2.*g-si)/min(si.x, si.y);
vec3 ro = vec3(0), p=ro;
ro.y = sin(t*.2)*15.+15.;
ro.x = sin(t*.5)*5.;
ro.z = t*5.;
vec3 rd = cam(uv, p, vec3(0,1,0), p + vec3(0,0,1));
float s = 1., h = .15, td = 0., d=1.,dd=0., w;
float var = 0.03;
if (iMouse.z>0.) var = 0.1*iMouse.y/iResolution.y;
for(float i=0.;i<200.;i++)
{
if(s<0.01||d>500.||td>.95) break;
s = map(p) * (s>0.001?var:.2);
if (s < h)
{
w = (1.-td) * (h-s)*i/200.;
fragColor += w;
td += w;
}
dd += 0.012;
td += 0.005;
s = max(s, 0.05);
d+=s;
p = ro+rd*d;
}
fragColor.rgb = mix( fragColor.rgb, vec3(0,0.15,0.52), 1.0 - exp( -0.001*d*d) )/dd; // fog

// vigneting from iq Shader Mike : https://www.shadertoy.com/view/MsXGWr
vec2 q = g/si;
fragColor.rgb *= 0.5 + 0.5*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.25 );
}
Loading

0 comments on commit a96a128

Please sign in to comment.