添加多模型渲染,添加贴图渲染,添加平行光, 暂时不上传assets
This commit is contained in:
@@ -1,9 +1,38 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
const int MAX_LIGHTS = 4;
|
||||
|
||||
struct Light {
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
layout(location = 0) in vec2 fragUV;
|
||||
layout(location = 1) in vec3 fragNormal;
|
||||
layout(location = 2) in vec3 fragWorldPos;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(set = 0, binding = 0) uniform UniformBufferObject {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
vec4 ambientColor;
|
||||
Light lights[MAX_LIGHTS];
|
||||
} ubo;
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler2D texSampler;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
vec3 albedo = texture(texSampler, fragUV).rgb;
|
||||
vec3 N = normalize(fragNormal);
|
||||
|
||||
vec3 result = ubo.ambientColor.rgb * albedo;
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; ++i) {
|
||||
vec3 L = normalize(-ubo.lights[i].direction.xyz);
|
||||
float diff = max(dot(N, L), 0.0);
|
||||
result += ubo.lights[i].color.rgb * ubo.lights[i].color.a * diff * albedo;
|
||||
}
|
||||
|
||||
outColor = vec4(result, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user