Skip to content

Commit

Permalink
Renderer refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
damacaa committed Oct 5, 2024
1 parent 0100fa3 commit 8add900
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 44 deletions.
4 changes: 4 additions & 0 deletions src/weird-renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ namespace WeirdRenderer
// Tell OpenGL which Shader Program we want to use
glUseProgram(m_outputShaderProgram.ID);

GLuint u_colorTextureLocation = glGetUniformLocation(m_outputShaderProgram.ID, "u_colorTexture");
glUniform1i(u_colorTextureLocation, 0);

m_outputTexture.bind(0);

m_outputRenderPlane.Draw(m_outputShaderProgram);


Expand Down
15 changes: 6 additions & 9 deletions src/weird-renderer/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ namespace WeirdRenderer
glBindTexture(GL_TEXTURE_2D, ID);
}



void Texture::unbind() const
{
glBindTexture(GL_TEXTURE_2D, 0);
Expand Down Expand Up @@ -211,21 +209,20 @@ namespace WeirdRenderer
Texture::Texture(int width, int height, GLuint filterMode)
{
glGenTextures(1, &ID);
bind();
glBindTexture(GL_TEXTURE_2D, ID);

unsigned char* textureData = new unsigned char[width * height * 4];
float* textureData = new float[width * height * 4];

for (size_t i = 0; i < width * height * 4; i++)
{
textureData[i] = 255;
textureData[i] = 1.0f;
}


glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, textureData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterMode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterMode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Prevents edge bleeding
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Prevents edge bleeding
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


delete[] textureData;
Expand Down
5 changes: 0 additions & 5 deletions src/weird-renderer/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ namespace WeirdRenderer
void dispose() const;

void saveToDisk(const char* fileName);

private:

GLenum m_textureSlot;

};
}

Expand Down
41 changes: 11 additions & 30 deletions src/weird-renderer/shaders/output.frag
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#version 330 core

// Outputs colors in RGBA
out vec4 FragColor;
out vec3 FragColor;

uniform vec2 u_resolution;
uniform float u_renderScale;

uniform float u_time;

uniform sampler2D u_colorTexture;
uniform sampler2D u_depthTexture;

float rand(vec2 co){
float rand(vec2 co)
{
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}

Expand All @@ -24,38 +24,19 @@ void main()
vec4 color = texture(u_colorTexture, screenUV);
float distance = color.w;


vec2 texelOffset = vec2(0.005, 0.0025);

// Sample the texture at the center and neighboring pixels
vec4 colorCenter = texture(u_colorTexture, screenUV);
vec4 colorRight = texture(u_colorTexture, screenUV + vec2(texelOffset.x, 0.0));
vec4 colorLeft = texture(u_colorTexture, screenUV - vec2(texelOffset.x, 0.0));
vec4 colorUp = texture(u_colorTexture, screenUV + vec2(0.0, texelOffset.y));
vec4 colorDown = texture(u_colorTexture, screenUV - vec2(0.0, texelOffset.y));

// Simple average of the neighboring pixels for antialiasing
vec4 averagedColor = (colorCenter + colorRight + colorLeft + colorUp + colorDown) / 5.0;

//distance = averagedColor.r;

//distance = sin(100.0 * distance);

//vec3 col = vec3(distance);
vec3 col = distance <= 0.5 ? color.xyz : vec3(0.9);

//vec2 TexCoords = fract(gl_FragCoord.xy * u_renderScale);

// Dot effect
//vec2 dist = TexCoords - vec2(0.5f, 0.5f);
//float mask = ((1-length(dist)) - 0.25) * 2;
//col *= mask;
// vec2 TexCoords = fract(gl_FragCoord.xy * u_renderScale);
// vec2 dist = TexCoords - vec2(0.5f, 0.5f);
// float mask = ((1.0 -length(dist)) - 0.25) * 2;

// CRT Line effect
//float mask = sin(3.14 * (gl_FragCoord.y * u_renderScale));
//mask = mask > 0.25 ? 1.0 : 0.0;
//col *= mask;
// float mask = sin(3.14 * (gl_FragCoord.y * u_renderScale));
// mask = mask > 0.25 ? 1.0 : 0.0;

//FragColor = color.xyz * mask;
//FragColor = color.wwww;
FragColor = color;

FragColor = color.xyz;
}

0 comments on commit 8add900

Please sign in to comment.