randomly translate noise every frame

This commit is contained in:
ktyl 2021-08-09 18:15:43 +01:00
parent 7f84ffd551
commit 24ec0f8e57
3 changed files with 18 additions and 9 deletions

View File

@ -26,7 +26,6 @@ layout (location = 13) uniform Sphere _spheres[SPHERES];
uniform vec4 _seed;
layout(rgba32f, binding = 0) uniform image2D img_output; // rgba32f defines internal format, image2d for random write to output texture
layout(binding=1) uniform sampler2D _noise; // noise texture
@ -164,7 +163,10 @@ vec2 pixelUv()
vec4 sampleNoise()
{
return texture(_noise, pixelUv());
vec2 uv = pixelUv();
uv += _seed.xy;
return texture(_noise, uv);
}
float random(vec2 st)
@ -242,8 +244,8 @@ void main()
vec2 uv = pixelUv();
int samples = 2;
int bounces = 2;
int samples = 1;
int bounces = 4;
for (int i = 0; i < samples; i++)
{

View File

@ -13,17 +13,15 @@ void updateUniforms(GLuint shaderProgram);
int main()
{
printf("GL_TEXTURE0: %d\n", GL_TEXTURE0);
printf("GL_TEXTURE1: %d\n", GL_TEXTURE1);
randomInit();
// create a window and opengl context
SDL_Window* window = gfxInit(WIDTH, HEIGHT);
// generate noise
GLuint noise = createNoiseTexture(WIDTH, HEIGHT);
// create a texture for the compute shader to write to
GLuint textureOutput = createWriteOnlyTexture(WIDTH, HEIGHT);
printWorkGroupLimits();
// compile shader programs
unsigned int computeProgram = compileComputeShaderProgram(
@ -32,10 +30,16 @@ int main()
"bin/shader.vert",
"bin/shader.frag");
// generate noise
GLuint noise = createNoiseTexture(WIDTH, HEIGHT);
glBindTexture(GL_TEXTURE_2D, noise);
int noiseLoc = glGetUniformLocation(computeProgram, "_noise");
glUniform1i(noiseLoc, noise);
// create a texture for the compute shader to write to
GLuint textureOutput = createWriteOnlyTexture(WIDTH, HEIGHT);
printWorkGroupLimits();
// initialise quad
initBuffers();
setVertexAttributes();

View File

@ -1,3 +1,6 @@
* [-] preprocessor
* [x] #include directives
* [ ] keep track of previously included files to avoid redefinitions
* [-] render image with compute shader
* [x] render a texture to a full-screen quad
* [x] pass uniforms to shader to animate it