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