Skip to content

Commit 8add900

Browse files
committed
Renderer refactor
1 parent 0100fa3 commit 8add900

File tree

4 files changed

+21
-44
lines changed

4 files changed

+21
-44
lines changed

src/weird-renderer/Renderer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ namespace WeirdRenderer
196196
// Tell OpenGL which Shader Program we want to use
197197
glUseProgram(m_outputShaderProgram.ID);
198198

199+
GLuint u_colorTextureLocation = glGetUniformLocation(m_outputShaderProgram.ID, "u_colorTexture");
200+
glUniform1i(u_colorTextureLocation, 0);
201+
199202
m_outputTexture.bind(0);
203+
200204
m_outputRenderPlane.Draw(m_outputShaderProgram);
201205

202206

src/weird-renderer/Texture.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ namespace WeirdRenderer
111111
glBindTexture(GL_TEXTURE_2D, ID);
112112
}
113113

114-
115-
116114
void Texture::unbind() const
117115
{
118116
glBindTexture(GL_TEXTURE_2D, 0);
@@ -211,21 +209,20 @@ namespace WeirdRenderer
211209
Texture::Texture(int width, int height, GLuint filterMode)
212210
{
213211
glGenTextures(1, &ID);
214-
bind();
212+
glBindTexture(GL_TEXTURE_2D, ID);
215213

216-
unsigned char* textureData = new unsigned char[width * height * 4];
214+
float* textureData = new float[width * height * 4];
217215

218216
for (size_t i = 0; i < width * height * 4; i++)
219217
{
220-
textureData[i] = 255;
218+
textureData[i] = 1.0f;
221219
}
222220

223-
224-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
221+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, textureData);
225222
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterMode);
226223
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterMode);
227-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Prevents edge bleeding
228-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Prevents edge bleeding
224+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
225+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
229226

230227

231228
delete[] textureData;

src/weird-renderer/Texture.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ namespace WeirdRenderer
4040
void dispose() const;
4141

4242
void saveToDisk(const char* fileName);
43-
44-
private:
45-
46-
GLenum m_textureSlot;
47-
4843
};
4944
}
5045

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#version 330 core
22

33
// Outputs colors in RGBA
4-
out vec4 FragColor;
4+
out vec3 FragColor;
55

66
uniform vec2 u_resolution;
77
uniform float u_renderScale;
88

99
uniform float u_time;
1010

1111
uniform sampler2D u_colorTexture;
12-
uniform sampler2D u_depthTexture;
1312

14-
float rand(vec2 co){
13+
float rand(vec2 co)
14+
{
1515
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
1616
}
1717

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

27-
28-
vec2 texelOffset = vec2(0.005, 0.0025);
29-
30-
// Sample the texture at the center and neighboring pixels
31-
vec4 colorCenter = texture(u_colorTexture, screenUV);
32-
vec4 colorRight = texture(u_colorTexture, screenUV + vec2(texelOffset.x, 0.0));
33-
vec4 colorLeft = texture(u_colorTexture, screenUV - vec2(texelOffset.x, 0.0));
34-
vec4 colorUp = texture(u_colorTexture, screenUV + vec2(0.0, texelOffset.y));
35-
vec4 colorDown = texture(u_colorTexture, screenUV - vec2(0.0, texelOffset.y));
36-
37-
// Simple average of the neighboring pixels for antialiasing
38-
vec4 averagedColor = (colorCenter + colorRight + colorLeft + colorUp + colorDown) / 5.0;
39-
40-
//distance = averagedColor.r;
41-
42-
//distance = sin(100.0 * distance);
43-
44-
//vec3 col = vec3(distance);
4527
vec3 col = distance <= 0.5 ? color.xyz : vec3(0.9);
4628

47-
//vec2 TexCoords = fract(gl_FragCoord.xy * u_renderScale);
48-
4929
// Dot effect
50-
//vec2 dist = TexCoords - vec2(0.5f, 0.5f);
51-
//float mask = ((1-length(dist)) - 0.25) * 2;
52-
//col *= mask;
30+
// vec2 TexCoords = fract(gl_FragCoord.xy * u_renderScale);
31+
// vec2 dist = TexCoords - vec2(0.5f, 0.5f);
32+
// float mask = ((1.0 -length(dist)) - 0.25) * 2;
5333

5434
// CRT Line effect
55-
//float mask = sin(3.14 * (gl_FragCoord.y * u_renderScale));
56-
//mask = mask > 0.25 ? 1.0 : 0.0;
57-
//col *= mask;
35+
// float mask = sin(3.14 * (gl_FragCoord.y * u_renderScale));
36+
// mask = mask > 0.25 ? 1.0 : 0.0;
5837

38+
//FragColor = color.xyz * mask;
5939
//FragColor = color.wwww;
60-
FragColor = color;
40+
41+
FragColor = color.xyz;
6142
}

0 commit comments

Comments
 (0)