Skip to content

Commit

Permalink
# - copyright acknowledged augusto ruiz
Browse files Browse the repository at this point in the history
  • Loading branch information
en-software committed Dec 2, 2023
1 parent b3fb0e4 commit 1095f4a
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 67 deletions.
6 changes: 4 additions & 2 deletions blooDot.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalLibraryDirectories Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">
</AdditionalLibraryDirectories>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">version.lib;dinput8.lib;dxguid.lib;user32.lib;gdi32.lib;winmm.lib;imm32.lib;ole32.lib;oleaut32.lib;shell32.lib;uuid.lib;iconv.lib;advapi32.lib;setupapi.lib</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">version.lib;dinput8.lib;dxguid.lib;user32.lib;gdi32.lib;winmm.lib;imm32.lib;ole32.lib;oleaut32.lib;shell32.lib;uuid.lib;iconv.lib;advapi32.lib;setupapi.lib;opengl32.lib</AdditionalDependencies>
<TurnOffAssemblyGeneration Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">false</TurnOffAssemblyGeneration>
<EnableUAC Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">false</EnableUAC>
<DelayLoadDLLs Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">
Expand Down Expand Up @@ -240,7 +240,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">version.lib;dinput8.lib;dxguid.lib;user32.lib;gdi32.lib;winmm.lib;imm32.lib;ole32.lib;oleaut32.lib;shell32.lib;uuid.lib;iconv.lib;advapi32.lib;setupapi.lib</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">version.lib;dinput8.lib;dxguid.lib;user32.lib;gdi32.lib;winmm.lib;imm32.lib;ole32.lib;oleaut32.lib;shell32.lib;uuid.lib;iconv.lib;advapi32.lib;setupapi.lib;opengl32.lib</AdditionalDependencies>
<TurnOffAssemblyGeneration Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
</TurnOffAssemblyGeneration>
<AdditionalLibraryDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -492,6 +492,7 @@
</None>
<None Include="res\convo.1.bml" />
<None Include="res\dingdescriptions.1.bml" />
<None Include="res\fragment.glsl" />
<None Include="res\manufacturer.dlg">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">true</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Xassy|x64'">false</DeploymentContent>
Expand All @@ -500,6 +501,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</DeploymentContent>
</None>
<None Include="res\vertex.glsl" />
<None Include="vcpkg.json" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions blooDot.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@
<None Include="planning\creatormode.ligma">
<Filter>Planning</Filter>
</None>
<None Include="res\fragment.glsl">
<Filter>Resource Files\shaders</Filter>
</None>
<None Include="res\vertex.glsl">
<Filter>Resource Files\shaders</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\nn-splash-scene.png">
Expand Down
2 changes: 1 addition & 1 deletion chunk-sizes.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ size_t chunkSizes[] = {
106415, // CHUNK_KEY_DINGS_SNURCH_SNAVIOR_FLOOR
702, // CHUNK_KEY_DINGS_SNURCH_SNAVIOR_COLLISION
882, // CHUNK_KEY_SHADER_VERTEX
4648 // CHUNK_KEY_SHADER_FRAGMENT
4873 // CHUNK_KEY_SHADER_FRAGMENT
};
2 changes: 2 additions & 0 deletions orchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ namespace blooDot::Orchestrator

void MainLoop(SDL_Renderer* renderer, SDL_Window* mainWindow)
{
#ifndef NDEBUG
toggleDebugView = isCreatorMode;

#endif
if (!InitializeDings())
{
mainRunning = false;
Expand Down
151 changes: 91 additions & 60 deletions res/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,24 @@ vec2 res = vec2(640.0,480.0); // /3.0
//------------------------------------------------------------------------
// sRGB to Linear
// Assuming using sRGB typed textures this should not be needed.
float ToLinear1(float c){return(c<=0.04045)?c/12.92:pow((c+0.055)/1.055,2.4);}
float ToLinear1(float c)
{
return
c <= 0.04045
? c / 12.92
: pow((c + 0.055) / 1.055, 2.4);
}

vec3 ToLinear(vec3 c)
{
return vec3(ToLinear1(c.r),ToLinear1(c.g),ToLinear1(c.b));
return vec3(ToLinear1(c.r),ToLinear1(c.g),ToLinear1(c.b));
}

// Linear to sRGB
// Assuming using sRGB typed textures this should not be needed
float ToSrgb1(float c)
{
return(c<0.0031308?c*12.92:1.055*pow(c,0.41666)-0.055);
return(c<0.0031308?c*12.92:1.055*pow(c,0.41666)-0.055);
}

vec3 ToSrgb(vec3 c)
Expand All @@ -62,111 +69,135 @@ vec3 ToSrgb(vec3 c)
// Also zeroes off screen
vec3 Fetch(vec2 pos,vec2 off)
{
pos=floor(pos*res+off)/res;
if(max(abs(pos.x-0.5),abs(pos.y-0.5))>0.5)return vec3(0.0,0.0,0.0);
return ToLinear(texture2D(tex0,pos.xy,-16.0).rgb);
pos=floor(pos*res+off)/res;
if(max(abs(pos.x-0.5),abs(pos.y-0.5))>0.5)
{
return vec3(0.0,0.0,0.0);
}

return ToLinear(texture2D(tex0,pos.xy,-16.0).rgb);
}

// Distance in emulated pixels to nearest texel
vec2 Dist(vec2 pos)
{
pos=pos*res;return -((pos-floor(pos))-vec2(0.5));
pos=pos*res;

return -((pos-floor(pos))-vec2(0.5));
}

// 1D Gaussian
float Gaus(float pos,float scale)
{
return exp2(scale*pos*pos);
return exp2(scale*pos*pos);
}

// 3-tap Gaussian filter along horz line
vec3 Horz3(vec2 pos,float off)
{
vec3 b=Fetch(pos,vec2(-1.0,off));
vec3 c=Fetch(pos,vec2( 0.0,off));
vec3 d=Fetch(pos,vec2( 1.0,off));
float dst=Dist(pos).x;
// Convert distance to weight
float scale=hardPix;
float wb=Gaus(dst-1.0,scale);
float wc=Gaus(dst+0.0,scale);
float wd=Gaus(dst+1.0,scale);
// Return filtered sample
return (b*wb+c*wc+d*wd)/(wb+wc+wd);
vec3 b=Fetch(pos,vec2(-1.0,off));
vec3 c=Fetch(pos,vec2( 0.0,off));
vec3 d=Fetch(pos,vec2( 1.0,off));
float dst=Dist(pos).x;
// Convert distance to weight
float scale=hardPix;
float wb=Gaus(dst-1.0,scale);
float wc=Gaus(dst+0.0,scale);
float wd=Gaus(dst+1.0,scale);

// Return filtered sample
return (b*wb+c*wc+d*wd)/(wb+wc+wd);
}

// 5-tap Gaussian filter along horz line
vec3 Horz5(vec2 pos,float off)
{
vec3 a=Fetch(pos,vec2(-2.0,off));
vec3 b=Fetch(pos,vec2(-1.0,off));
vec3 c=Fetch(pos,vec2( 0.0,off));
vec3 d=Fetch(pos,vec2( 1.0,off));
vec3 e=Fetch(pos,vec2( 2.0,off));
float dst=Dist(pos).x;
// Convert distance to weight.
float scale=hardPix;
float wa=Gaus(dst-2.0,scale);
float wb=Gaus(dst-1.0,scale);
float wc=Gaus(dst+0.0,scale);
float wd=Gaus(dst+1.0,scale);
float we=Gaus(dst+2.0,scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
vec3 a=Fetch(pos,vec2(-2.0,off));
vec3 b=Fetch(pos,vec2(-1.0,off));
vec3 c=Fetch(pos,vec2( 0.0,off));
vec3 d=Fetch(pos,vec2( 1.0,off));
vec3 e=Fetch(pos,vec2( 2.0,off));
float dst=Dist(pos).x;

// Convert distance to weight.
float scale=hardPix;
float wa=Gaus(dst-2.0,scale);
float wb=Gaus(dst-1.0,scale);
float wc=Gaus(dst+0.0,scale);
float wd=Gaus(dst+1.0,scale);
float we=Gaus(dst+2.0,scale);

// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}

// Return scanline weight
float Scan(vec2 pos,float off)
{
float dst=Dist(pos).y;
return Gaus(dst+off,hardScan);
float dst=Dist(pos).y;

return Gaus(dst+off,hardScan);
}

// Allow nearest three lines to effect pixel.
vec3 Tri(vec2 pos)
{
vec3 a=Horz3(pos,-1.0);
vec3 b=Horz5(pos, 0.0);
vec3 c=Horz3(pos, 1.0);
float wa=Scan(pos,-1.0);
float wb=Scan(pos, 0.0);
float wc=Scan(pos, 1.0);
return a*wa+b*wb+c*wc;
vec3 a=Horz3(pos,-1.0);
vec3 b=Horz5(pos, 0.0);
vec3 c=Horz3(pos, 1.0);
float wa=Scan(pos,-1.0);
float wb=Scan(pos, 0.0);
float wc=Scan(pos, 1.0);

return a*wa+b*wb+c*wc;
}

// Distortion of scanlines, and end of screen alpha
vec2 Warp(vec2 pos)
{
pos=pos*2.0-1.0;
pos*=vec2(1.0+(pos.y*pos.y)*warp.x,1.0+(pos.x*pos.x)*warp.y);
return pos*0.5+0.5;
pos=pos*2.0-1.0;
pos*=vec2(1.0+(pos.y*pos.y)*warp.x,1.0+(pos.x*pos.x)*warp.y);

return pos*0.5+0.5;
}

// Shadow mask
vec3 Mask(vec2 pos)
{
pos.x+=pos.y*3.0;
vec3 mask=vec3(maskDark,maskDark,maskDark);
pos.x=fract(pos.x/6.0);
if(pos.x<0.333)mask.r=maskLight;
else if(pos.x<0.666)mask.g=maskLight;
else mask.b=maskLight;
return mask;
pos.x+=pos.y*3.0;
vec3 mask=vec3(maskDark,maskDark,maskDark);
pos.x=fract(pos.x/6.0);
if(pos.x<0.333)
{
mask.r=maskLight;
}
else if(pos.x<0.666)
{
mask.g=maskLight;
}
else
{
mask.b=maskLight;
}

return mask;
}

// Draw dividing bars
float Bar(float pos,float bar)
{
pos-=bar;return pos*pos<4.0?0.0:1.0;
pos-=bar;

return pos*pos<4.0?0.0:1.0;
}

// Entry
void main()
{
// Unmodified
vec2 pos=Warp(v_texCoord);
vec4 fragColor;
fragColor.rgb=Tri(pos)*Mask(gl_FragCoord.xy);
fragColor.rgb=ToSrgb(fragColor.rgb);
gl_FragColor=v_color * vec4(fragColor.rgb, 1.0);
// Unmodified
vec2 pos=Warp(v_texCoord);
vec4 fragColor;
fragColor.rgb=Tri(pos)*Mask(gl_FragCoord.xy);
fragColor.rgb=ToSrgb(fragColor.rgb);
gl_FragColor=v_color * vec4(fragColor.rgb, 1.0);
}
25 changes: 21 additions & 4 deletions shader-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

using namespace blooDot::Res;

/// <summary>
/// Original inspiration for this part came from code by Augusto Ruiz
/// https://github.com/AugustoRuiz/sdl2glsl (MIT Licence)
/// </summary>
namespace blooDot::ShaderEngine
{
PFNGLCREATESHADERPROC glCreateShader;
Expand Down Expand Up @@ -87,7 +91,11 @@ namespace blooDot::ShaderEngine
{
char* log = (char*)malloc(logLen * sizeof(char));
glGetProgramInfoLog(programId, logLen, &logLen, log);
std::cout << "Prog Info Log: " << std::endl << log << std::endl;
std::cout
<< "Shader linker output:\n"
<< log
<< "\n";

free(log);
}
}
Expand Down Expand Up @@ -159,14 +167,23 @@ namespace blooDot::ShaderEngine
glGetShaderiv(result, GL_COMPILE_STATUS, &shaderCompiled);
if (shaderCompiled != GL_TRUE)
{
std::cout << "Error en la compilación: " << result << "!" << std::endl;
std::cout
<< "Failed to compiler shader:\n"
<< result
<< "\n";

GLint logLength;
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar* log = (GLchar*)malloc(logLength);

glGetShaderInfoLog(result, logLength, &logLength, log);
std::cout << "Shader compile log:" << log << std::endl;
std::cout
<< "Shader compiler output:\n"
<< log
<< "\n";

free(log);
}

Expand All @@ -175,7 +192,7 @@ namespace blooDot::ShaderEngine
}
else
{
std::cout << "Shader compilado correctamente. Id = " << result << std::endl;
std::cout << "Successfully compiled shader #" << result << "\n";
}

return result;
Expand Down

0 comments on commit 1095f4a

Please sign in to comment.