Shader fixes
This commit is contained in:
parent
f10fa5ac02
commit
c7e77006a1
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
@ -39,11 +39,12 @@ uniform float envmapStrength;
|
|||
#ifdef _Irr
|
||||
//!uniform vec4 shirr[7];
|
||||
#endif
|
||||
#ifdef _Brdf
|
||||
uniform sampler2D senvmapBrdf;
|
||||
#endif
|
||||
#ifdef _Rad
|
||||
uniform sampler2D senvmapRadiance;
|
||||
uniform sampler2D senvmapBrdf;
|
||||
uniform int envmapNumMipmaps;
|
||||
uniform vec2 cameraProj;
|
||||
#endif
|
||||
#ifdef _EnvCol
|
||||
uniform vec3 backgroundCol;
|
||||
|
@ -53,7 +54,8 @@ uniform float envmapStrength;
|
|||
uniform sampler2D ssaotex;
|
||||
#endif
|
||||
|
||||
#ifdef _Rad
|
||||
#ifdef _IndPos
|
||||
uniform vec2 cameraProj;
|
||||
uniform vec3 eye;
|
||||
uniform vec3 eyeLook;
|
||||
#endif
|
||||
|
@ -62,7 +64,7 @@ uniform float envmapStrength;
|
|||
#endif
|
||||
|
||||
in vec2 texCoord;
|
||||
#ifdef _Rad
|
||||
#ifdef _IndPos
|
||||
in vec3 viewRay;
|
||||
#endif
|
||||
out vec4 fragColor;
|
||||
|
@ -80,15 +82,16 @@ void main() {
|
|||
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb,
|
||||
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
|
||||
|
||||
#ifdef _Rad
|
||||
#ifdef _IndPos
|
||||
#ifdef _InvY // D3D
|
||||
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
#else
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
#endif
|
||||
vec3 p = getPos(eye, eyeLook, viewRay, depth, cameraProj);
|
||||
#endif
|
||||
#ifdef _Brdf
|
||||
vec3 v = normalize(eye - p.xyz);
|
||||
|
||||
float dotNV = max(dot(n, v), 0.0);
|
||||
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
|
||||
vec2 envBRDF = texture(senvmapBrdf, vec2(metrough.y, 1.0 - dotNV)).xy;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{
|
||||
"name": "eye",
|
||||
"link": "_cameraPosition",
|
||||
"ifdef": ["_Rad"]
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "eyeSnap",
|
||||
|
@ -25,11 +25,12 @@
|
|||
{
|
||||
"name": "eyeLook",
|
||||
"link": "_cameraLook",
|
||||
"ifdef": ["_Rad"]
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "invVP",
|
||||
"link": "_inverseViewProjectionMatrix"
|
||||
"link": "_inverseViewProjectionMatrix",
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "shirr",
|
||||
|
@ -49,12 +50,12 @@
|
|||
{
|
||||
"name": "senvmapBrdf",
|
||||
"link": "_envmapBrdf",
|
||||
"ifdef": ["_Rad"]
|
||||
"ifdef": ["_Brdf"]
|
||||
},
|
||||
{
|
||||
"name": "cameraProj",
|
||||
"link": "_cameraPlaneProj",
|
||||
"ifdef": ["_Rad"]
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "envmapStrength",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#version 450
|
||||
|
||||
#ifdef _Rad
|
||||
#ifdef _IndPos
|
||||
uniform mat4 invVP;
|
||||
uniform vec3 eye;
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
|||
in vec2 pos;
|
||||
|
||||
out vec2 texCoord;
|
||||
#ifdef _Rad
|
||||
#ifdef _IndPos
|
||||
out vec3 viewRay;
|
||||
#endif
|
||||
|
||||
|
@ -22,7 +22,7 @@ void main() {
|
|||
|
||||
gl_Position = vec4(pos.xy, 0.0, 1.0);
|
||||
|
||||
#ifdef _Rad
|
||||
#ifdef _IndPos
|
||||
// NDC (at the back of cube)
|
||||
vec4 v = vec4(pos.x, pos.y, 1.0, 1.0);
|
||||
v = vec4(invVP * v);
|
||||
|
|
|
@ -67,8 +67,6 @@ def add_world_defs():
|
|||
# if rpdat.rp_dfgi:
|
||||
# wrd.world_defs += '_DFGI'
|
||||
# assets.add_khafile_def('arm_sdf')
|
||||
# wrd.world_defs += '_Rad' # Always do radiance for gi
|
||||
# wrd.world_defs += '_Irr'
|
||||
if rpdat.rp_ssgi == 'RTGI' or rpdat.rp_ssgi == 'RTAO':
|
||||
if rpdat.rp_ssgi == 'RTGI':
|
||||
wrd.world_defs += '_RTGI'
|
||||
|
@ -87,8 +85,6 @@ def add_world_defs():
|
|||
if rpdat.arm_voxelgi_temporal:
|
||||
assets.add_khafile_def('arm_voxelgi_temporal')
|
||||
wrd.world_defs += '_VoxelGITemporal'
|
||||
wrd.world_defs += '_Rad' # Always do radiance for voxels
|
||||
wrd.world_defs += '_Irr'
|
||||
|
||||
if voxelgi:
|
||||
wrd.world_defs += '_VoxelGI'
|
||||
|
@ -113,6 +109,11 @@ def add_world_defs():
|
|||
assets.add_khafile_def('arm_ltc')
|
||||
break
|
||||
|
||||
if '_Rad' in wrd.world_defs or '_VoxelGI' in wrd.world_defs:
|
||||
wrd.world_defs += '_Brdf'
|
||||
if '_Brdf' in wrd.world_defs or '_VoxelAO' in wrd.world_defs:
|
||||
wrd.world_defs += '_IndPos'
|
||||
|
||||
def build():
|
||||
rpdat = arm.utils.get_rp()
|
||||
if rpdat.rp_driver != 'Armory' and arm.api.drivers[rpdat.rp_driver]['make_rpath'] != None:
|
||||
|
|
|
@ -571,12 +571,13 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
frag.add_uniform('vec2 spotlightData', '_spotlampData') # cutoff, cutoff - exponent
|
||||
frag.add_uniform('float envmapStrength', link='_envmapStrength')
|
||||
|
||||
if '_Brdf' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D senvmapBrdf', link='_envmapBrdf')
|
||||
if '_Irr' in wrd.world_defs:
|
||||
frag.add_include('std/shirr.glsl')
|
||||
frag.add_uniform('vec4 shirr[7]', link='_envmapIrradiance', included=True)
|
||||
if '_Rad' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D senvmapRadiance', link='_envmapRadiance')
|
||||
frag.add_uniform('sampler2D senvmapBrdf', link='_envmapBrdf')
|
||||
frag.add_uniform('int envmapNumMipmaps', link='_envmapNumMipmaps')
|
||||
|
||||
is_shadows = not '_NoShadows' in wrd.world_defs
|
||||
|
@ -688,6 +689,9 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
frag.write('}')
|
||||
frag.tab -= 1
|
||||
|
||||
if '_Brdf' in wrd.world_defs:
|
||||
frag.write('vec2 envBRDF = texture(senvmapBrdf, vec2(roughness, 1.0 - dotNV)).xy;')
|
||||
|
||||
if '_Irr' in wrd.world_defs:
|
||||
frag.write('vec3 indirect = shIrradiance(n);')
|
||||
if '_EnvTex' in wrd.world_defs:
|
||||
|
@ -700,7 +704,6 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
frag.write('vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;')
|
||||
if '_EnvLDR' in wrd.world_defs:
|
||||
frag.write('prefilteredColor = pow(prefilteredColor, vec3(2.2));')
|
||||
frag.write('vec2 envBRDF = texture(senvmapBrdf, vec2(roughness, 1.0 - dotNV)).xy;')
|
||||
frag.write('indirect += prefilteredColor * (f0 * envBRDF.x + envBRDF.y) * 1.5;')
|
||||
else:
|
||||
frag.write('vec3 indirect = albedo;')
|
||||
|
|
Loading…
Reference in a new issue