diff options
| author | quou <quou@disroot.org> | 2025-01-01 18:43:31 +1100 | 
|---|---|---|
| committer | quou <quou@disroot.org> | 2025-01-01 18:43:31 +1100 | 
| commit | d26100734623f37063206b9b144c2a29fd71d414 (patch) | |
| tree | 11aefe54b4110109a841cb656b2f309ee69a1893 /intermediate | |
| parent | 568ba73c71b650f905bd1b3f60f10871316eefdc (diff) | |
material system
Diffstat (limited to 'intermediate')
| -rw-r--r-- | intermediate/brick_albedo.bmp | bin | 0 -> 16777354 bytes | |||
| -rw-r--r-- | intermediate/brick_ao.bmp | bin | 0 -> 16777354 bytes | |||
| -rw-r--r-- | intermediate/brick_metal.bmp | bin | 0 -> 16777354 bytes | |||
| -rw-r--r-- | intermediate/brick_normal.bmp | bin | 0 -> 16777354 bytes | |||
| -rw-r--r-- | intermediate/bricks.mat | 11 | ||||
| -rw-r--r-- | intermediate/monkey.glb | bin | 80692 -> 40636 bytes | |||
| -rw-r--r-- | intermediate/plastic.mat | 11 | ||||
| -rw-r--r-- | intermediate/surface.glsl | 83 | 
8 files changed, 97 insertions, 8 deletions
| diff --git a/intermediate/brick_albedo.bmp b/intermediate/brick_albedo.bmpBinary files differ new file mode 100644 index 0000000..54a8a71 --- /dev/null +++ b/intermediate/brick_albedo.bmp diff --git a/intermediate/brick_ao.bmp b/intermediate/brick_ao.bmpBinary files differ new file mode 100644 index 0000000..59ed011 --- /dev/null +++ b/intermediate/brick_ao.bmp diff --git a/intermediate/brick_metal.bmp b/intermediate/brick_metal.bmpBinary files differ new file mode 100644 index 0000000..bafe5f3 --- /dev/null +++ b/intermediate/brick_metal.bmp diff --git a/intermediate/brick_normal.bmp b/intermediate/brick_normal.bmpBinary files differ new file mode 100644 index 0000000..6add824 --- /dev/null +++ b/intermediate/brick_normal.bmp diff --git a/intermediate/bricks.mat b/intermediate/bricks.mat new file mode 100644 index 0000000..28bea24 --- /dev/null +++ b/intermediate/bricks.mat @@ -0,0 +1,11 @@ +[params] +metalness: 1.0 +roughness: 1.0 +ao: 1.0 +albedo: ffffff + +[textures] +albedo: brick_albedo.tex +ao: brick_ao.tex +metal: brick_metal.tex +normal: brick_normal.tex diff --git a/intermediate/monkey.glb b/intermediate/monkey.glbBinary files differ index d199545..3e8fd29 100644 --- a/intermediate/monkey.glb +++ b/intermediate/monkey.glb diff --git a/intermediate/plastic.mat b/intermediate/plastic.mat new file mode 100644 index 0000000..ff71d8b --- /dev/null +++ b/intermediate/plastic.mat @@ -0,0 +1,11 @@ +[params] +metalness: 0.0 +roughness: 0.0 +ao: 1.0 +albedo: ff0000 + +[textures] +#albedo: brick_albedo.tex +#ao: brick_ao.tex +#metal: brick_metal.tex +#normal: brick_normal.tex diff --git a/intermediate/surface.glsl b/intermediate/surface.glsl index 18c13a3..7988502 100644 --- a/intermediate/surface.glsl +++ b/intermediate/surface.glsl @@ -14,6 +14,9 @@ type: vec3  name: normal  type: vec3  [attribute] +name: tangent +type: vec3 +[attribute]  name: uv  type: vec2 @@ -21,8 +24,14 @@ type: vec2  name: uv  type: vec2  [interpolator] +name: position +type: vec4 +[interpolator]  name: normal  type: vec3 +[interpolator] +name: tbn +type: mat3  [struct]  name: MVP @@ -33,11 +42,52 @@ type: mat4  name: view_projection  type: mat4 +[struct] +name: Material +[variable] +name: albedo +type: vec3 +[variable] +name: metalness +type: float +[variable] +name: roughness +type: float +[variable] +name: ao +type: float +  [cbuffer]  name: c_mvp  type: MVP  stage: vertex +[cbuffer] +name: material +type: Material +stage: fragment + +[texture] +name: albedo +stage: fragment +dimension: 2 +[texture] +name: ao +stage: fragment +dimension: 2 +[texture] +name: metal +stage: fragment +dimension: 2 +[texture] +name: rough +stage: fragment +dimension: 2 +[texture] +name: normal +stage: fragment +dimension: 2 +  [target]  name: colour  type: vec4 @@ -47,12 +97,16 @@ type: vec4  #ifdef VERTEX_SHADER  void main() { +	vec4 pos = c_mvp.model * vec4(position, 1.0); +	vec3 t = normalize((c_mvp.model * vec4(tangent, 0.0)).xyz); +	vec3 b = normalize((c_mvp.model * vec4(normal, 0.0)).xyz); +	vec3 n = normalize((c_mvp.model * vec4(cross(normal, tangent), 0.0)).xyz); +	interpolator.normal = n; +	interpolator.tbn = mat3(t, b, n);  	interpolator.uv = uv; -	interpolator.normal = mat3(c_mvp.model) * normal; -	gl_Position = -		c_mvp.view_projection * -		c_mvp.model * -		vec4(position, 1.0); +	interpolator.position = pos; +	interpolator.tbn = mat3(t, b, n); +	gl_Position = c_mvp.view_projection * pos;  }  #endif @@ -60,9 +114,22 @@ void main() {  #ifdef FRAGMENT_SHADER  void main() { -	vec3 normal = normalize(interpolator.normal); -	float light = max(dot(normal, vec3(0, 0, 1)), 0.0); -	colour = vec4(light.xxx, 1.0); +	vec2 uv = interpolator.uv; + +	vec3 nrmsample = texture(normal, uv).rgb; + +	vec2 nrmxy = nrmsample.xy * 2.0 - 1.0; +	vec3 nrm = normalize(vec3(nrmxy, 1.0)); +	if (nrmsample.b == 1.0) /* default texture */ +		nrm = vec3(0, 0, 1); +	nrm = normalize(interpolator.tbn * nrm); + +	float light = max(dot(nrm, vec3(0, 0, 1)), 0.0); + +	vec3 ambient = 0.05.xxx * texture(ao, uv).r; +	vec3 col = light * material.albedo; +	col *= texture(albedo, uv).rgb; +	colour = vec4(col, 1.0);  }  #endif |