Minor changes
Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#ifndef EV_GLSL_PBR_H
|
||||
#define EV_GLSL_PBR_H
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float a)
|
||||
{
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N,H),0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float num = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return num/denom;
|
||||
}
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float k)
|
||||
{
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float k)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx1 = GeometrySchlickGGX(NdotV, k);
|
||||
float ggx2 = GeometrySchlickGGX(NdotL, k);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef EV_GLSL_MACROS_H
|
||||
#define EV_GLSL_MACROS_H
|
||||
|
||||
#define __EV_CAT_IMPL(a,...) a##__VA_ARGS__
|
||||
#define EV_CAT(a,...) __EV_CAT_IMPL(a, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
+28
-54
@@ -1,9 +1,10 @@
|
||||
#version 450
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
|
||||
#include <shaders://_builtins/types.glsl>
|
||||
#include <shaders://_builtins/constants.glsl>
|
||||
#include <shaders://_builtins/srgb_ops.glsl>
|
||||
#include "shaders://_builtins/types.glsl"
|
||||
#include "shaders://_builtins/constants.glsl"
|
||||
#include "shaders://_builtins/srgb_ops.glsl"
|
||||
#include "shaders://_builtins/PBR.glsl"
|
||||
|
||||
struct Light {
|
||||
vec3 color;
|
||||
@@ -46,67 +47,41 @@ layout(location = 4) smooth in mat3 TBN;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float a)
|
||||
vec4 GetAlbedo(Material material, vec2 uv)
|
||||
{
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N,H),0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float num = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return num/denom;
|
||||
vec4 albedo;
|
||||
if(material.albedoTexture == 0) {
|
||||
albedo = material.baseColor;
|
||||
} else {
|
||||
albedo = texture(texSampler[material.albedoTexture], uv);
|
||||
}
|
||||
return albedo;
|
||||
}
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float k)
|
||||
vec3 GetNormal(Material material, vec2 uv, mat3 TBN)
|
||||
{
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float k)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx1 = GeometrySchlickGGX(NdotV, k);
|
||||
float ggx2 = GeometrySchlickGGX(NdotL, k);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
vec3 normal;
|
||||
if(material.normalTexture == 0) {
|
||||
normal = TBN[2].xyz;
|
||||
} else {
|
||||
vec3 sampled_normal = LinearToSRGB(texture(texSampler[material.normalTexture], uv)).rgb;
|
||||
sampled_normal = 2.0 * sampled_normal - vec3(1.0);
|
||||
normal = normalize(TBN * sampled_normal);
|
||||
}
|
||||
return normal;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ];
|
||||
|
||||
vec3 albedo;
|
||||
float alpha;
|
||||
if(material.albedoTexture == 0) {
|
||||
albedo = material.baseColor.xyz;
|
||||
} else {
|
||||
vec4 sampledColor = texture(texSampler[material.albedoTexture], uv);
|
||||
if(sampledColor.a < 0.5) {
|
||||
discard;
|
||||
}
|
||||
albedo = sampledColor.rgb;
|
||||
alpha = sampledColor.a;
|
||||
vec4 albedo4 = GetAlbedo(material, uv);
|
||||
if(albedo4.a < 0.5) {
|
||||
// discard;
|
||||
}
|
||||
vec3 albedo = albedo4.rgb;
|
||||
|
||||
vec3 out_normal;
|
||||
if(material.normalTexture == 0) {
|
||||
out_normal = TBN[2].xyz;
|
||||
} else {
|
||||
vec3 sampled_normal = LinearToSRGB(texture(texSampler[material.normalTexture], uv)).rgb;
|
||||
sampled_normal = 2.0 * sampled_normal - vec3(1.0);
|
||||
out_normal = normalize(TBN * sampled_normal);
|
||||
}
|
||||
vec3 N = GetNormal(material, uv, TBN);
|
||||
|
||||
float metallicFactor;
|
||||
float roughnessFactor;
|
||||
@@ -134,7 +109,6 @@ void main()
|
||||
vec3 V = normalize(cameraPos - position);
|
||||
vec3 L = normalize(pointLightPos - position);
|
||||
vec3 H = normalize(V + L);
|
||||
vec3 N = out_normal;
|
||||
float distance = length(pointLightPos - position);
|
||||
float attenuation = 1.0 / (distance * distance);
|
||||
vec3 radiance = pointLightColor * attenuation * lightIntensity;
|
||||
@@ -163,5 +137,5 @@ void main()
|
||||
color += emissiveness;
|
||||
color = color / (color + vec3(1.0));
|
||||
|
||||
outColor = vec4(color, alpha);
|
||||
outColor = vec4(color, 1.0);
|
||||
}
|
||||
|
||||
+5
-23
@@ -3,17 +3,8 @@
|
||||
"materials": [
|
||||
{
|
||||
"albedoTexture": "assets://textures/BoomBox_baseColor.tx",
|
||||
"baseColor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 1, 1, 1, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"emissiveTexture": "assets://textures/BoomBox_emissive.tx",
|
||||
"id": "BoomBox_Mat",
|
||||
"metallicFactor": 1,
|
||||
@@ -23,18 +14,9 @@
|
||||
"roughnessFactor": 1
|
||||
},
|
||||
{
|
||||
"baseColor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"id": "_Material_Dummy_1",
|
||||
"baseColor": [ 1, 1, 1, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"id": "Boombox_Material_Dummy_1",
|
||||
"metallicFactor": 1,
|
||||
"pipeline": "DefaultPipeline",
|
||||
"roughnessFactor": 1
|
||||
|
||||
+10
-55
@@ -3,17 +3,8 @@
|
||||
"materials": [
|
||||
{
|
||||
"albedoTexture": "assets://textures/CesiumMilkTruck.tx",
|
||||
"baseColor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 1, 1, 1, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"id": "wheels",
|
||||
"metallicFactor": 0,
|
||||
"pipeline": "DefaultPipeline",
|
||||
@@ -21,68 +12,32 @@
|
||||
},
|
||||
{
|
||||
"albedoTexture": "assets://textures/CesiumMilkTruck.tx",
|
||||
"baseColor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 1, 1, 1, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"id": "truck",
|
||||
"metallicFactor": 0,
|
||||
"pipeline": "DefaultPipeline",
|
||||
"roughnessFactor": 1
|
||||
},
|
||||
{
|
||||
"baseColor": [
|
||||
0,
|
||||
0.04050629958510399,
|
||||
0.021240700036287308,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 0, 0.04050629958510399, 0.021240700036287308, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"id": "glass",
|
||||
"metallicFactor": 0,
|
||||
"pipeline": "DefaultPipeline",
|
||||
"roughnessFactor": 1
|
||||
},
|
||||
{
|
||||
"baseColor": [
|
||||
0.06400000303983688,
|
||||
0.06400000303983688,
|
||||
0.06400000303983688,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 0.06400000303983688, 0.06400000303983688, 0.06400000303983688, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"id": "window_trim",
|
||||
"metallicFactor": 0,
|
||||
"pipeline": "DefaultPipeline",
|
||||
"roughnessFactor": 1
|
||||
},
|
||||
{
|
||||
"baseColor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 1, 1, 1, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"id": "Scene_Material_Dummy_4",
|
||||
"metallicFactor": 1,
|
||||
"pipeline": "DefaultPipeline",
|
||||
|
||||
@@ -3,17 +3,8 @@
|
||||
"materials": [
|
||||
{
|
||||
"albedoTexture": "assets://textures/Default_albedo.tx",
|
||||
"baseColor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 1, 1, 1, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"emissiveTexture": "assets://textures/Default_emissive.tx",
|
||||
"id": "Material_MR",
|
||||
"metallicFactor": 1,
|
||||
@@ -23,17 +14,8 @@
|
||||
"roughnessFactor": 1
|
||||
},
|
||||
{
|
||||
"baseColor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"emissiveFactor": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"baseColor": [ 1, 1, 1, 1 ],
|
||||
"emissiveFactor": [ 1, 1, 1 ],
|
||||
"id": "Scene_Material_Dummy_1",
|
||||
"metallicFactor": 1,
|
||||
"pipeline": "DefaultPipeline",
|
||||
|
||||
+138
-174
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user