Skip to content
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
Binary file added Original.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CIS565: Project 4: Image Processing/Vertex Shading
-------------------------------------------------------------------------------
Fall 2012
-------------------------------------------------------------------------------
Due Friday 11/09/2012
-------------------------------------------------------------------------------

Implemented the following:
1 - Original Image
2 - Box blur
3 - Negative
4 - Gaussian Blur
5 - Grayscale
6 - Edge Detection
7 - Toon Shading
8 - Vintage Photo (Blur, Noise, Vignettting)
9 - Brightness
0 - Unsharp Mask
- - Sharpened image
q - Night Vision (Noise and circular mask)


In my custom vertex shader, I randomized using the position's y value and then nultiplied it with time and then took a sin wave to get a wave moving up and down randomized on y position.


Blog:
http://tijugraphics.blogspot.com/


-------------------------------------------------------------------------------
NOTE:
-------------------------------------------------------------------------------
Expand Down
Binary file added part1/ImageProcessing/ImageProcessing.sdf
Binary file not shown.
10 changes: 10 additions & 0 deletions part1/ImageProcessing/ImageProcessing/ImageProcessing.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@
</ItemGroup>
<ItemGroup>
<None Include="boxBlurFS.glsl" />
<None Include="brightnessFS.glsl" />
<None Include="edgeDetectionFS.glsl" />
<None Include="gaussianBlurFS.glsl" />
<None Include="grayscaleFS.glsl" />
<None Include="negativeFS.glsl" />
<None Include="nightVisionFS.glsl" />
<None Include="passthroughFS.glsl" />
<None Include="passthroughVS.glsl" />
<None Include="sharpenFS.glsl" />
<None Include="toonShadingFS.glsl" />
<None Include="unsharpMaskFS.glsl" />
<None Include="vintageFS.glsl" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>
Binary file added part1/ImageProcessing/ImageProcessing/Lenna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
8 changes: 8 additions & 0 deletions part1/ImageProcessing/ImageProcessing/brightnessFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;

void main(void)
{
gl_FragColor = vec4(texture2D(u_image, v_Texcoords).xyz*1.3, 1.0);
}
31 changes: 31 additions & 0 deletions part1/ImageProcessing/ImageProcessing/edgeDetectionFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;
uniform vec2 u_step;

const int KERNEL_WIDTH = 3; // Odd
const float offset = 1.0;
const vec3 W = vec3(0.2, 0.2, 0.2);
const mat3 vert = mat3(vec3(-1,-2,-1), vec3(0,0,0), vec3(1,2,1));
const mat3 hor = mat3(vec3(-1,0,1), vec3(-2,0,2), vec3(-1,0,1));

void main(void)
{
float luminance = dot(texture2D(u_image, v_Texcoords).rgb, W);

float accumHor = 0.0;
float accumVert = 0.0;

for (int i = 0; i < KERNEL_WIDTH; ++i)
{
for (int j = 0; j < KERNEL_WIDTH; ++j)
{
vec2 coord = vec2(v_Texcoords.s + ((float(i) - offset) * u_step.s), v_Texcoords.t + ((float(j) - offset) * u_step.t));
float dotProd = dot(texture2D(u_image, coord).rgb, W);
accumHor += dotProd * hor[i][j];
accumVert += dotProd * vert[i][j];
}
}

gl_FragColor = vec4(vec3(length(vec2(accumHor, accumVert))), 1.0);
}
24 changes: 24 additions & 0 deletions part1/ImageProcessing/ImageProcessing/gaussianBlurFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;
uniform vec2 u_step;

const int KERNEL_WIDTH = 3; // Odd
const float offset = 1.0;
const mat3 gauss = mat3(vec3(1,2,1), vec3(2,4,2), vec3(1,2,1));

void main(void)
{
vec3 accum = vec3(0.0);

for (int i = 0; i < KERNEL_WIDTH; ++i)
{
for (int j = 0; j < KERNEL_WIDTH; ++j)
{
vec2 coord = vec2(v_Texcoords.s + ((float(i) - offset) * u_step.s), v_Texcoords.t + ((float(j) - offset) * u_step.t));
accum += texture2D(u_image, coord).rgb * gauss[i][j];
}
}

gl_FragColor = vec4(accum / 16.0, 1.0);
}
10 changes: 10 additions & 0 deletions part1/ImageProcessing/ImageProcessing/grayscaleFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;
const vec3 W = vec3(0.2125, 0.7154, 0.0721);

void main(void)
{
float luminance = dot(texture2D(u_image, v_Texcoords).rgb, W);
gl_FragColor = vec4(vec3(luminance),1.0);
}
61 changes: 58 additions & 3 deletions part1/ImageProcessing/ImageProcessing/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@
#include "Utility.h"
#include "SOIL.h"

int width = 640;
int height = 480;
int width = 512;
int height = 512;

GLuint positionLocation = 0;
GLuint texcoordsLocation = 1;
const char *attributeLocations[] = { "Position", "Tex" };

GLuint passthroughProgram;
GLuint boxBlurProgram;
GLuint negativeProgram;
GLuint gaussianBlurProgram;
GLuint grayscaleProgram;
GLuint edgeDetectionProgram;
GLuint toonShadingProgram;
GLuint vintageProgram;
GLuint brightnessProgram;
GLuint sharpenProgram;
GLuint unsharpMaskProgram;
GLuint nightVisionProgram;
GLuint weirdProgram;

GLuint initShader(const char *vertexShaderPath, const char *fragmentShaderPath)
{
Expand All @@ -36,7 +47,7 @@ GLuint initShader(const char *vertexShaderPath, const char *fragmentShaderPath)

void initTextures()
{
GLuint image = SOIL_load_OGL_texture("Valve.png", 3, 0, 0);
GLuint image = SOIL_load_OGL_texture("Lenna.png", 3, 0, 0);
glBindTexture(GL_TEXTURE_2D, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Expand Down Expand Up @@ -104,6 +115,39 @@ void keyboard(unsigned char key, int x, int y)
case '2':
glUseProgram(boxBlurProgram);
break;
case '3':
glUseProgram(negativeProgram);
break;
case '4':
glUseProgram(gaussianBlurProgram);
break;
case '5':
glUseProgram(grayscaleProgram);
break;
case '6':
glUseProgram(edgeDetectionProgram);
break;
case '7':
glUseProgram(toonShadingProgram);
break;
case '8':
glUseProgram(vintageProgram);
break;
case '9':
glUseProgram(brightnessProgram);
break;
case '0':
glUseProgram(unsharpMaskProgram);
break;
case '-':
glUseProgram(sharpenProgram);
break;
case 'q':
glUseProgram(nightVisionProgram);
break;
case 'w':
glUseProgram(weirdProgram);
break;
}
}

Expand Down Expand Up @@ -133,6 +177,17 @@ int main(int argc, char* argv[])
initTextures();
passthroughProgram = initShader("passthroughVS.glsl", "passthroughFS.glsl");
boxBlurProgram = initShader("passthroughVS.glsl", "boxBlurFS.glsl");
negativeProgram = initShader("passthroughVS.glsl", "negativeFS.glsl");
gaussianBlurProgram = initShader("passthroughVS.glsl", "gaussianBlurFS.glsl");
grayscaleProgram = initShader("passthroughVS.glsl", "grayscaleFS.glsl");
edgeDetectionProgram = initShader("passthroughVS.glsl", "edgeDetectionFS.glsl");
toonShadingProgram = initShader("passthroughVS.glsl", "toonShadingFS.glsl");
vintageProgram = initShader("passthroughVS.glsl", "vintageFS.glsl");
brightnessProgram = initShader("passthroughVS.glsl", "brightnessFS.glsl");
unsharpMaskProgram = initShader("passthroughVS.glsl", "unsharpMaskFS.glsl");
sharpenProgram = initShader("passthroughVS.glsl", "sharpenFS.glsl");
nightVisionProgram = initShader("passthroughVS.glsl", "nightVisionFS.glsl");
weirdProgram = initShader("weirdVS.glsl", "passthroughFS.glsl");

glutDisplayFunc(display);
glutReshapeFunc(reshape);
Expand Down
8 changes: 8 additions & 0 deletions part1/ImageProcessing/ImageProcessing/negativeFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;

void main(void)
{
gl_FragColor = 1.0 - texture2D(u_image, v_Texcoords);
}
18 changes: 18 additions & 0 deletions part1/ImageProcessing/ImageProcessing/nightVisionFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;

// From stack overflow
float rand(vec2 val)
{
return fract(sin(dot(val.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

void main(void)
{
float noise = rand(vec2(v_Texcoords.s, v_Texcoords.t));
if (length(vec2(v_Texcoords.s - 0.5, v_Texcoords.t - 0.5)) > 0.45)
gl_FragColor = vec4(vec3(0),1.0);
else
gl_FragColor = vec4(vec3(texture2D(u_image, v_Texcoords).xyz * vec3(0,1,0)) + vec3(noise/4.0), 1.0);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions part1/ImageProcessing/ImageProcessing/sharpenFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;
uniform vec2 u_step;

const int KERNEL_WIDTH = 3; // Odd
const float offset = 1.0;
const mat3 gauss = mat3(vec3(1,2,1), vec3(2,4,2), vec3(1,2,1));

void main(void)
{
vec3 accum = vec3(0.0);

for (int i = 0; i < KERNEL_WIDTH; ++i)
{
for (int j = 0; j < KERNEL_WIDTH; ++j)
{
vec2 coord = vec2(v_Texcoords.s + ((float(i) - offset) * u_step.s), v_Texcoords.t + ((float(j) - offset) * u_step.t));
accum += texture2D(u_image, coord).rgb * gauss[i][j];
}
}

vec4 originalColor = texture2D(u_image, v_Texcoords);

// Unsharp Mask
vec3 difference = abs(vec3(originalColor.xyz) - accum / 16.0);

if (difference.x > 0.04 || difference.y > 0.04 || difference.z > 0.04)
gl_FragColor = vec4(originalColor.xyz*1.1, 1.0);
else
gl_FragColor = originalColor;
}
43 changes: 43 additions & 0 deletions part1/ImageProcessing/ImageProcessing/toonShadingFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;
uniform vec2 u_step;

const int KERNEL_WIDTH = 3; // Odd
const float offset = 1.0;
const vec3 W = vec3(0.3, 0.3, 0.3);
const mat3 vert = mat3(vec3(-1,-2,-1), vec3(0,0,0), vec3(1,2,1));
const mat3 hor = mat3(vec3(-1,0,1), vec3(-2,0,2), vec3(-1,0,1));

void main(void)
{
vec3 color = texture2D(u_image, v_Texcoords).rgb;
float luminance = dot(color, W);

float accumHor = 0.0;
float accumVert = 0.0;

for (int i = 0; i < KERNEL_WIDTH; ++i)
{
for (int j = 0; j < KERNEL_WIDTH; ++j)
{
vec2 coord = vec2(v_Texcoords.s + ((float(i) - offset) * u_step.s), v_Texcoords.t + ((float(j) - offset) * u_step.t));
float dotProd = dot(texture2D(u_image, coord).rgb, W);
accumHor += dotProd * hor[i][j];
accumVert += dotProd * vert[i][j];
}
}

float len = length(vec2(accumHor, accumVert));
if (len > 0.36)
gl_FragColor = vec4(vec3(0),1.0);
else
{
float quantize = 6.3;
color.rgb *= quantize;
color.rgb += vec3(0.5);
ivec3 irgb = ivec3(color.rgb);
color.rgb = vec3(irgb) / quantize;
gl_FragColor = vec4(vec3(color), 1.0);
}
}
30 changes: 30 additions & 0 deletions part1/ImageProcessing/ImageProcessing/unsharpMaskFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
varying vec2 v_Texcoords;

uniform sampler2D u_image;
uniform vec2 u_step;

const int KERNEL_WIDTH = 3; // Odd
const float offset = 1.0;
const mat3 gauss = mat3(vec3(1,2,1), vec3(2,4,2), vec3(1,2,1));

void main(void)
{
vec3 accum = vec3(0.0);

for (int i = 0; i < KERNEL_WIDTH; ++i)
{
for (int j = 0; j < KERNEL_WIDTH; ++j)
{
vec2 coord = vec2(v_Texcoords.s + ((float(i) - offset) * u_step.s), v_Texcoords.t + ((float(j) - offset) * u_step.t));
accum += texture2D(u_image, coord).rgb * gauss[i][j];
}
}

vec4 originalColor = texture2D(u_image, v_Texcoords);

// Unsharp Mask
vec3 difference = abs(vec3(originalColor.xyz) - accum / 16.0);

gl_FragColor = vec4(difference*4.0, 1.0);

}
Loading