Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old-movie style #1

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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
11 changes: 6 additions & 5 deletions Intro/leviathan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
</ProjectReference>
<PreBuildEvent>
<Message>Minify user-supplied shader files.</Message>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\edges.frag src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Editor|Win32'">
Expand Down Expand Up @@ -267,7 +267,7 @@
</ProjectReference>
<PreBuildEvent>
<Message>Minify user-supplied shader files.</Message>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\edges.frag src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -357,7 +357,7 @@
</ProjectReference>
<PreBuildEvent>
<Message>Minify user-supplied shader files.</Message>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\edges.frag src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Heavy Release|Win32'">
Expand Down Expand Up @@ -450,7 +450,7 @@
</ProjectReference>
<PreBuildEvent>
<Message>Minify user-supplied shader files.</Message>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\edges.frag src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Snapshot|Win32'">
Expand Down Expand Up @@ -549,7 +549,7 @@
</ProjectReference>
<PreBuildEvent>
<Message>Minify user-supplied shader files.</Message>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
<Command>shader_minifier.exe -v -o src\shaders\shaders.inl src\shaders\mouton.frag src\shaders\mouton.vert src\shaders\edges.frag src\shaders\fxaa.frag src\shaders\postprocess.frag</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -565,6 +565,7 @@
<ClCompile Include="src\main.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="src\shaders\edges.frag" />
<None Include="src\shaders\fxaa.frag" />
<None Include="src\shaders\mouton.frag" />
<None Include="src\shaders\mouton.vert" />
Expand Down
3 changes: 3 additions & 0 deletions Intro/leviathan.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<None Include="src\shaders\shaders.inl">
<Filter>shaders</Filter>
</None>
<None Include="src\shaders\edges.frag">
<Filter>shaders</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Filter Include="ext">
Expand Down
21 changes: 21 additions & 0 deletions Intro/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
// static allocation saves a few bytes
static int shaderMain;
static int shaderFXAA;
static int shaderEdges;
static int shaderPostProcess;
// static HDC hDC;


#pragma code_seg(".main")
void entrypoint(void)
{
Expand Down Expand Up @@ -66,6 +68,14 @@ void entrypoint(void)
((PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader"))(shaderFXAA, f);
((PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram"))(shaderFXAA);

// Edges
f = ((PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader"))(GL_FRAGMENT_SHADER);
((PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource"))(f, 1, &edges_frag, 0);
((PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader"))(f);

shaderEdges = ((PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram"))();
((PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader"))(shaderEdges, f);
((PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram"))(shaderEdges);

// Post process
f = ((PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader"))(GL_FRAGMENT_SHADER);
Expand Down Expand Up @@ -93,6 +103,7 @@ void entrypoint(void)
PeekMessage(0, 0, 0, 0, PM_REMOVE);
#endif


// main renderer
((PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"))(shaderMain);
((PFNGLUNIFORM1FPROC)wglGetProcAddress("glUniform1f"))(0, time);
Expand All @@ -114,6 +125,16 @@ void entrypoint(void)
((PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"))(shaderFXAA);
glRects(-1, -1, 1, 1);

// edges

glBindTexture(GL_TEXTURE_2D, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, XRES, YRES, 0);
((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"))(GL_TEXTURE0);
((PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"))(shaderEdges);
((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"))(0, 0);
glRects(-1, -1, 1, 1);

// Post processing

glBindTexture(GL_TEXTURE_2D, 1);
Expand Down
45 changes: 45 additions & 0 deletions Intro/src/shaders/edges.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#version 150
out vec4 fragColor;
const vec2 iResolution = vec2(1280.,720.);

uniform sampler2D prevPass;

float checkSame(vec4 center, vec4 samplef)
{
vec2 centerNormal = center.xy;
float centerDepth = center.z;
vec2 sampleNormal = samplef.xy;
float sampleDepth = samplef.z;

if (centerDepth > .999 && sampleDepth > .999) return 1.;

// Less sensitive when it's far away; more edge details when it's closer.
float sensitivity = mix(1.3, .4, centerDepth);

float distNormal = distance(centerNormal, sampleNormal) * sensitivity;
if (distNormal > 0.15) return mix(0.6, 1., smoothstep(0.15, 1., distNormal));

float diffDepth = abs(centerDepth - sampleDepth) * sensitivity;
bool isSameDepth = min(centerDepth,sampleDepth) / max(centerDepth,sampleDepth) > 0.85;
//isSameDepth = true;

return isSameDepth ? 1.0 : 0.6;
// return 1.;
}

void main(void)
{
float width = 0.0009;
vec4 sample0 = texture(prevPass, gl_FragCoord.xy / iResolution.xy);
vec4 sample1 = texture(prevPass, gl_FragCoord.xy / iResolution.xy + vec2(width, width));
vec4 sample2 = texture(prevPass, gl_FragCoord.xy / iResolution.xy + vec2(-width, -width));
vec4 sample3 = texture(prevPass, gl_FragCoord.xy / iResolution.xy + vec2(-width, width));
vec4 sample4 = texture(prevPass, gl_FragCoord.xy / iResolution.xy + vec2(width, -width));

float edge = checkSame(sample1, sample2) * checkSame(sample3, sample4);

// edge, base color, depth
fragColor = vec4(edge, sample0.w, sample0.z, 1.);
//fragColor = vec4(edge, sample0.w, sample0.z, 1.);
}

23 changes: 12 additions & 11 deletions Intro/src/shaders/fxaa.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ uniform sampler2D prevPass;

vec3 FxaaPixelShader( vec4 uv, sampler2D tex, vec2 rcpFrame) {

vec3 rgbNW = textureLod(tex, uv.zw, 0.0).xyz;
vec3 rgbNE = textureLod(tex, uv.zw + vec2(1,0)*rcpFrame.xy, 0.0).xyz;
vec3 rgbSW = textureLod(tex, uv.zw + vec2(0,1)*rcpFrame.xy, 0.0).xyz;
vec3 rgbSE = textureLod(tex, uv.zw + vec2(1,1)*rcpFrame.xy, 0.0).xyz;
vec3 rgbM = textureLod(tex, uv.xy, 0.0).xyz;
vec3 rgbNW = textureLod(tex, uv.zw, 0.0).rrg;
vec3 rgbNE = textureLod(tex, uv.zw + vec2(1,0)*rcpFrame.xy, 0.0).rrg;
vec3 rgbSW = textureLod(tex, uv.zw + vec2(0,1)*rcpFrame.xy, 0.0).rrg;
vec3 rgbSE = textureLod(tex, uv.zw + vec2(1,1)*rcpFrame.xy, 0.0).rrg;
vec3 rgbM = textureLod(tex, uv.xy, 0.0).rrg;

vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
Expand All @@ -37,11 +37,11 @@ vec3 FxaaPixelShader( vec4 uv, sampler2D tex, vec2 rcpFrame) {
dir * rcpDirMin)) * rcpFrame.xy;

vec3 rgbA = (1.0/2.0) * (
textureLod(tex, uv.xy + dir * (1.0/3.0 - 0.5), 0.0).xyz +
textureLod(tex, uv.xy + dir * (2.0/3.0 - 0.5), 0.0).xyz);
textureLod(tex, uv.xy + dir * (1.0/3.0 - 0.5), 0.0).rrg +
textureLod(tex, uv.xy + dir * (2.0/3.0 - 0.5), 0.0).rrg);
vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (
textureLod(tex, uv.xy + dir * (0.0/3.0 - 0.5), 0.0).xyz +
textureLod(tex, uv.xy + dir * (3.0/3.0 - 0.5), 0.0).xyz);
textureLod(tex, uv.xy + dir * (0.0/3.0 - 0.5), 0.0).rrg +
textureLod(tex, uv.xy + dir * (3.0/3.0 - 0.5), 0.0).rrg);

float lumaB = dot(rgbB, luma);

Expand All @@ -57,5 +57,6 @@ void main(void)
vec4 uv = vec4( texcoord, texcoord - (invRes * 0.5));

vec3 col = FxaaPixelShader(uv, prevPass, invRes);
fragColor = vec4(col,1.);
}
vec4 orig = textureLod(prevPass, uv.xy, 0.0);
fragColor = vec4(col.r, col.b, orig.zw);
}
Loading