Skip to content

Commit

Permalink
Edited Bloom. Added Glowing Mouse. Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
ReVHeaDRaZ committed Dec 17, 2022
1 parent fe2ab1f commit ea83dfb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 45 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Spiromorph - A port of [mickjc750/Spiromorph](https://github.com/mickjc750/Spiro
| <b>HOME and END-</b> | Change Amount of Envelopes In Phase|
| <b>INS and DEL-</b> | Change Amplitude|
| <b>H-</b> | HUD ON/OFF |
| <b>W and S-</b> | Bloom Shader Intensity |
| <b>A and D-</b> | Bloom Shader Sharpness |

# Executable for WIN32
Just download the release, unzip and run SFML-Spiromorph.exe
Expand Down
52 changes: 31 additions & 21 deletions content/razbloom.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,59 @@ void main(){
vec4 sum=vec4(0);
vec2 texcoord=gl_FragCoord.xy/iResolution.xy;
float blurSize= 1. / blurSizeAmount;
//vec2 texcoord=gl_TexCoord[0].xy;

sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y))*.20;

sum+=texture2D(currentTexture,vec2(texcoord.x+blurSize,texcoord.y))*.13;
sum+=texture2D(currentTexture,vec2(texcoord.x-blurSize,texcoord.y))*.13;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y+blurSize))*.13;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y-blurSize))*.13;
sum+=texture2D(currentTexture,vec2(texcoord.x+blurSize,texcoord.y))*.12;
sum+=texture2D(currentTexture,vec2(texcoord.x-blurSize,texcoord.y))*.12;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y+blurSize))*.12;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y-blurSize))*.12;

sum+=texture2D(currentTexture,vec2(texcoord.x+blurSize,texcoord.y+blurSize))*.11;
sum+=texture2D(currentTexture,vec2(texcoord.x+blurSize,texcoord.y-blurSize))*.11;
sum+=texture2D(currentTexture,vec2(texcoord.x-blurSize,texcoord.y+blurSize))*.11;
sum+=texture2D(currentTexture,vec2(texcoord.x-blurSize,texcoord.y-blurSize))*.11;
sum+=texture2D(currentTexture,vec2(texcoord.x+blurSize,texcoord.y+blurSize))*.12;
sum+=texture2D(currentTexture,vec2(texcoord.x+blurSize,texcoord.y-blurSize))*.12;
sum+=texture2D(currentTexture,vec2(texcoord.x-blurSize,texcoord.y+blurSize))*.12;
sum+=texture2D(currentTexture,vec2(texcoord.x-blurSize,texcoord.y-blurSize))*.12;

sum+=texture2D(currentTexture,vec2(texcoord.x+2.*blurSize,texcoord.y))*.09;
sum+=texture2D(currentTexture,vec2(texcoord.x-2.*blurSize,texcoord.y))*.09;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y+2.*blurSize))*.09;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y-2.*blurSize))*.09;

sum+=texture2D(currentTexture,vec2(texcoord.x+2.*blurSize,texcoord.y+2*blurSize))*.08;
sum+=texture2D(currentTexture,vec2(texcoord.x+2.*blurSize,texcoord.y-2*blurSize))*.08;
sum+=texture2D(currentTexture,vec2(texcoord.x-2*blurSize,texcoord.y+2.*blurSize))*.08;
sum+=texture2D(currentTexture,vec2(texcoord.x-2*blurSize,texcoord.y-2.*blurSize))*.08;
sum+=texture2D(currentTexture,vec2(texcoord.x+2.*blurSize,texcoord.y+2*blurSize))*.09;
sum+=texture2D(currentTexture,vec2(texcoord.x+2.*blurSize,texcoord.y-2*blurSize))*.09;
sum+=texture2D(currentTexture,vec2(texcoord.x-2*blurSize,texcoord.y+2.*blurSize))*.09;
sum+=texture2D(currentTexture,vec2(texcoord.x-2*blurSize,texcoord.y-2.*blurSize))*.09;

sum+=texture2D(currentTexture,vec2(texcoord.x+3.*blurSize,texcoord.y))*.07;
sum+=texture2D(currentTexture,vec2(texcoord.x-3.*blurSize,texcoord.y))*.07;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y+3.*blurSize))*.07;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y-3.*blurSize))*.07;

sum+=texture2D(currentTexture,vec2(texcoord.x+3.*blurSize,texcoord.y+3*blurSize))*.06;
sum+=texture2D(currentTexture,vec2(texcoord.x+3.*blurSize,texcoord.y-3*blurSize))*.06;
sum+=texture2D(currentTexture,vec2(texcoord.x-3*blurSize,texcoord.y+3.*blurSize))*.06;
sum+=texture2D(currentTexture,vec2(texcoord.x-3*blurSize,texcoord.y-3.*blurSize))*.06;
sum+=texture2D(currentTexture,vec2(texcoord.x+3.*blurSize,texcoord.y+3*blurSize))*.07;
sum+=texture2D(currentTexture,vec2(texcoord.x+3.*blurSize,texcoord.y-3*blurSize))*.07;
sum+=texture2D(currentTexture,vec2(texcoord.x-3*blurSize,texcoord.y+3.*blurSize))*.07;
sum+=texture2D(currentTexture,vec2(texcoord.x-3*blurSize,texcoord.y-3.*blurSize))*.07;

sum+=texture2D(currentTexture,vec2(texcoord.x+4.*blurSize,texcoord.y))*.05;
sum+=texture2D(currentTexture,vec2(texcoord.x-4.*blurSize,texcoord.y))*.05;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y+4.*blurSize))*.05;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y-4.*blurSize))*.05;

sum+=texture2D(currentTexture,vec2(texcoord.x+4.*blurSize,texcoord.y+4*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x+4.*blurSize,texcoord.y-4*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x-4*blurSize,texcoord.y+4.*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x-4*blurSize,texcoord.y-4.*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x+4.*blurSize,texcoord.y+4*blurSize))*.05;
sum+=texture2D(currentTexture,vec2(texcoord.x+4.*blurSize,texcoord.y-4*blurSize))*.05;
sum+=texture2D(currentTexture,vec2(texcoord.x-4*blurSize,texcoord.y+4.*blurSize))*.05;
sum+=texture2D(currentTexture,vec2(texcoord.x-4*blurSize,texcoord.y-4.*blurSize))*.05;

sum+=texture2D(currentTexture,vec2(texcoord.x+5.*blurSize,texcoord.y))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x-5.*blurSize,texcoord.y))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y+5.*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x,texcoord.y-5.*blurSize))*.04;

sum+=texture2D(currentTexture,vec2(texcoord.x+5.*blurSize,texcoord.y+5*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x+5.*blurSize,texcoord.y-5*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x-5*blurSize,texcoord.y+5.*blurSize))*.04;
sum+=texture2D(currentTexture,vec2(texcoord.x-5*blurSize,texcoord.y-5.*blurSize))*.04;


//increase blur with intensity!
gl_FragColor=sum*intensity+texture2D(currentTexture,texcoord);
Expand Down
18 changes: 9 additions & 9 deletions content/razdot.frag
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ void main(void)
vec2 uv=gl_FragCoord.xy/iResolution.xy;// x: <0, 1>, y: <0, 1>
uv.x=uv.x-iMouse.x/iResolution.x;
uv.y=uv.y+iMouse.y/iResolution.y;
uv.y-=16.6;// To adjust y position
uv.y-=16;// To adjust y position

uv.x*=iResolution.x/iResolution.y;// x: * aspect ratio, y: >

float d=length(uv)-.1;// signed distance function
vec3 col=vec3(step(0.,-d),0,0);// create red circle with black background

vec3 col=vec3(0,0,step(0.,-d));// create blue circle with black background

float glow=.01/d;// create glow and diminish it with distance
glow=clamp(glow,0.,1.);// remove artifacts
col+=vec3(glow*35.,0,0);// add glow

col+=vec3(0,0,glow*8.);// add glow

gl_FragColor=vec4(col,1.);// output color
}
21 changes: 14 additions & 7 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int main(int argc, char *argv[])

sf::RenderWindow window(sf::VideoMode(winW, winH), "Spiromorph", windowStyle);
window.setFramerateLimit(60);
window.setMouseCursorVisible(false);

// Initialize Shaders
if(!InitShaders(winW,winH)) return -1;
Expand Down Expand Up @@ -184,26 +185,26 @@ int main(int argc, char *argv[])
selectedSpiro = numberOfSpiros;
SetTextForCurrentSpiro();
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num8){
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::W){
bloomIntensity += 0.5f;
if(bloomIntensity > 10.0f) bloomIntensity = 10.0f;
SetBloomShader(bloomIntensity, bloomBlurAmount);
SetBloomText(bloomIntensity, bloomBlurAmount);
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num7){
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::S){
bloomIntensity -= 0.5f;
if(bloomIntensity < 0.0f) bloomIntensity = 0.0f;
SetBloomShader(bloomIntensity, bloomBlurAmount);
SetBloomText(bloomIntensity, bloomBlurAmount);
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num0){
bloomBlurAmount += 5.0f;
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::D){
bloomBlurAmount += 8.0f;
if(bloomBlurAmount > 1000.0f) bloomBlurAmount = 1000.0f;
SetBloomShader(bloomIntensity, bloomBlurAmount);
SetBloomText(bloomIntensity, bloomBlurAmount);
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num9){
bloomBlurAmount -= 5.0f;
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::A){
bloomBlurAmount -= 8.0f;
if(bloomBlurAmount < 0.0f) bloomBlurAmount = 0.0f;
SetBloomShader(bloomIntensity, bloomBlurAmount);
SetBloomText(bloomIntensity, bloomBlurAmount);
Expand All @@ -214,7 +215,7 @@ int main(int argc, char *argv[])
UpdateSpiromorphs(spiromorphs, numberOfSpiros, frame_time);

// Set shader parameters
UpdateShaderParameters(&clk, window.getSize().x/2, (window.getSize().y/2)+350);
UpdateShaderParameters(&clk, sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);

window.clear();

Expand All @@ -236,6 +237,12 @@ int main(int argc, char *argv[])
window.draw(render, &bloomshader);
}

// Draw Glowing Mouse pointer
rendertexture.clear(sf::Color::Transparent);
rendertexture.display();
render.setTexture(rendertexture.getTexture());
window.draw(render, renderstate);

// Draw Hud
if(drawHud){
DrawHud(window);
Expand Down
4 changes: 2 additions & 2 deletions src/Razshaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ bool InitShaders(float WIN_WIDTH, float WIN_HEIGHT){

// Set Shader resolutions
fireshader.setUniform("resolution", sf::Vector2f(45, 45));
glowshader.setUniform("resolution", sf::Vector2f(45, 45));
glowshader.setUniform("resolution", sf::Vector2f(WIN_WIDTH/16, WIN_HEIGHT/16));
bloomshader.setUniform("resolution", sf::Vector2f(WIN_WIDTH, WIN_HEIGHT));

// Set Blend renderstate for glow
// Set Blend renderstate for glowing mouse
renderstate.blendMode = sf::BlendAdd;
renderstate.shader = &glowshader;

Expand Down
12 changes: 6 additions & 6 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"InPhase- Home/End\n"\
"Amplitude- Ins/Del\n"\
"Hide Hud- H\n"\
"Glow Intensity- 7/8\n"\
"Glow Sharpness- 9/0\n"
"Glow Intensity- W/S\n"\
"Glow Sharpness- A/D\n"

sf::Font font;
sf::Text headingText, currentSpiroText, speedText, inphaseText, ampText, fpsText, controlsText, bloomText;
Expand Down Expand Up @@ -83,13 +83,13 @@ void InitTextObjects(sf::RenderWindow* window)
}

void SetCurrentSpiroText(float _current){
currentSpiroText.setString("SPIRO: " + to_string(_current));
currentSpiroText.setString("SPIRO: " + to_string(_current));
}
void SetSpeedText(float _speed){
speedText.setString("SPEED: " + to_string(_speed));
speedText.setString("SPEED: " + to_string(_speed));
}
void SetInphaseText(int _inphase, int _numElements){
inphaseText.setString("IN PHASE: " + to_string(_inphase) + " of " + to_string(_numElements));
inphaseText.setString("IN PHASE: " + to_string(_inphase) + " of " + to_string(_numElements));
}
void SetAmpText(float _amp){
ampText.setString("AMPLITUDE: " + to_string(_amp));
Expand All @@ -98,5 +98,5 @@ void SetFpsText(float _fps){
fpsText.setString("FPS: " + to_string(_fps));
}
void SetBloomText(float _bloomintesity, float _bloomBlurAmount){
bloomText.setString("*SHADERS*\nIntensity: " + to_string(_bloomintesity) + "\nSharpness: " + to_string(_bloomBlurAmount));
bloomText.setString("*BLOOM SHADER*\n Intensity: " + to_string(_bloomintesity) + "\n Sharpness: " + to_string(_bloomBlurAmount));
}

0 comments on commit ea83dfb

Please sign in to comment.