Skip to content

Commit

Permalink
Add rocket tab separator at uniform name underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
gustafla committed Aug 6, 2023
1 parent a82e010 commit 007e6d2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ tracks, and before you set reasonable values to them, nothing will render.

![Camera controls in Rocket](doc/rocketcam.png)

A good starting point is to set CamFov to some value between 45 and 90,
CamPos.z to 3, leave CamTarget as all zeroes (the origin).
A good starting point is to set Fov to some value between 45 and 90,
Pos.z to 3, leave Target as all zeroes (the origin).
Also try and see what other rocket tracks do.

## Releasing
Expand Down
Binary file modified doc/rocketcam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions shaders/bloom_pre.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ out vec4 FragColor;

in vec2 FragCoord;

uniform float r_PostBloomTreshold;
uniform float r_Post_BloomTreshold;
uniform sampler2D u_InputSampler;

void main() {
vec3 c = texture2D(u_InputSampler, FragCoord * 0.5 + 0.5).rgb;
float brightness = dot(c, vec3(0.2126, 0.7152, 0.0722));
if (brightness < 1. + r_PostBloomTreshold) {
if (brightness < 1. + r_Post_BloomTreshold) {
discard;
}
FragColor = vec4(c, 1.);
Expand Down
4 changes: 2 additions & 2 deletions shaders/post.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ uniform sampler2D u_BloomSampler;
uniform int u_NoiseSize;
uniform float u_RocketRow;
uniform vec2 u_Resolution;
uniform float r_PostAberration;
uniform float r_Post_Aberration;

#define BLUR_SAMPLES 8

Expand All @@ -25,7 +25,7 @@ vec3 acesApprox(vec3 v) {
vec3 radialSum(vec2 r) {
vec3 color = vec3(0.);
for (int i = 0; i < BLUR_SAMPLES; i++) {
vec2 d = (r * float(i) * r_PostAberration) / BLUR_SAMPLES;
vec2 d = (r * float(i) * r_Post_Aberration) / BLUR_SAMPLES;
vec2 uv = FragCoord * (0.5 - d) + 0.5;
color += texture2D(u_InputSampler, uv).rgb;
}
Expand Down
14 changes: 7 additions & 7 deletions shaders/shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ in vec2 FragCoord;

uniform float u_RocketRow;
uniform vec2 u_Resolution;
uniform float r_CamFov;
uniform vec3 r_CamPos;
uniform vec3 r_CamTarget;
uniform float r_Cam_Fov;
uniform vec3 r_Cam_Pos;
uniform vec3 r_Cam_Target;
uniform float r_MotionBlur;

uniform sampler2D u_FeedbackSampler;
Expand All @@ -25,14 +25,14 @@ float aspectRatio() {
}

mat3 viewMatrix() {
vec3 f = normalize(r_CamTarget - r_CamPos);
vec3 f = normalize(r_Cam_Target - r_Cam_Pos);
vec3 s = normalize(cross(f, vec3(0., 1., 0.)));
vec3 u = cross(s, f);
return mat3(s, u, f);
}

vec3 cameraRay() {
float c = tan((90. - r_CamFov / 2.) * (PI / 180.));
float c = tan((90. - r_Cam_Fov / 2.) * (PI / 180.));
return normalize(vec3(FragCoord * vec2(aspectRatio(), 1.), c));
}

Expand Down Expand Up @@ -76,8 +76,8 @@ float march(vec3 o, vec3 d) {
void main() {
vec3 ray = viewMatrix() * cameraRay();

float t = march(r_CamPos, ray);
vec3 pos = r_CamPos + ray * t;
float t = march(r_Cam_Pos, ray);
vec3 pos = r_Cam_Pos + ray * t;

vec3 normal = normal(pos);
float ndotl = max(dot(-normal, vec3(0., -1., 0)), 0.);
Expand Down
61 changes: 36 additions & 25 deletions src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <SDL2/SDL.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sync.h>

#define NOISE_SIZE 256
Expand Down Expand Up @@ -221,53 +222,63 @@ demo_t *demo_init(int width, int height) {
return demo;
}

static char *rocket_component(const char *name, size_t name_len, char c) {
static char components[UFM_NAME_MAX + 2];
assert(name_len < UFM_NAME_MAX);
memcpy(components, name, name_len);
components[name_len] = '.';
components[name_len + 1] = c;
components[name_len + 2] = 0;
return components;
static const char *rocket_track_name(uniform_t *ufm, char c) {
static char trackname[UFM_NAME_MAX];

// Adjust for r_ -prefix
const char *name = ufm->name + 2;
size_t name_len = ufm->name_len - 2;

memcpy(trackname, name, name_len + 1);

// Replace second underscore with colon (tab) when possible
char *underscore = memchr(trackname, '_', name_len);
if (underscore) {
*underscore = ':';
}

// Add component suffix when required
if (c) {
trackname[name_len] = '.';
trackname[name_len + 1] = c;
trackname[name_len + 2] = 0;
}

return trackname;
}

static void set_rocket_uniforms(const program_t *program,
struct sync_device *rocket, double rocket_row) {
for (size_t i = 0; i < program->uniform_count; i++) {
uniform_t *ufm = program->uniforms + i;

// Check and adjust for r_ -prefix
// Check for r_ -prefix
if (ufm->name_len < 3 || ufm->name[0] != 'r' || ufm->name[1] != '_') {
continue;
}
const char *name = ufm->name + 2;
size_t name_len = ufm->name_len - 2;

GLuint location = glGetUniformLocation(program->handle, ufm->name);
switch (ufm->type) {
case UFM_FLOAT:
glUniform1f(location, GET_VALUE(name));
glUniform1f(location, GET_VALUE(rocket_track_name(ufm, 0)));
break;
case UFM_VEC2:
glUniform2f(location,
GET_VALUE(rocket_component(name, name_len, 'x')),
GET_VALUE(rocket_component(name, name_len, 'y')));
glUniform2f(location, GET_VALUE(rocket_track_name(ufm, 'x')),
GET_VALUE(rocket_track_name(ufm, 'y')));
break;
case UFM_VEC3:
glUniform3f(location,
GET_VALUE(rocket_component(name, name_len, 'x')),
GET_VALUE(rocket_component(name, name_len, 'y')),
GET_VALUE(rocket_component(name, name_len, 'z')));
glUniform3f(location, GET_VALUE(rocket_track_name(ufm, 'x')),
GET_VALUE(rocket_track_name(ufm, 'y')),
GET_VALUE(rocket_track_name(ufm, 'z')));
break;
case UFM_VEC4:
glUniform4f(location,
GET_VALUE(rocket_component(name, name_len, 'x')),
GET_VALUE(rocket_component(name, name_len, 'y')),
GET_VALUE(rocket_component(name, name_len, 'z')),
GET_VALUE(rocket_component(name, name_len, 'w')));
glUniform4f(location, GET_VALUE(rocket_track_name(ufm, 'x')),
GET_VALUE(rocket_track_name(ufm, 'y')),
GET_VALUE(rocket_track_name(ufm, 'z')),
GET_VALUE(rocket_track_name(ufm, 'w')));
break;
case UFM_INT:
glUniform1i(location, (GLint)GET_VALUE(name));
glUniform1i(location, (GLint)GET_VALUE(rocket_track_name(ufm, 0)));
break;
case UFM_UNKNOWN:;
}
Expand Down

0 comments on commit 007e6d2

Please sign in to comment.