mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 12:42:34 +00:00
Added support for rendering multiple lights, standardized shaders to use snake case for variables and camel case for functions, stubbed PBR material shader include.
This commit is contained in:
@@ -5,25 +5,25 @@ layout (location = 1) out vec4 fragColor;
|
||||
layout (location = 2) out vec3 fragNormal;
|
||||
layout (location = 3) out vec3 fragUV;
|
||||
|
||||
in vec3 outPosition, outColor, outNormal, outUV, outFragPos, outCameraPos;
|
||||
in vec3 out_position, out_color, out_normal, out_uv, out_frag_pos, out_camera_pos;
|
||||
out vec4 outputFragColor;
|
||||
flat in int outHasTexture;
|
||||
flat in int out_has_texture;
|
||||
|
||||
uniform sampler2D diffuse_texture;
|
||||
|
||||
void main() {
|
||||
vec3 result;
|
||||
|
||||
if (outHasTexture == 0) {
|
||||
result = outColor;
|
||||
if (out_has_texture == 0) {
|
||||
result = out_color;
|
||||
} else {
|
||||
result = texture(diffuse_texture, outUV.xy).xyz + 0.25;
|
||||
result = texture(diffuse_texture, out_uv.xy).xyz + 0.25;
|
||||
}
|
||||
|
||||
fragPosition = outPosition;
|
||||
fragPosition = out_position;
|
||||
fragColor = vec4(result, 1.0);
|
||||
fragNormal = outNormal;
|
||||
fragUV = outUV;
|
||||
fragNormal = out_normal;
|
||||
fragUV = out_uv;
|
||||
|
||||
float gamma = 2.2;
|
||||
outputFragColor.rgb = pow(fragColor.rgb, vec3(1.0 / gamma));
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
out vec4 frag_color;
|
||||
|
||||
@include "light_struct"
|
||||
const int DIRECTIONAL = 0;
|
||||
const int POINT = 1;
|
||||
const int SPOT = 2;
|
||||
|
||||
in vec2 outTexCoords;
|
||||
flat in Light outLight[1];
|
||||
flat in Light out_lights[7];
|
||||
in vec2 out_tex_coords;
|
||||
flat in int out_light_count;
|
||||
|
||||
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||
|
||||
vec4 directionalLight(Light light) {
|
||||
vec3 norm = normalize(texture(normal, outTexCoords).rgb);
|
||||
vec3 diffuse_color = texture(diffuse, outTexCoords).rgb;
|
||||
vec3 fragPos = texture(position, outTexCoords).rgb;
|
||||
vec3 norm = normalize(texture(normal, out_tex_coords).rgb);
|
||||
vec3 diffuse_color = texture(diffuse, out_tex_coords).rgb;
|
||||
vec3 frag_pos = texture(position, out_tex_coords).rgb;
|
||||
|
||||
vec3 lightDir = normalize(light.position - fragPos);
|
||||
vec3 lightDir = normalize(light.position - frag_pos);
|
||||
float diff = max(dot(norm, lightDir), 0);
|
||||
|
||||
vec3 _ambient = light.ambient;
|
||||
@@ -59,5 +60,10 @@ vec4 calculateLighting(Light light) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
FragColor = texture(diffuse, outTexCoords) * calculateLighting(outLight[0]);
|
||||
}
|
||||
frag_color = vec4(0.0);
|
||||
|
||||
for(int i = 0; i < out_light_count; i++)
|
||||
{
|
||||
frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
|
||||
}
|
||||
}
|
||||
|
||||
16
assets/shaders/include/material_struct.glsl
Normal file
16
assets/shaders/include/material_struct.glsl
Normal file
@@ -0,0 +1,16 @@
|
||||
struct Material {
|
||||
vec3 color;
|
||||
vec3 roughness;
|
||||
vec3 metalic;
|
||||
vec3 specular;
|
||||
|
||||
bool use_color_texture;
|
||||
bool use_roughness_texture;
|
||||
bool use_metalic_texture;
|
||||
bool use_specular_texture;
|
||||
|
||||
sampler2D color_tex;
|
||||
sampler2D roughness_tex;
|
||||
sampler2D metalic_tex;
|
||||
sampler2D specular_tex;
|
||||
};
|
||||
@@ -1,28 +1,28 @@
|
||||
# version 330 core
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
layout(location = 2) in vec3 inNormal;
|
||||
layout(location = 3) in vec3 inUV;
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec3 in_color;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
layout(location = 3) in vec3 in_uv;
|
||||
|
||||
uniform mat4 projection, view, model;
|
||||
uniform int hasTexture;
|
||||
uniform vec3 cameraPos;
|
||||
uniform int has_texture;
|
||||
uniform vec3 camera_pos;
|
||||
|
||||
out vec3 outPosition, outColor, outNormal, outUV;
|
||||
out vec3 outFragPos, outViewPos, outCameraPos;
|
||||
flat out int outHasTexture;
|
||||
out vec3 out_position, out_color, out_normal, out_uv;
|
||||
out vec3 out_frag_pos, out_view_pos, out_camera_pos;
|
||||
flat out int out_has_texture;
|
||||
|
||||
void main() {
|
||||
// projection * view * model * position
|
||||
outPosition = inPosition;
|
||||
outColor = inColor;
|
||||
outNormal= normalize(transpose(inverse(mat3(model))) * inNormal);
|
||||
outUV = inUV;
|
||||
outHasTexture = hasTexture;
|
||||
outCameraPos = cameraPos;
|
||||
out_position = in_position;
|
||||
out_color = in_color;
|
||||
out_normal= normalize(transpose(inverse(mat3(model))) * in_normal);
|
||||
out_uv = in_uv;
|
||||
out_has_texture = has_texture;
|
||||
out_camera_pos = camera_pos;
|
||||
|
||||
outFragPos = vec3(model * vec4(inPosition, 1.0));
|
||||
out_frag_pos = vec3(model * vec4(in_position, 1.0));
|
||||
|
||||
gl_Position = projection * view * model * vec4(inPosition, 1.0);
|
||||
gl_Position = projection * view * model * vec4(in_position, 1.0);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
#version 330 core
|
||||
@include "light_struct"
|
||||
|
||||
layout (location = 0) in vec3 inPosition;
|
||||
layout (location = 1) in vec2 inTexCoords;
|
||||
layout (location = 0) in vec3 in_position;
|
||||
layout (location = 1) in vec2 in_tex_coords;
|
||||
|
||||
uniform sampler2D diffuse, position, texcoord, normal, depth;
|
||||
uniform Light light[1];
|
||||
uniform int light_count;
|
||||
uniform Light lights[7];
|
||||
|
||||
out vec2 outTexCoords;
|
||||
flat out Light outLight[1];
|
||||
out vec2 out_tex_coords;
|
||||
flat out int out_light_count;
|
||||
flat out Light out_lights[7];
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
||||
outTexCoords = inTexCoords;
|
||||
outLight = light;
|
||||
}
|
||||
gl_Position = vec4(in_position.x, in_position.y, in_position.z, 1.0);
|
||||
out_tex_coords = in_tex_coords;
|
||||
out_light_count = light_count;
|
||||
|
||||
for(int i = 0; i < light_count; i++)
|
||||
{
|
||||
out_lights[i] = lights[i];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user