rendering simplified

This commit is contained in:
John Alanbrook 2023-12-15 18:45:09 +00:00
parent 56c8542797
commit b732d12bed
16 changed files with 86 additions and 271 deletions

View file

@ -2,18 +2,18 @@
Register functions with built-in drawing callbacks to have code execute at particular points in time. Some drawing functions take world coordinates, while others take screen coordinates. Register functions with built-in drawing callbacks to have code execute at particular points in time. Some drawing functions take world coordinates, while others take screen coordinates.
register_gui gui
Called before nk_gui. Screen space. Called before nk_gui. Screen space.
register_nk_gui draw
Called during the Nuklear debug pass. Use Nuklear functions only.
register_draw
Called every frame. World space. Called every frame. World space.
register_debug debug
Called if drawing physics. World space. Called if drawing physics. World space.
gizmo
Called usually for editor purposes. World space.
# Mum # Mum
Mum is the GUI compositing system here. When drawing a mum, the bottom left corner is [0,0]. Change the anchor property of any Mum to change where it is drawn. Mum is the GUI compositing system here. When drawing a mum, the bottom left corner is [0,0]. Change the anchor property of any Mum to change where it is drawn.

View file

@ -642,13 +642,18 @@ component.edge2d = Object.copy(collider2d, {
/* EDITOR */ /* EDITOR */
gizmo() { gizmo() {
this.spoints().forEach(function(x) { if (this.type === Spline.type.catmull) {
Debug.point(world2screen(this.gameobject.this2world(x)), 3, Color.green); this.spoints().forEach(x => Debug.point(this.gameobject.this2world(x), 3, Color.teal));
}, this); this.cpoints.forEach((x,i) => Debug.numbered_point(this.gameobject.this2world(x), i));
} else {
this.cpoints.forEach(function(x, i) { for (var i = 1; i < this.cpoints.length; i+=2) {
Debug.numbered_point(this.gameobject.this2world(x), i); Debug.point(this.gameobject.this2world(this.cpoints[i]), 3, Color.green);
}, this); Debug.line([this.gameobject.this2world(this.cpoints[i-1]), this.gameobject.this2world(this.cpoints[i])], Color.yellow);
}
// for (var i = 0; i < this.cpoints.length; i+=3)
// Debug.numbered_point(this.gameobject.this2world(this.cpoints[
}
}, },
finish_center(change) { finish_center(change) {

View file

@ -7,9 +7,7 @@ var Gizmos = {
}; };
var Shape = { var Shape = {
circle(pos, radius, color) { circle(pos, radius, color) { cmd(115, pos, radius, color); },
cmd(115, pos, radius, color);
},
}; };
var Debug = { var Debug = {
@ -24,7 +22,6 @@ var Debug = {
obj[fn.name] = newfn; obj[fn.name] = newfn;
}, },
draw_grid(width, span, color) { draw_grid(width, span, color) {
color = color ? color : Color.green; color = color ? color : Color.green;
cmd(47, width, span, color); cmd(47, width, span, color);
@ -35,6 +32,8 @@ var Debug = {
Shape.circle(pos, size, color); Shape.circle(pos, size, color);
// cmd(51, pos, size,color); // cmd(51, pos, size,color);
}, },
coordinate(pos, size, color) { GUI.text(JSON.stringify(pos.map(p=>Math.round(p))), pos, size, color); },
arrow(start, end, color, capsize) { arrow(start, end, color, capsize) {
color = color ? color : Color.red; color = color ? color : Color.red;
@ -58,8 +57,8 @@ var Debug = {
}, },
numbered_point(pos, n) { numbered_point(pos, n) {
Debug.point(world2screen(pos), 3); Debug.point(pos, 3);
GUI.text(n, world2screen(pos).add([0,4]), 1); GUI.text(n, pos.add([0,4]), 1);
}, },
phys_drawing: false, phys_drawing: false,
@ -76,12 +75,14 @@ var Debug = {
Register.debug.register(fn,obj); Register.debug.register(fn,obj);
}, },
gameobject(go) {
},
line(points, color, type, thickness) { line(points, color, type, thickness) {
thickness ??= 1; thickness ??= 1;
type ??= 0;
if (!type)
type = 0;
if (!color) if (!color)
color = Color.white; color = Color.white;

View file

@ -215,7 +215,7 @@ var editor = {
Game.pause(); Game.pause();
Player.players[0].control(this); Player.players[0].control(this);
Player.players[0].uncontrol(limited_editor); Player.players[0].uncontrol(limited_editor);
Register.gui.register(editor.ed_gui, editor); Register.gui.register(editor.gui, editor);
Register.draw.register(editor.draw, editor); Register.draw.register(editor.draw, editor);
Debug.register_call(editor.ed_debug, editor); Debug.register_call(editor.ed_debug, editor);
Register.update.register(gui_controls.update, gui_controls); Register.update.register(gui_controls.update, gui_controls);
@ -367,6 +367,13 @@ var editor = {
color_depths: [], color_depths: [],
draw() { draw() {
Debug.point(world2screen(this.cursor), 2, Color.green);
this.selectlist.forEach(x => {
if ('gizmo' in x && typeof x['gizmo'] === 'function' )
x.gizmo();
});
Debug.line(bb2points(cwh2bb([0,0],[Game.native.x,Game.native.y])).wrapped(1), Color.yellow); Debug.line(bb2points(cwh2bb([0,0],[Game.native.x,Game.native.y])).wrapped(1), Color.yellow);
/* Draw selection box */ /* Draw selection box */
@ -384,23 +391,22 @@ var editor = {
Debug.boundingbox(bb, Color.Editor.select.alpha(0.1)); Debug.boundingbox(bb, Color.Editor.select.alpha(0.1));
Debug.line(bb2points(bb).wrapped(1), Color.white); Debug.line(bb2points(bb).wrapped(1), Color.white);
} }
Debug.coordinate([0,0]);
}, },
ed_gui() { gui() {
/* Clean out killed objects */ /* Clean out killed objects */
this.selectlist = this.selectlist.filter(function(x) { return x.alive; }); this.selectlist = this.selectlist.filter(function(x) { return x.alive; });
GUI.text("WORKING LAYER: " + this.working_layer, [0,520]); GUI.text("WORKING LAYER: " + this.working_layer, [0,520]);
GUI.text("MODE: " + this.edit_mode, [0,500]); GUI.text("MODE: " + this.edit_mode, [0,500]);
Debug.point(world2screen(this.cursor), 2, Color.green); if (this.comp_info && this.sel_comp)
if (this.comp_info && this.sel_comp) {
GUI.text(Input.print_pawn_kbm(this.sel_comp,false), [100,700],1); GUI.text(Input.print_pawn_kbm(this.sel_comp,false), [100,700],1);
}
GUI.text("0,0", world2screen([0,0]));
GUI.text(editor.edit_level.worldpos().map(x => Math.round(x)), world2screen(editor.edit_level.worldpos()), 1, Color.red); // GUI.text(editor.edit_level.worldpos().map(x => Math.round(x)), world2screen(editor.edit_level.worldpos()), 1, Color.red);
GUI.text("+", world2screen(editor.edit_level.worldpos()), 1, Color.blue); GUI.text("+", world2screen(editor.edit_level.worldpos()), 1, Color.blue);
var thiso = editor.get_this(); var thiso = editor.get_this();
@ -451,9 +457,6 @@ var editor = {
GUI.text(sname, world2screen(x.worldpos()).add([0, 32]), 1, Color.editor.ur); GUI.text(sname, world2screen(x.worldpos()).add([0, 32]), 1, Color.editor.ur);
GUI.text(x.worldpos().map(function(x) { return Math.round(x); }), world2screen(x.worldpos()), 1, Color.white); GUI.text(x.worldpos().map(function(x) { return Math.round(x); }), world2screen(x.worldpos()), 1, Color.white);
// Debug.arrow(world2screen(x.worldpos()), world2screen(x.worldpos().add(x.up().scale(40))), Color.yellow, 1); // Debug.arrow(world2screen(x.worldpos()), world2screen(x.worldpos().add(x.up().scale(40))), Color.yellow, 1);
if ('gizmo' in x && typeof x['gizmo'] === 'function' )
x.gizmo();
}); });
Object.entries(thiso.objects).forEach(function(x) { Object.entries(thiso.objects).forEach(function(x) {
@ -1202,7 +1205,7 @@ editor.inputs.down = function() { this.key_move([0,-1]); };
editor.inputs.down.rep = true; editor.inputs.down.rep = true;
editor.inputs.tab = function() { editor.inputs.tab = function() {
if (!this.selectlist.length === 1) return; if (!(this.selectlist.length === 1)) return;
if (!this.selectlist[0].components) return; if (!this.selectlist[0].components) return;
var sel = this.selectlist[0].components; var sel = this.selectlist[0].components;

View file

@ -2,7 +2,6 @@
#include "log.h" #include "log.h"
#include "resources.h" #include "resources.h"
#include "shader.h"
#include "stb_ds.h" #include "stb_ds.h"
#include "font.h" #include "font.h"
#include "window.h" #include "window.h"

View file

@ -7,7 +7,6 @@
#include "gameobject.h" #include "gameobject.h"
extern HMM_Vec3 eye; extern HMM_Vec3 eye;
struct shader;
typedef struct material { typedef struct material {
@ -52,9 +51,6 @@ void loadmodel(struct model *model);
void model_init(); void model_init();
void draw_model(struct model *model, HMM_Mat4 amodel);
void draw_models(struct model *model, struct shader *shader);
struct drawmodel *make_drawmodel(gameobject *go); struct drawmodel *make_drawmodel(gameobject *go);
void draw_drawmodel(struct drawmodel *dm); void draw_drawmodel(struct drawmodel *dm);
void free_drawmodel(struct drawmodel *dm); void free_drawmodel(struct drawmodel *dm);

View file

@ -1,126 +0,0 @@
#include "skybox.h"
#include "shader.h"
#include <stdlib.h>
#include <string.h>
#include "render.h"
static const float skyboxVertices[216] = {
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f};
struct mSkybox *MakeSkybox(const char *cubemap) {
/*
struct mSkybox *newskybox = malloc(sizeof(struct mSkybox));
newskybox->shader = MakeShader("skyvert.glsl", "skyfrag.glsl");
shader_compile(newskybox->shader);
glGenVertexArrays(1, &newskybox->VAO);
glGenBuffers(1, &newskybox->VBO);
glBindVertexArray(newskybox->VAO);
glBindBuffer(GL_ARRAY_BUFFER, newskybox->VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float),
(void *) 0);
shader_use(newskybox->shader);
shader_setint(newskybox->shader, "skybox", 0);
*/
/*
const char *faces[6] =
{ "right.jpg", "left.jpg", "top.jpg", "bottom.jpg", "front.jpg",
"back.jpg"
};
*/
/*
glGenTextures(1, &newskybox->id);
glBindTexture(GL_TEXTURE_CUBE_MAP, newskybox->id);
*/
/*char buf[100] = { '\0' };*/
for (int i = 0; i < 6; i++) {
/*
buf[0] = '\0';
strcat(buf, cubemap);
strcat(buf, "/");
strcat(buf, faces[i]);
IMG_Load(buf);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 2048,
2048, 0, GL_RGB, GL_UNSIGNED_BYTE, data->pixels);
*/
}
/*
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R,
GL_CLAMP_TO_EDGE);
return newskybox;
*/
return NULL;
}
void skybox_draw(const struct mSkybox *skybox,
const struct mCamera *camera) {
/*
shader_use(skybox->shader);
mfloat_t view[16] = { 0.f };
getviewmatrix(view, camera);
shader_setmat4(skybox->shader, "skyview", view);
// skybox cube
glBindVertexArray(skybox->VAO);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox->id);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
*/
}

View file

@ -1,17 +0,0 @@
#ifndef SKYBOX_H
#define SKYBOX_H
struct mCamera;
struct mSkybox {
unsigned int VAO;
unsigned int VBO;
unsigned int id;
struct shader *shader;
};
struct mSkybox *MakeSkybox(const char *cubemap);
void skybox_draw(const struct mSkybox *skybox,
const struct mCamera *camera);
#endif

View file

@ -6,7 +6,6 @@
#include "limits.h" #include "limits.h"
#include "log.h" #include "log.h"
#include "resources.h" #include "resources.h"
#include "shader.h"
#include "sound.h" #include "sound.h"
#include "texture.h" #include "texture.h"
#include <stdbool.h> #include <stdbool.h>

View file

@ -2,7 +2,6 @@
#include "render.h" #include "render.h"
#include "yugine.h" #include "yugine.h"
#include "shader.h"
#include "log.h" #include "log.h"
#include <assert.h> #include <assert.h>
#include "debug.h" #include "debug.h"
@ -24,6 +23,37 @@
#define v_amt 5000 #define v_amt 5000
struct flush {
sg_shader shader;
sg_pipeline pipe;
sg_bindings bind;
void *verts;
int c;
int v;
int sc;
int sv;
};
typedef struct flush flush;
static flush fpoint;
static flush circle;
void flushview(flush *f, HMM_Mat4 *view)
{
sg_apply_pipeline(f->pipe);
sg_apply_bindings(&f->bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(*view));
sg_draw(f->sc, f->c, 1);
}
void flushpass(flush *f)
{
f->sc = f->c;
f->c = 0;
f->sv = f->v;
f->v = 0;
}
static sg_shader point_shader; static sg_shader point_shader;
static sg_pipeline point_pipe; static sg_pipeline point_pipe;
static sg_bindings point_bind; static sg_bindings point_bind;

View file

@ -4,7 +4,6 @@
#include "render.h" #include "render.h"
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include <shader.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View file

@ -6,7 +6,6 @@
#include "font.h" #include "font.h"
#include "gameobject.h" #include "gameobject.h"
#include "log.h" #include "log.h"
#include "shader.h"
#include "sprite.h" #include "sprite.h"
#include "window.h" #include "window.h"
#include "model.h" #include "model.h"
@ -528,7 +527,6 @@ void full_2d_pass(struct window *window)
////// TEXT && GUI ////// TEXT && GUI
debug_nextpass(); debug_nextpass();
call_gui(); call_gui();
debug_flush(&hudproj); debug_flush(&hudproj);
text_flush(&hudproj); text_flush(&hudproj);

View file

@ -1,54 +0,0 @@
#include "shader.h"
#include "config.h"
#include "font.h"
#include "log.h"
#include "render.h"
#include "resources.h"
#include "stb_ds.h"
#include "timer.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "time.h"
#define SHADER_BUF 10000
static struct shader *shaders;
struct shader *MakeShader(const char *vertpath, const char *fragpath) {
if (arrcap(shaders) == 0)
arrsetcap(shaders, 20);
struct shader init = {
.vertpath = vertpath,
.fragpath = fragpath};
shader_compile(&init);
arrput(shaders, init);
return &arrlast(shaders);
}
void shader_compile(struct shader *shader) {
YughInfo("Making shader with %s and %s.", shader->vertpath, shader->fragpath);
char spath[MAXPATH];
sprintf(spath, "%s%s", "shaders/", shader->vertpath);
const char *vsrc = slurp_text(spath, NULL);
sprintf(spath, "%s%s", "shaders/", shader->fragpath);
const char *fsrc = slurp_text(spath, NULL);
shader->shd = sg_make_shader(&(sg_shader_desc){
.vs.source = vsrc,
.fs.source = fsrc,
.label = shader->vertpath,
});
free(vsrc);
free(fsrc);
}
void shader_compile_all() {
for (int i = 0; i < arrlen(shaders); i++)
shader_compile(&shaders[i]);
}

View file

@ -1,15 +0,0 @@
#ifndef SHADER_H
#define SHADER_H
#include "sokol/sokol_gfx.h"
struct shader {
sg_shader shd;
const char *vertpath;
const char *fragpath;
};
void shader_compile_all();
struct shader *MakeShader(const char *vertpath, const char *fragpath);
void shader_compile(struct shader *shader);
#endif

View file

@ -5,7 +5,6 @@
#include "gameobject.h" #include "gameobject.h"
#include "log.h" #include "log.h"
#include "render.h" #include "render.h"
#include "shader.h"
#include "stb_ds.h" #include "stb_ds.h"
#include "texture.h" #include "texture.h"
#include "timer.h" #include "timer.h"

View file

@ -39,26 +39,24 @@ in float radius;
void main() void main()
{ {
if (segsize<0)
return;
float f = atan(coords.y, coords.x) + PI;
if (mod(f, segsize) < segsize/2)
discard;
float px = 1/radius; float px = 1/radius;
float R1 = 1.f; float R1 = 1.f;
float R2 = 1.0 - fill; float R2 = 1.0 - fill;
float dist = sqrt(pow(coords.x,2) + pow(coords.y,2)); float dist = sqrt(pow(coords.x,2) + pow(coords.y,2));
color = fcolor; color = fcolor;
// if (dist < R2 || dist > R1)
// discard;
float sm = 1 - smoothstep(R1-px,R1,dist); float sm = 1 - smoothstep(R1-px,R1,dist);
float sm2 = smoothstep(R2-px,R2,dist); float sm2 = smoothstep(R2-px,R2,dist);
float a = sm*sm2; float a = sm*sm2;
color = mix(vec4(0,0,0,0), fcolor, a); color = mix(vec4(0,0,0,0), fcolor, a);
if (segsize<0)
return;
float f = atan(coords.y, coords.x) + PI;
if (mod(f, segsize) < segsize/2)
discard;
} }
@end @end