Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ find_package(box2d CONFIG REQUIRED)

find_package(nlohmann_json CONFIG REQUIRED)

find_package(TGUI CONFIG REQUIRED)

find_package(OpenSSL REQUIRED)

find_package(TGUI CONFIG REQUIRED)


#Настройка конфигурации
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TMXLITE_LIB ${TMXLITE_LIB} "libtmxlite-s-d")
Expand All @@ -58,10 +60,12 @@ file(GLOB_RECURSE SOURCES "src/*.cpp" "include/*.h")
# Добавьте источник в исполняемый файл этого проекта.
add_executable (Roberto ${SOURCES})
add_executable (tester "tester/main.cpp" "include/SFMLOrthogonalLayer.hpp")
add_executable (ShaderTester "ShaderTest/main.cpp")
add_executable (sfmlTest "sfmlTest/main.cpp")
add_executable (rostikTest "rostikTest/main.cpp")

target_link_libraries(tester PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES} thor ${TMXLITE_LIB})
target_link_libraries(ShaderTester PRIVATE sfml-system sfml-network sfml-graphics sfml-window)
target_link_libraries(sfmlTest PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES})
target_link_libraries(Roberto PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES} thor ${TMXLITE_LIB})
target_link_libraries(rostikTest PRIVATE sfml-system sfml-network sfml-graphics sfml-window box2d::box2d nlohmann_json::nlohmann_json tgui ${OPENSSL_LIBRARIES} thor ${TMXLITE_LIB})
Expand Down
36 changes: 18 additions & 18 deletions Resources/maps/testMap.tmx

Large diffs are not rendered by default.

281 changes: 281 additions & 0 deletions Resources/shaders/ExplosionSharer.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
// "Volumetric explosion" by Duke
// https://www.shadertoy.com/view/lsySzd
//-------------------------------------------------------------------------------------
// Based on "Supernova remnant" (https://www.shadertoy.com/view/MdKXzc)
// and other previous shaders
// otaviogood's "Alien Beacon" (https://www.shadertoy.com/view/ld2SzK)
// and Shane's "Cheap Cloud Flythrough" (https://www.shadertoy.com/view/Xsc3R4) shaders
// Some ideas came from other shaders from this wonderful site
// Press 1-2-3 to zoom in and zoom out.
// License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
//-------------------------------------------------------------------------------------

// comment this string to see each part in full screen
#define BOTH
// uncomment this string to see left part
//#define LEFT

//#define LOW_QUALITY

#define DITHERING

//#define TONEMAPPING

//-------------------
#define pi 3.14159265
#define R(p, a) p=cos(a)*p+sin(a)*vec2(p.y, -p.x)

// iq's noise
float noise( in vec3 x )
{
vec3 p = floor(x);
vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy;
vec2 rg = textureLod( iChannel0, (uv+ 0.5)/256.0, 0.0 ).yx;
return 1. - 0.82*mix( rg.x, rg.y, f.z );
}

float fbm( vec3 p )
{
return noise(p*.06125)*.5 + noise(p*.125)*.25 + noise(p*.25)*.125 + noise(p*.4)*.2;
}

float Sphere( vec3 p, float r )
{
return length(p)-r;
}

//==============================================================
// otaviogood's noise from https://www.shadertoy.com/view/ld2SzK
//--------------------------------------------------------------
// This spiral noise works by successively adding and rotating sin waves while increasing frequency.
// It should work the same on all computers since it's not based on a hash function like some other noises.
// It can be much faster than other noise functions if you're ok with some repetition.
const float nudge = 4.; // size of perpendicular vector
float normalizer = 1.0 / sqrt(1.0 + nudge*nudge); // pythagorean theorem on that perpendicular to maintain scale
float SpiralNoiseC(vec3 p)
{
float n = -mod(iTime * 0.2,-2.); // noise amount
float iter = 2.0;
for (int i = 0; i < 8; i++)
{
// add sin and cos scaled inverse with the frequency
n += -abs(sin(p.y*iter) + cos(p.x*iter)) / iter; // abs for a ridged look
// rotate by adding perpendicular and scaling down
p.xy += vec2(p.y, -p.x) * nudge;
p.xy *= normalizer;
// rotate on other axis
p.xz += vec2(p.z, -p.x) * nudge;
p.xz *= normalizer;
// increase the frequency
iter *= 1.733733;
}
return n;
}

float VolumetricExplosion(vec3 p)
{
float final = Sphere(p,4.);
#ifdef LOW_QUALITY
final += noise(p*12.5)*.2;
#else
final += fbm(p*50.);
#endif
final += SpiralNoiseC(p.zxy*0.4132+333.)*3.0; //1.25;

return final;
}

float map(vec3 p)
{
R(p.xz, iMouse.x*0.008*pi+iTime*0.1);

float VolExplosion = VolumetricExplosion(p/0.5)*0.5; // scale

return VolExplosion;
}
//--------------------------------------------------------------

// assign color to the media
vec3 computeColor( float density, float radius )
{
// color based on density alone, gives impression of occlusion within
// the media
vec3 result = mix( vec3(1.0,0.9,0.8), vec3(0.4,0.15,0.1), density );

// color added to the media
vec3 colCenter = 7.*vec3(0.8,1.0,1.0);
vec3 colEdge = 1.5*vec3(0.48,0.53,0.5);
result *= mix( colCenter, colEdge, min( (radius+.05)/.9, 1.15 ) );

return result;
}

bool RaySphereIntersect(vec3 org, vec3 dir, out float near, out float far)
{
float b = dot(dir, org);
float c = dot(org, org) - 8.;
float delta = b*b - c;
if( delta < 0.0)
return false;
float deltasqrt = sqrt(delta);
near = -b - deltasqrt;
far = -b + deltasqrt;
return far > 0.0;
}

// Applies the filmic curve from John Hable's presentation
// More details at : http://filmicgames.com/archives/75
vec3 ToneMapFilmicALU(vec3 _color)
{
_color = max(vec3(0), _color - vec3(0.004));
_color = (_color * (6.2*_color + vec3(0.5))) / (_color * (6.2 * _color + vec3(1.7)) + vec3(0.06));
return _color;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
const float KEY_1 = 49.5/256.0;
const float KEY_2 = 50.5/256.0;
const float KEY_3 = 51.5/256.0;
float key = 0.0;
key += 0.7*texture(iChannel1, vec2(KEY_1,0.25)).x;
key += 0.7*texture(iChannel1, vec2(KEY_2,0.25)).x;
key += 0.7*texture(iChannel1, vec2(KEY_3,0.25)).x;

vec2 uv = fragCoord/iResolution.xy;

// ro: ray origin
// rd: direction of the ray
vec3 rd = normalize(vec3((fragCoord.xy-0.5*iResolution.xy)/iResolution.y, 1.));
vec3 ro = vec3(0., 0., -6.+key*1.6);

// ld, td: local, total density
// w: weighting factor
float ld=0., td=0., w=0.;

// t: length of the ray
// d: distance function
float d=1., t=0.;

const float h = 0.1;

vec4 sum = vec4(0.0);

float min_dist=0.0, max_dist=0.0;

if(RaySphereIntersect(ro, rd, min_dist, max_dist))
{

t = min_dist*step(t,min_dist);

// raymarch loop
#ifdef LOW_QUALITY
for (int i=0; i<56; i++)
#else
for (int i=0; i<86; i++)
#endif
{

vec3 pos = ro + t*rd;

// Loop break conditions.
if(td>0.9 || d<0.12*t || t>10. || sum.a > 0.99 || t>max_dist) break;

// evaluate distance function
float d = map(pos);

#ifdef BOTH
/*
if (uv.x<0.5)
{
d = abs(d)+0.07;
}
*/
//split screen variant
//d = uv.x < 0.5 ? abs(d)+0.07 : d;

d = cos(iTime)*uv.x < 0.1 ? abs(d)+0.07 : d;
#else
#ifdef LEFT
d = abs(d)+0.07;
#endif
#endif

// change this string to control density
d = max(d,0.03);

// point light calculations
vec3 ldst = vec3(0.0)-pos;
float lDist = max(length(ldst), 0.001);

// the color of light
vec3 lightColor=vec3(1.0,0.5,0.25);

sum.rgb+=(lightColor/exp(lDist*lDist*lDist*.08)/30.); // bloom

if (d<h)
{
// compute local density
ld = h - d;

// compute weighting factor
w = (1. - td) * ld;

// accumulate density
td += w + 1./200.;

vec4 col = vec4( computeColor(td,lDist), td );

// emission
sum += sum.a * vec4(sum.rgb, 0.0) * 0.2 / lDist;

// uniform scale density
col.a *= 0.2;
// colour by alpha
col.rgb *= col.a;
// alpha blend in contribution
sum = sum + col*(1.0 - sum.a);

}

td += 1./70.;

#ifdef DITHERING
// idea from https://www.shadertoy.com/view/lsj3Dw
vec2 uvd = uv;
uvd.y*=120.;
uvd.x*=280.;
d=abs(d)*(.8+0.08*texture(iChannel2,vec2(uvd.y,-uvd.x+0.5*sin(4.*iTime+uvd.y*4.0))).r);
#endif

// trying to optimize step size
#ifdef LOW_QUALITY
t += max(d*0.25,0.01);
#else
t += max(d * 0.08 * max(min(length(ldst),d),2.0), 0.01);
#endif


}

// simple scattering
#ifdef LOW_QUALITY
sum *= 1. / exp( ld * 0.2 ) * 0.9;
#else
sum *= 1. / exp( ld * 0.2 ) * 0.8;
#endif

sum = clamp( sum, 0.0, 1.0 );

sum.xyz = sum.xyz*sum.xyz*(3.0-2.0*sum.xyz);

}

#ifdef TONEMAPPING
fragColor = vec4(ToneMapFilmicALU(sum.xyz*2.2),1.0);
#else
fragColor = vec4(sum.xyz,1.0);
#endif
}
26 changes: 26 additions & 0 deletions Resources/shaders/Shader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 resolution;
uniform vec2 mousedPosition;
uniform float time;

const int complexity = 50;
const float fluid_speed = 22.0;
const float color_intensity = 1.0;
void main()
{
vec2 p=(3.0*gl_FragCoord.xy-resolution)/max(resolution.x, resolution.y);

for (int i=1;i<complexity;i++)
{
vec2 newp=p + time*0.00001;
newp.x+=0.2/float(i)*sin(float(i)*p.y+time/fluid_speed+0.0*float(i+ 0)+ mousedPosition.x) + 0.6;
newp.y+=0.8/float(i)*sin(float(i)*p.x+time/fluid_speed+0.0*float(i+ 0)+ mousedPosition.y) - 0.4;
p=newp;
}
vec3 col=vec3(color_intensity*sin(4.0*p.x)+color_intensity, color_intensity*sin(2.0*p.y)+color_intensity, color_intensity*sin(p.x+p.y)+color_intensity);
gl_FragColor=vec4(col, 0.7);
}
35 changes: 35 additions & 0 deletions Resources/shaders/SmokeShader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 resolution;
uniform float time;

void main() {
vec2 uv = gl_FragCoord.xy / resolution.xy;
float aspectRatio = resolution.x / resolution.y;

// Базовая анимация, можно настраивать
float smoke = sin(uv.x * 10.0 + time * 2.0) * 0.1;
smoke += sin(uv.x * 5.0 + time * 3.0) * 0.05;

// Добавим немного случайных волн для текстуры дыма
vec2 distortion = vec2(
sin(uv.y * 10.0 + time * 1.5),
cos(uv.y * 15.0 + time * 2.0)
) * 0.005;

uv += distortion;

// Прозрачность зависит от координаты по y
float transparency = 1.0 - uv.y * 0.5;

// Цвет дыма
vec3 color = vec3(0.7, 0.7, 0.7);

// Смешиваем цвет с анимацией и прозрачностью
color += smoke;
color *= transparency;

gl_FragColor = vec4(color, 1.0);
}
Loading