Skip to content

Commit

Permalink
I think I actually added a shader in like under 15 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Speak2Erase committed Dec 23, 2021
1 parent 67fc115 commit 5add0a5
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ set(EMBEDDED_INPUT
shader/cubic_lens.frag
shader/water.frag
shader/zoom.vert
shader/binary_glitch.frag
assets/icon.png
assets/gamecontrollerdb.txt
)
Expand Down
23 changes: 12 additions & 11 deletions Dockerfile-windows
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019

# install vs community (not vs buildtools because we need devenv to upgrade vs solutions
ADD https://aka.ms/vs/16/release/vs_community.exe /vs_community.exe
RUN C:\vs_community.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended
RUN C:\vs_community.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --add Microsoft.VisualStudio.Workload.C++

# install chocolatey and use it to install cmake, git, conan, vim (vim for xxd only, since installing cygwin breaks docker)
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
RUN iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco install -y cmake git conan vim
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); `
choco install -y cmake git conan vim;

# configure path (add xxd and cmake), conan remotes, and fix windows path size limits for conan
RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\Program Files\CMake\bin;C:\tools\vim\vim82', 'Machine')
RUN conan remote add eliza https://rkevin.jfrog.io/artifactory/api/conan/eliza
RUN conan remote add bincrafters https://bincrafters.jfrog.io/artifactory/api/conan/public-conan
RUN conan remote add astrabit https://rkevin.jfrog.io/artifactory/api/conan/astrabit
RUN conan config set general.revisions_enabled=1
RUN setx CONAN_USE_ALWAYS_SHORT_PATHS 1
RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\Program Files\CMake\bin;C:\tools\vim\vim82', 'Machine'); `
conan remote add eliza https://rkevin.jfrog.io/artifactory/api/conan/eliza; `
conan remote add bincrafters https://bincrafters.jfrog.io/artifactory/api/conan/public-conan; `
conan remote add astrabit https://rkevin.jfrog.io/artifactory/api/conan/astrabit; `
conan config set general.revisions_enabled=1; `
conan profile new default --detect; `
setx CONAN_USE_ALWAYS_SHORT_PATHS 1;

# prebuild all dependencies using the conanfile in this commit
COPY conanfile.py C:/Temp/install_deps/
RUN conan install --build=missing C:\Temp\install_deps
RUN conan install --build=missing C:\Temp\install_deps -s compiler.cppstd=20 -s compiler.runtime=static

# finally, we build oneshot when we run the container
ENTRYPOINT ["C:\\work\\src\\build-entrypoint-windows.bat"]
13 changes: 13 additions & 0 deletions binding-mri/viewport-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ RB_METHOD(setCubicTime)
return Qnil;
}

RB_METHOD(setBinaryStrength)
{
int strength;
rb_get_args(argc, argv, "i", &strength);

Viewport *v = getPrivateData<Viewport>(self);

v->setBinaryStrength(strength);

return Qnil;
}

RB_METHOD(setWaterTime)
{
double time;
Expand Down Expand Up @@ -148,6 +160,7 @@ viewportBindingInit()
_rb_define_method(klass, "setRGBOffset", setRGBOffset);
_rb_define_method(klass, "setZoom", setZoom);
_rb_define_method(klass, "setCubicTime", setCubicTime);
_rb_define_method(klass, "setBinaryStrength", setBinaryStrength);
_rb_define_method(klass, "setWaterTime", setWaterTime);

INIT_PROP_BIND( Viewport, Rect, "rect" );
Expand Down
53 changes: 53 additions & 0 deletions shader/binary_glitch.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

// Binary Glitch - based on Luminosity.
// use the Mouse to effect the strength.


// by D34N 4L3X
// [email protected]

uniform sampler2D texture;
uniform int strength
varying vec2 v_texCoord;

void main()
{
vec2 uv = v_texCoord;
// uv.t = 1.0 - uv.t;

float x = uv.s;
float y = uv.t;

//
float glitchStrength = 10. - float(strength);

// get snapped position
float psize = 0.04 * glitchStrength;
float psq = 1.0 / psize;

float px = floor( x * psq + 0.5) * psize;
float py = floor( y * psq + 0.5) * psize;

vec4 colSnap = texture2D( texture, vec2( px,py) );

float lum = pow( 1.0 - (colSnap.r + colSnap.g + colSnap.b) / 3.0, glitchStrength ); // remove the minus one if you want to invert luma



// do move with lum as multiplying factor
float qsize = psize * lum;

float qsq = 1.0 / qsize;

float qx = floor( x * qsq + 0.5) * qsize;
float qy = floor( y * qsq + 0.5) * qsize;

float rx = (px - qx) * lum + x;
float ry = (py - qy) * lum + y;

vec4 colMove = texture2D( texture, vec2( rx,ry) );


// final color
gl_FragColor = colMove;
}
3 changes: 2 additions & 1 deletion src/graphics/headers/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class Scene
const Vec4 /* rbg */,
const Vec2 /* zoom */,
const float /* cubic */,
const float /* water */) {}
const float /* water */,
const int /* binary */) {}

const Geometry &getGeometry() const { return geometry; }

Expand Down
34 changes: 33 additions & 1 deletion src/graphics/source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class ScreenScene : public Scene
}
}

void requestViewportRender(const Vec4 &c, const Vec4 &f, const Vec4 &t, const bool s, const Vec4 rx, const Vec4 ry, const Vec2 z, const float cubic, const float water)
void requestViewportRender(const Vec4 &c, const Vec4 &f, const Vec4 &t, const bool s, const Vec4 rx, const Vec4 ry, const Vec2 z, const float cubic, const float water, const int binary)
{
const IntRect &viewpRect = glState.scissorBox.get();
const IntRect &screenRect = geometry.rect;
Expand All @@ -192,6 +192,7 @@ class ScreenScene : public Scene
const bool rgbOffset = rx.xyzNotNull() || ry.xyzNotNull() && !toneGrayEffect && !s && !(z.x != 1 || z.y != 1) && !cubicEffect;
const bool scannedEffect = s && !t.w != 0 && !rgbOffset && !(z.x != 1 || z.y != 1) && !cubicEffect;
const bool zoomEffect = (z.x != 1 || z.y != 1) && !scannedEffect && !rgbOffset && !cubicEffect;
const bool binaryEffect = binary != 0;

if (toneGrayEffect)
{
Expand All @@ -215,6 +216,37 @@ class ScreenScene : public Scene
GrayShader &shader = shState->shaders().gray;
shader.bind();
shader.setGray(t.w);
/* shader.applyViewportProj(); */
shader.setTexSize(viewpRect.size());

TEX::bind(pp.backBuffer().tex);

glState.blend.pushSet(false);
screenQuad.draw();
glState.blend.pop();
}

if (binaryEffect)
{
pp.swapRender();

if (!viewpRect.encloses(screenRect))
{
/* Scissor test _does_ affect FBO blit operations,
* and since we're inside the draw cycle, it will
* be turned on, so turn it off temporarily */
glState.scissorTest.pushSet(false);

GLMeta::blitBegin(pp.frontBuffer());
GLMeta::blitSource(pp.backBuffer());
GLMeta::blitRectangle(geometry.rect, Vec2i());
GLMeta::blitEnd();

glState.scissorTest.pop();
}

BinaryShader &shader = shState->shaders().binary;
shader.bind();
shader.applyViewportProj();
shader.setTexSize(viewpRect.size());

Expand Down
11 changes: 11 additions & 0 deletions src/opengl/headers/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ class WaterShader : public ShaderBase
GLint u_iTime, u_opacity;
};

class BinaryShader : public ShaderBase
{
public:
BinaryShader();

void setStrength(const int value);
private:
GLint u_strength;
};


/* Global object containing all available shaders */
struct ShaderSet
Expand Down Expand Up @@ -423,6 +433,7 @@ struct ShaderSet
ZoomShader zoom;
CubicShader cubic;
WaterShader water;
BinaryShader binary;
};

#endif // SHADER_H
1 change: 1 addition & 0 deletions src/opengl/headers/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Viewport : public Scene, public SceneElement, public Flashable, public Dis
DECL_ATTR( RGBOffsetx, Vec4 )
DECL_ATTR( RGBOffsety, Vec4 )
DECL_ATTR( CubicTime, float )
DECL_ATTR( BinaryStrength, int )
DECL_ATTR( WaterTime, float )
DECL_ATTR( Zoom, Vec2 )

Expand Down
15 changes: 15 additions & 0 deletions src/opengl/source/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "crt_sprite.frag.xxd"
#include "cubic_lens.frag.xxd"
#include "water.frag.xxd"
#include "binary_glitch.frag.xxd"
#include "chronos.frag.xxd"
#include "zoom.vert.xxd"

Expand Down Expand Up @@ -757,4 +758,18 @@ void WaterShader::setiTime(const float value)
void WaterShader::setOpacity(const float value)
{
gl.Uniform1f(u_opacity, value);
}

BinaryShader::BinaryShader()
{
INIT_SHADER(simple, binary, BinaryShader);

ShaderBase::init();

GET_U(strength);
}

void BinaryShader::setStrength(const int value)
{
gl.Uniform1i(u_strength, value);
}
8 changes: 6 additions & 2 deletions src/opengl/source/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct ViewportPrivate

float waterTime;

int binaryStrength;

Vec2 zoom;

EtcTemps tmp;
Expand All @@ -70,6 +72,7 @@ struct ViewportPrivate
rgbOffsety(Vec4(0, 0, 0, 0)),
cubicTime(0.0),
waterTime(0.0),
binaryStrength(0),
zoom(Vec2(1.0, 1.0))
{
rect->set(x, y, width, height);
Expand Down Expand Up @@ -110,7 +113,7 @@ struct ViewportPrivate
bool needsEffectRender(bool flashing)
{
bool rectEffective = !rect->isEmpty();
bool colorToneEffective = color->hasEffect() || tone->hasEffect() || flashing || scanned || rgbOffsetx.xyzNotNull() || rgbOffsety.xyzNotNull() || zoom.x != 1 || zoom.y != 1 || cubicTime != 0.0 || waterTime != 0.0;
bool colorToneEffective = color->hasEffect() || tone->hasEffect() || flashing || scanned || rgbOffsetx.xyzNotNull() || rgbOffsety.xyzNotNull() || zoom.x != 1 || zoom.y != 1 || cubicTime != 0.0 || waterTime != 0.0 || binaryStrength != 0;

return (rectEffective && colorToneEffective && isOnScreen);
}
Expand Down Expand Up @@ -169,6 +172,7 @@ DEF_ATTR_SIMPLE(Viewport, Color, Color&, *p->color)
DEF_ATTR_SIMPLE(Viewport, Tone, Tone&, *p->tone)
DEF_ATTR_SIMPLE(Viewport, Scanned, bool, p->scanned)
DEF_ATTR_SIMPLE(Viewport, CubicTime, float, p->cubicTime)
DEF_ATTR_SIMPLE(Viewport, BinaryStrength, int, p->binaryStrength)
DEF_ATTR_SIMPLE(Viewport, WaterTime, float, p->waterTime)
DEF_ATTR_SIMPLE(Viewport, RGBOffsetx, Vec4, p->rgbOffsetx)
DEF_ATTR_SIMPLE(Viewport, RGBOffsety, Vec4, p->rgbOffsety)
Expand Down Expand Up @@ -226,7 +230,7 @@ void Viewport::composite()
* render them. */
if (renderEffect)
scene->requestViewportRender
(p->color->norm, flashColor, p->tone->norm, p->scanned, p->rgbOffsetx, p->rgbOffsety, p->zoom, p->cubicTime, p->waterTime);
(p->color->norm, flashColor, p->tone->norm, p->scanned, p->rgbOffsetx, p->rgbOffsety, p->zoom, p->cubicTime, p->waterTime, p->binaryStrength);

glState.scissorBox.pop();
glState.scissorTest.pop();
Expand Down

0 comments on commit 5add0a5

Please sign in to comment.