material system? am i bikeshedding?
This commit is contained in:
parent
2a19346038
commit
2b971ecc2a
5 changed files with 49 additions and 2 deletions
6
src/common-shaders/basic.frag
Normal file
6
src/common-shaders/basic.frag
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#version 300 es
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
|
||||||
|
}
|
7
src/common-shaders/basic.ts
Normal file
7
src/common-shaders/basic.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { Shader } from "../renderer/shader";
|
||||||
|
import { WebGLApp } from "../renderer/webgl";
|
||||||
|
import frag from "./basic.frag";
|
||||||
|
import vert from "./basic.vert";
|
||||||
|
|
||||||
|
export const basic = (app: WebGLApp) =>
|
||||||
|
new Shader({}).vertex(vert).fragment(frag).app(app);
|
9
src/common-shaders/basic.vert
Normal file
9
src/common-shaders/basic.vert
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#version 300 es
|
||||||
|
attribute vec4 aVertexPosition;
|
||||||
|
|
||||||
|
uniform mat4 uModelViewMatrix;
|
||||||
|
uniform mat4 uProjectionMatrix;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;
|
||||||
|
}
|
9
src/renderer/material.ts
Normal file
9
src/renderer/material.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { Shader } from "./shader";
|
||||||
|
|
||||||
|
export type MaterialConfig = {
|
||||||
|
shader: Shader;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class Material {
|
||||||
|
constructor(public config: MaterialConfig) {}
|
||||||
|
}
|
|
@ -2,15 +2,31 @@ import { mat4, vec3 } from "gl-matrix";
|
||||||
import { Transform } from "./transform";
|
import { Transform } from "./transform";
|
||||||
import { WebGLApp } from "./webgl";
|
import { WebGLApp } from "./webgl";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uniform/Attribute locations
|
||||||
|
*/
|
||||||
export type ShaderConfig = {
|
export type ShaderConfig = {
|
||||||
time?: boolean;
|
// Engine rendering features
|
||||||
|
model?: 0; // always zero to ensure we render correctly. This is implied.
|
||||||
|
view?: number;
|
||||||
|
projection?: number;
|
||||||
|
world?: number;
|
||||||
|
light0?: number;
|
||||||
|
light0Color?: number;
|
||||||
|
uv0?: number;
|
||||||
|
normals?: number;
|
||||||
|
vertexColor?: number;
|
||||||
|
time?: number;
|
||||||
|
|
||||||
|
// other reasons (like materials)
|
||||||
|
material?: { [key: string]: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Shader {
|
export class Shader {
|
||||||
static VERTEX = 35633;
|
static VERTEX = 35633;
|
||||||
static FRAGMENT = 35632;
|
static FRAGMENT = 35632;
|
||||||
|
|
||||||
constructor(private config: ShaderConfig = {}) {}
|
constructor(private config: ShaderConfig) {}
|
||||||
|
|
||||||
private vertexCode = "";
|
private vertexCode = "";
|
||||||
private fragmentCode = "";
|
private fragmentCode = "";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue