generated from sigonasr2/CPlusPlusProjectTemplate
Native mosaic PGE fragment shader implementation. Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
a38ef4e71d
commit
dca53a3df0
File diff suppressed because one or more lines are too long
Binary file not shown.
13
main.cpp
13
main.cpp
@ -37,12 +37,17 @@ public:
|
||||
}else{
|
||||
lastIncrease=std::max(0.f,lastIncrease-fElapsedTime);
|
||||
}
|
||||
Clear(WHITE);
|
||||
Clear(BLACK);
|
||||
srand(48190);
|
||||
for(int i=0;i<100;i++){
|
||||
DrawCircle({rand()%640,rand()%480},rand()%30,{uint8_t(rand()%255),uint8_t(rand()%255),uint8_t(rand()%255)});
|
||||
for(int i=0;i<500;i++){
|
||||
if(rand()%2){
|
||||
DrawCircle({rand()%640,rand()%480},rand()%30,{uint8_t(rand()%255),uint8_t(rand()%255),uint8_t(rand()%255)});
|
||||
}else{
|
||||
FillCircle({rand()%640,rand()%480},rand()%30,{uint8_t(rand()%255),uint8_t(rand()%255),uint8_t(rand()%255)});
|
||||
}
|
||||
}
|
||||
DrawStringDecal({0,0},"Mosaic Effect: "+std::to_string(GetMosaicEffect()),BLACK);
|
||||
DrawStringDecal({1,1},"Mosaic Effect: "+std::to_string(GetMosaicEffect()),BLACK);
|
||||
DrawStringDecal({0,0},"Mosaic Effect: "+std::to_string(GetMosaicEffect()),WHITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1248,7 +1248,7 @@ namespace olc
|
||||
std::vector<std::string> vDroppedFilesCache;
|
||||
olc::vi2d vDroppedFilesPoint;
|
||||
olc::vi2d vDroppedFilesPointCache;
|
||||
uint8_t mosaic=0;
|
||||
uint8_t mosaic=1;
|
||||
|
||||
// Command Console Specific
|
||||
bool bConsoleShow = false;
|
||||
@ -3596,7 +3596,7 @@ namespace olc
|
||||
return mosaic;
|
||||
}
|
||||
void PixelGameEngine::SetMosaicEffect(uint8_t effectLevel){
|
||||
mosaic=effectLevel;
|
||||
mosaic=std::max(uint8_t(1),effectLevel);
|
||||
}
|
||||
|
||||
|
||||
@ -4865,8 +4865,17 @@ namespace olc
|
||||
#else
|
||||
"#version 330 core\n"
|
||||
#endif
|
||||
"out vec4 pixel;\n""in vec2 oTex;\n"
|
||||
"in vec4 oCol;\n""uniform sampler2D sprTex;\n""void main(){pixel = texture(sprTex, oTex) * oCol;}";
|
||||
"out vec4 pixel;\n"
|
||||
"in vec2 oTex;\n"
|
||||
"in vec4 oCol;\n"
|
||||
"uniform int mosaic;\n"
|
||||
"uniform vec2 size;\n"
|
||||
"uniform sampler2D sprTex;\n"
|
||||
"void main(){\n"
|
||||
"vec2 texelSize = 1.0 / size; \n"
|
||||
"vec2 pos = oTex / texelSize; \n""vec2 outputPos = vec2(floor(pos.x/float(mosaic))*float(mosaic),floor(pos.y/float(mosaic))*float(mosaic));\n"
|
||||
"pixel = texture(sprTex, outputPos*texelSize) * oCol;\n"
|
||||
"}";
|
||||
locShaderSource(m_nFS, 1, &strFS, NULL);
|
||||
locCompileShader(m_nFS);
|
||||
|
||||
@ -4883,13 +4892,12 @@ namespace olc
|
||||
"layout(location = 2) in vec4 aCol;\n"
|
||||
"out vec2 oTex;\n"
|
||||
"out vec4 oCol;\n"
|
||||
"uniform int mosaic;\n"
|
||||
"\n"
|
||||
"void main(){\n"
|
||||
"float p = 1.0 / aPos.z;\n"
|
||||
"gl_Position = p * vec4(aPos.x, aPos.y, 0.0, 1.0);\n"
|
||||
"oTex = p * aTex;\n"
|
||||
"oCol = vec4(aCol.r,float(mosaic)/255.0,0,aCol.a);\n"
|
||||
"oCol = aCol;\n"
|
||||
"}";
|
||||
locShaderSource(m_nVS, 1, &strVS, NULL);
|
||||
locCompileShader(m_nVS);
|
||||
@ -4974,7 +4982,9 @@ namespace olc
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
locUseProgram(m_nQuadShader);
|
||||
GLint myUniformLocation = glGetUniformLocation(m_nQuadShader, "mosaic");
|
||||
GLint myUniformLocation2 = glGetUniformLocation(m_nQuadShader, "size");
|
||||
glUniform1i(myUniformLocation,ptrPGE->GetMosaicEffect());
|
||||
glUniform2f(myUniformLocation2,ptrPGE->ScreenWidth(),ptrPGE->ScreenHeight());
|
||||
locBindVertexArray(m_vaQuad);
|
||||
|
||||
#if defined(OLC_PLATFORM_EMSCRIPTEN)
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user