Merge clustered rendeder - wip, unstable
This commit is contained in:
parent
ac38825cef
commit
850dade8a5
|
@ -1,200 +0,0 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.inc"
|
||||
#include "std/gbuffer.glsl"
|
||||
#include "std/math.glsl"
|
||||
#include "std/brdf.glsl"
|
||||
#ifdef _Irr
|
||||
#include "std/shirr.glsl"
|
||||
#endif
|
||||
#ifdef _VoxelGI
|
||||
#include "std/conetrace.glsl"
|
||||
#endif
|
||||
#ifdef _VoxelAOvar
|
||||
#include "std/conetrace.glsl"
|
||||
#endif
|
||||
|
||||
// uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbuffer0;
|
||||
uniform sampler2D gbuffer1;
|
||||
|
||||
#ifdef _VoxelGI
|
||||
uniform sampler3D voxels;
|
||||
#endif
|
||||
#ifdef _VoxelAOvar
|
||||
uniform sampler3D voxels;
|
||||
#endif
|
||||
#ifdef _VoxelGITemporal
|
||||
uniform sampler3D voxelsLast;
|
||||
uniform float voxelBlend;
|
||||
#endif
|
||||
#ifdef _VoxelGICam
|
||||
uniform vec3 eyeSnap;
|
||||
#endif
|
||||
|
||||
uniform float envmapStrength;
|
||||
#ifdef _Irr
|
||||
//!uniform vec4 shirr[7];
|
||||
#endif
|
||||
#ifdef _Brdf
|
||||
uniform sampler2D senvmapBrdf;
|
||||
#endif
|
||||
#ifdef _Rad
|
||||
uniform sampler2D senvmapRadiance;
|
||||
uniform int envmapNumMipmaps;
|
||||
#endif
|
||||
#ifdef _EnvCol
|
||||
uniform vec3 backgroundCol;
|
||||
#endif
|
||||
|
||||
#ifdef _SSAO
|
||||
uniform sampler2D ssaotex;
|
||||
#endif
|
||||
|
||||
#ifdef _IndPos
|
||||
uniform vec2 cameraProj;
|
||||
uniform vec3 eye;
|
||||
uniform vec3 eyeLook;
|
||||
#endif
|
||||
|
||||
in vec2 texCoord;
|
||||
#ifdef _IndPos
|
||||
in vec3 viewRay;
|
||||
#endif
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
|
||||
|
||||
vec3 n;
|
||||
n.z = 1.0 - abs(g0.x) - abs(g0.y);
|
||||
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
|
||||
n = normalize(n);
|
||||
|
||||
vec2 metrough = unpackFloat(g0.b);
|
||||
|
||||
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
|
||||
vec2 occspec = unpackFloat2(g1.a);
|
||||
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
|
||||
|
||||
#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;
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGI
|
||||
#ifdef _VoxelGICam
|
||||
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
#else
|
||||
vec3 voxpos = p / voxelgiHalfExtents;
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGITemporal
|
||||
vec4 indirectDiffuse = traceDiffuse(voxpos, n, voxels) * voxelBlend + traceDiffuse(voxpos, n, voxelsLast) * (1.0 - voxelBlend);
|
||||
#else
|
||||
vec4 indirectDiffuse = traceDiffuse(voxpos, n, voxels);
|
||||
#endif
|
||||
|
||||
fragColor.rgb = indirectDiffuse.rgb * voxelgiDiff * g1.rgb;
|
||||
|
||||
if (occspec.y > 0.0) {
|
||||
vec3 indirectSpecular = traceSpecular(voxels, voxpos, n, v, metrough.y);
|
||||
indirectSpecular *= f0 * envBRDF.x + envBRDF.y;
|
||||
fragColor.rgb += indirectSpecular * voxelgiSpec * occspec.y;
|
||||
}
|
||||
|
||||
// if (!isInsideCube(voxpos)) fragColor = vec4(1.0); // Show bounds
|
||||
#endif
|
||||
|
||||
// Envmap
|
||||
#ifdef _Irr
|
||||
vec3 envl = shIrradiance(n);
|
||||
#ifdef _EnvTex
|
||||
envl /= PI;
|
||||
#endif
|
||||
#else
|
||||
vec3 envl = vec3(1.0);
|
||||
#endif
|
||||
|
||||
#ifdef _Rad
|
||||
vec3 reflectionWorld = reflect(-v, n);
|
||||
float lod = getMipFromRoughness(metrough.y, envmapNumMipmaps);
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef _EnvLDR
|
||||
envl.rgb = pow(envl.rgb, vec3(2.2));
|
||||
#ifdef _Rad
|
||||
prefilteredColor = pow(prefilteredColor, vec3(2.2));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
envl.rgb *= albedo;
|
||||
|
||||
#ifdef _Rad // Indirect specular
|
||||
envl.rgb += prefilteredColor * (f0 * envBRDF.x + envBRDF.y) * 1.5 * occspec.y;
|
||||
#else
|
||||
#ifdef _EnvCol
|
||||
envl.rgb += backgroundCol * surfaceF0(g1.rgb, metrough.x); // f0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _SSS
|
||||
envl.rgb *= envmapStrength * occspec.x;
|
||||
#else
|
||||
envl.rgb *= envmapStrength * occspec.x; // Occlusion
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelAOvar
|
||||
|
||||
#ifdef _VoxelGICam
|
||||
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
#else
|
||||
vec3 voxpos = p / voxelgiHalfExtents;
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGITemporal
|
||||
envl.rgb *= 1.0 - (traceAO(voxpos, n, voxels) * voxelBlend + traceAO(voxpos, n, voxelsLast) * (1.0 - voxelBlend));
|
||||
#else
|
||||
envl.rgb *= 1.0 - traceAO(voxpos, n, voxels);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGI
|
||||
fragColor.rgb += envl * voxelgiEnv;
|
||||
#else
|
||||
fragColor.rgb = envl;
|
||||
#endif
|
||||
|
||||
#ifdef _SSAO
|
||||
#ifdef _RTGI
|
||||
fragColor.rgb *= texture(ssaotex, texCoord).rgb;
|
||||
#else
|
||||
fragColor.rgb *= texture(ssaotex, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Show voxels
|
||||
// vec3 origin = vec3(texCoord * 2.0 - 1.0, 0.99);
|
||||
// vec3 direction = vec3(0.0, 0.0, -1.0);
|
||||
// vec4 color = vec4(0.0f);
|
||||
// for(uint step = 0; step < 400 && color.a < 0.99f; ++step) {
|
||||
// vec3 point = origin + 0.005 * step * direction;
|
||||
// color += (1.0f - color.a) * textureLod(voxels, point * 0.5 + 0.5, 0);
|
||||
// }
|
||||
// fragColor.rgb += color.rgb;
|
||||
|
||||
// Show SSAO
|
||||
// fragColor.rgb = texture(ssaotex, texCoord).rrr;
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
{
|
||||
"variants": ["_VoxelAOvar"],
|
||||
"contexts": [
|
||||
{
|
||||
"name": "deferred_indirect",
|
||||
"depth_write": false,
|
||||
"color_write_alpha": false,
|
||||
"compare_mode": "always",
|
||||
"cull_mode": "none",
|
||||
"links": [
|
||||
{
|
||||
"name": "eye",
|
||||
"link": "_cameraPosition",
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "eyeSnap",
|
||||
"link": "_cameraPositionSnap",
|
||||
"ifdef": ["_VoxelGICam"]
|
||||
},
|
||||
{
|
||||
"name": "voxelBlend",
|
||||
"link": "_voxelBlend",
|
||||
"ifdef": ["_VoxelGITemporal"]
|
||||
},
|
||||
{
|
||||
"name": "eyeLook",
|
||||
"link": "_cameraLook",
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "invVP",
|
||||
"link": "_inverseViewProjectionMatrix",
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "shirr",
|
||||
"link": "_envmapIrradiance",
|
||||
"ifdef": ["_Irr"]
|
||||
},
|
||||
{
|
||||
"name": "senvmapRadiance",
|
||||
"link": "_envmapRadiance",
|
||||
"ifdef": ["_Rad"]
|
||||
},
|
||||
{
|
||||
"name": "envmapNumMipmaps",
|
||||
"link": "_envmapNumMipmaps",
|
||||
"ifdef": ["_Rad"]
|
||||
},
|
||||
{
|
||||
"name": "senvmapBrdf",
|
||||
"link": "_envmapBrdf",
|
||||
"ifdef": ["_Brdf"]
|
||||
},
|
||||
{
|
||||
"name": "cameraProj",
|
||||
"link": "_cameraPlaneProj",
|
||||
"ifdef": ["_IndPos"]
|
||||
},
|
||||
{
|
||||
"name": "envmapStrength",
|
||||
"link": "_envmapStrength"
|
||||
},
|
||||
{
|
||||
"name": "backgroundCol",
|
||||
"link": "_backgroundCol",
|
||||
"ifdef": ["_EnvCol"]
|
||||
}
|
||||
],
|
||||
"vertex_shader": "deferred_indirect.vert.glsl",
|
||||
"fragment_shader": "deferred_indirect.frag.glsl"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,19 +1,23 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.inc"
|
||||
#include "std/brdf.glsl"
|
||||
#include "std/gbuffer.glsl"
|
||||
#include "std/math.glsl"
|
||||
#ifdef _LightIES
|
||||
#include "std/ies.glsl"
|
||||
#include "std/brdf.glsl"
|
||||
#ifdef _Clusters
|
||||
#include "std/clusters.glsl"
|
||||
#endif
|
||||
#ifdef _VoxelGIDirect
|
||||
#include "std/conetrace.glsl"
|
||||
#ifdef _ShadowMap
|
||||
#include "std/shadows.glsl"
|
||||
#endif
|
||||
#ifdef _LTC
|
||||
#include "std/ltc.glsl"
|
||||
#ifdef _Irr
|
||||
#include "std/shirr.glsl"
|
||||
#endif
|
||||
#ifndef _NoShadows
|
||||
#include "std/shadows.glsl"
|
||||
#ifdef _VoxelGI
|
||||
#include "std/conetrace.glsl"
|
||||
#endif
|
||||
#ifdef _VoxelAOvar
|
||||
#include "std/conetrace.glsl"
|
||||
#endif
|
||||
#ifdef _SSS
|
||||
#include "std/sss.glsl"
|
||||
|
@ -21,198 +25,330 @@
|
|||
#ifdef _SSRS
|
||||
#include "std/ssrs.glsl"
|
||||
#endif
|
||||
#include "std/gbuffer.glsl"
|
||||
|
||||
#ifdef _VoxelGIDirect
|
||||
uniform sampler3D voxels;
|
||||
#ifdef _LightIES
|
||||
#include "std/ies.glsl"
|
||||
#endif
|
||||
#ifdef _VoxelGICam
|
||||
uniform vec3 eyeSnap;
|
||||
#ifdef _LTC
|
||||
#include "std/ltc.glsl"
|
||||
#endif
|
||||
|
||||
// uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbuffer0;
|
||||
uniform sampler2D gbuffer1;
|
||||
#ifdef _gbuffer2direct
|
||||
uniform sampler2D gbuffer2;
|
||||
|
||||
#ifdef _VoxelGI
|
||||
uniform sampler3D voxels;
|
||||
#endif
|
||||
#ifdef _VoxelAOvar
|
||||
uniform sampler3D voxels;
|
||||
#endif
|
||||
#ifdef _VoxelGITemporal
|
||||
uniform sampler3D voxelsLast;
|
||||
uniform float voxelBlend;
|
||||
#endif
|
||||
#ifdef _VoxelGICam
|
||||
uniform vec3 eyeSnap;
|
||||
#endif
|
||||
|
||||
// TODO: separate shaders
|
||||
#ifndef _NoShadows
|
||||
#ifdef _SoftShadows
|
||||
uniform sampler2D svisibility;
|
||||
#else
|
||||
uniform sampler2D shadowMap;
|
||||
uniform samplerCube shadowMapCube;
|
||||
#endif
|
||||
uniform float envmapStrength;
|
||||
#ifdef _Irr
|
||||
//!uniform vec4 shirr[7];
|
||||
#endif
|
||||
#ifdef _Brdf
|
||||
uniform sampler2D senvmapBrdf;
|
||||
#endif
|
||||
#ifdef _Rad
|
||||
uniform sampler2D senvmapRadiance;
|
||||
uniform int envmapNumMipmaps;
|
||||
#endif
|
||||
#ifdef _EnvCol
|
||||
uniform vec3 backgroundCol;
|
||||
#endif
|
||||
|
||||
#ifdef _SSAO
|
||||
uniform sampler2D ssaotex;
|
||||
#endif
|
||||
|
||||
#ifdef _SSS
|
||||
uniform vec2 lightPlane;
|
||||
#endif
|
||||
|
||||
#ifdef _SSRS
|
||||
//!uniform mat4 VP;
|
||||
uniform mat4 invVP;
|
||||
#endif
|
||||
|
||||
#ifdef _LightIES
|
||||
//!uniform sampler2D texIES;
|
||||
//!uniform sampler2D texIES;
|
||||
#endif
|
||||
|
||||
#ifdef _SMSizeUniform
|
||||
uniform vec2 smSizeUniform;
|
||||
#endif
|
||||
|
||||
#ifdef _SSS
|
||||
vec2 lightPlane;
|
||||
#endif
|
||||
|
||||
uniform mat4 invVP;
|
||||
uniform mat4 LWVP;
|
||||
uniform vec3 lightColor;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec2 lightProj;
|
||||
uniform int lightType;
|
||||
uniform int lightShadow;
|
||||
uniform float shadowsBias;
|
||||
uniform vec2 spotlightData;
|
||||
#ifdef _LTC
|
||||
uniform vec3 lightArea0;
|
||||
uniform vec3 lightArea1;
|
||||
uniform vec3 lightArea2;
|
||||
uniform vec3 lightArea3;
|
||||
uniform sampler2D sltcMat;
|
||||
uniform sampler2D sltcMag;
|
||||
#endif
|
||||
uniform vec3 eye;
|
||||
#ifdef _SSRS
|
||||
//!uniform mat4 VP;
|
||||
uniform vec3 lightArea0;
|
||||
uniform vec3 lightArea1;
|
||||
uniform vec3 lightArea2;
|
||||
uniform vec3 lightArea3;
|
||||
uniform sampler2D sltcMat;
|
||||
uniform sampler2D sltcMag;
|
||||
#endif
|
||||
|
||||
in vec4 wvpposition;
|
||||
uniform vec2 cameraProj;
|
||||
uniform vec3 eye;
|
||||
uniform vec3 eyeLook;
|
||||
|
||||
#ifdef _Clusters
|
||||
uniform vec4 lightsArray[maxLights * 2];
|
||||
#ifdef _Spot
|
||||
uniform vec4 lightsArraySpot[maxLights];
|
||||
#endif
|
||||
uniform sampler2D clustersData;
|
||||
uniform vec2 cameraPlane;
|
||||
const float clusterNear = 3.0;
|
||||
const vec3 clusterSlices = vec3(16, 16, 16);
|
||||
#ifdef _ShadowMap
|
||||
#ifdef _ShadowMapCube
|
||||
uniform vec2 lightProj;
|
||||
uniform samplerCube shadowMap0;
|
||||
// uniform samplerCube shadowMap1;
|
||||
// uniform samplerCube shadowMap2;
|
||||
// uniform samplerCube shadowMap3;
|
||||
#else
|
||||
uniform sampler2D shadowMap0;
|
||||
// uniform sampler2D shadowMap1;
|
||||
// uniform sampler2D shadowMap2;
|
||||
// uniform sampler2D shadowMap3;
|
||||
uniform mat4 LWVP0;
|
||||
// uniform mat4 LWVP1;
|
||||
// uniform mat4 LWVP2;
|
||||
// uniform mat4 LWVP3;
|
||||
#endif
|
||||
#ifdef _Spot
|
||||
uniform sampler2D shadowMapSpot0;
|
||||
// uniform sampler2D shadowMapSpot1;
|
||||
// uniform sampler2D shadowMapSpot2;
|
||||
// uniform sampler2D shadowMapSpot3;
|
||||
uniform mat4 LWVPSpot0;
|
||||
// uniform mat4 LWVPSpot1;
|
||||
// uniform mat4 LWVPSpot2;
|
||||
// uniform mat4 LWVPSpot3;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _Sun
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunCol;
|
||||
#ifdef _ShadowMap
|
||||
uniform sampler2D shadowMap;
|
||||
uniform float shadowsBias;
|
||||
#ifdef _CSM
|
||||
//!uniform vec4 casData[shadowmapCascades * 4 + 4];
|
||||
#else
|
||||
uniform mat4 LWVP;
|
||||
#endif
|
||||
// #ifdef _SoftShadows
|
||||
// uniform sampler2D svisibility;
|
||||
// #else
|
||||
#endif // _ShadowMap
|
||||
#endif
|
||||
|
||||
#ifdef _LightClouds
|
||||
uniform sampler2D texClouds;
|
||||
uniform float time;
|
||||
#endif
|
||||
|
||||
in vec2 texCoord;
|
||||
in vec3 viewRay;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
vec2 texCoord = wvpposition.xy / wvpposition.w;
|
||||
texCoord = texCoord * 0.5 + 0.5;
|
||||
#ifdef _InvY
|
||||
texCoord.y = 1.0 - texCoord.y;
|
||||
#endif
|
||||
|
||||
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
|
||||
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
|
||||
float spec = unpackFloat2(g1.a).g;
|
||||
// #ifdef _InvY // D3D
|
||||
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0; // 0 - 1 => -1 - 1
|
||||
// #else
|
||||
// TODO: store_depth
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
// #endif
|
||||
|
||||
|
||||
vec3 n;
|
||||
n.z = 1.0 - abs(g0.x) - abs(g0.y);
|
||||
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
|
||||
n = normalize(n);
|
||||
|
||||
vec3 p = getPos2(invVP, depth, texCoord);
|
||||
vec2 metrough = unpackFloat(g0.b);
|
||||
|
||||
vec3 v = normalize(eye - p);
|
||||
float dotNV = dot(n, v);
|
||||
|
||||
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
|
||||
vec2 occspec = unpackFloat2(g1.a);
|
||||
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
|
||||
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
|
||||
|
||||
vec3 lp = lightPos - p;
|
||||
vec3 l = normalize(lp);
|
||||
vec3 h = normalize(v + l);
|
||||
float dotNH = dot(n, h);
|
||||
float dotVH = dot(v, h);
|
||||
float dotNL = dot(n, l);
|
||||
|
||||
float visibility = 1.0;
|
||||
|
||||
#ifndef _NoShadows
|
||||
|
||||
#ifdef _SoftShadows
|
||||
|
||||
visibility = texture(svisibility, texCoord).r;
|
||||
|
||||
#else
|
||||
|
||||
if (lightShadow == 1) {
|
||||
vec4 lPos = LWVP * vec4(p + n * shadowsBias * 10, 1.0);
|
||||
if (lPos.w > 0.0) {
|
||||
#ifdef _SMSizeUniform
|
||||
visibility = shadowTest(shadowMap, lPos.xyz / lPos.w, shadowsBias, smSizeUniform);
|
||||
#else
|
||||
visibility = shadowTest(shadowMap, lPos.xyz / lPos.w, shadowsBias, shadowmapSize);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (lightShadow == 2) { // Cube
|
||||
visibility = PCFCube(shadowMapCube, lp, -l, shadowsBias, lightProj, n);
|
||||
}
|
||||
#endif
|
||||
// #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);
|
||||
vec3 v = normalize(eye - p);
|
||||
float dotNV = max(dot(n, v), 0.0);
|
||||
|
||||
#ifdef _Brdf
|
||||
vec2 envBRDF = texture(senvmapBrdf, vec2(metrough.y, 1.0 - dotNV)).xy;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _VoxelGIShadow // #else
|
||||
#ifdef _VoxelGI
|
||||
#ifdef _VoxelGICam
|
||||
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
#else
|
||||
vec3 voxpos = p / voxelgiHalfExtents;
|
||||
#endif
|
||||
if (dotNL > 0.0) visibility = max(0, 1.0 - traceShadow(voxels, voxpos, l, 0.1, length(lp), n));
|
||||
#endif
|
||||
|
||||
visibility *= attenuate(distance(p, lightPos));
|
||||
#ifdef _VoxelGITemporal
|
||||
vec4 indirectDiffuse = traceDiffuse(voxpos, n, voxels) * voxelBlend + traceDiffuse(voxpos, n, voxelsLast) * (1.0 - voxelBlend);
|
||||
#else
|
||||
vec4 indirectDiffuse = traceDiffuse(voxpos, n, voxels);
|
||||
#endif
|
||||
|
||||
#ifdef _LightIES
|
||||
visibility *= iesAttenuation(-l);
|
||||
#endif
|
||||
if (lightType == 2) { // Spot
|
||||
float spotEffect = dot(lightDir, l);
|
||||
// x - cutoff, y - cutoff - exponent
|
||||
if (spotEffect < spotlightData.x) {
|
||||
visibility *= smoothstep(spotlightData.y, spotlightData.x, spotEffect);
|
||||
}
|
||||
fragColor.rgb = indirectDiffuse.rgb * voxelgiDiff * g1.rgb;
|
||||
|
||||
if (occspec.y > 0.0) {
|
||||
vec3 indirectSpecular = traceSpecular(voxels, voxpos, n, v, metrough.y);
|
||||
indirectSpecular *= f0 * envBRDF.x + envBRDF.y;
|
||||
fragColor.rgb += indirectSpecular * voxelgiSpec * occspec.y;
|
||||
}
|
||||
|
||||
#ifdef _LTC
|
||||
if (lightType == 3) { // Area
|
||||
float theta = acos(dotNV);
|
||||
vec2 tuv = vec2(metrough.y, theta / (0.5 * PI));
|
||||
tuv = tuv * LUT_SCALE + LUT_BIAS;
|
||||
vec4 t = texture(sltcMat, tuv);
|
||||
mat3 invM = mat3(
|
||||
vec3(1.0, 0.0, t.y),
|
||||
vec3(0.0, t.z, 0.0),
|
||||
vec3(t.w, 0.0, t.x));
|
||||
|
||||
float ltcspec = ltcEvaluate(n, v, dotNV, p, invM, lightArea0, lightArea1, lightArea2, lightArea3);
|
||||
ltcspec *= texture(sltcMag, tuv).a;
|
||||
float ltcdiff = ltcEvaluate(n, v, dotNV, p, mat3(1.0), lightArea0, lightArea1, lightArea2, lightArea3);
|
||||
fragColor.rgb = albedo * ltcdiff + ltcspec * spec;
|
||||
}
|
||||
else {
|
||||
// if (!isInsideCube(voxpos)) fragColor = vec4(1.0); // Show bounds
|
||||
#endif
|
||||
|
||||
#ifdef _Hair // Aniso
|
||||
if (texture(gbuffer2, texCoord).a == 2) {
|
||||
const float shinyParallel = metrough.y;
|
||||
const float shinyPerpendicular = 0.1;
|
||||
const vec3 v = vec3(0.99146, 0.11664, 0.05832);
|
||||
vec3 T = abs(dot(n, v)) > 0.99999 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, v);
|
||||
fragColor.rgb = orenNayarDiffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH) + wardSpecular(n, h, dotNL, dotNV, dotNH, T, shinyParallel, shinyPerpendicular) * spec;
|
||||
}
|
||||
else fragColor.rgb = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH) * spec;
|
||||
// Envmap
|
||||
#ifdef _Irr
|
||||
vec3 envl = shIrradiance(n);
|
||||
#ifdef _EnvTex
|
||||
envl /= PI;
|
||||
#endif
|
||||
#else
|
||||
fragColor.rgb = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH) * spec;
|
||||
vec3 envl = vec3(1.0);
|
||||
#endif
|
||||
|
||||
#ifdef _LTC
|
||||
}
|
||||
#ifdef _Rad
|
||||
vec3 reflectionWorld = reflect(-v, n);
|
||||
float lod = getMipFromRoughness(metrough.y, envmapNumMipmaps);
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
|
||||
#endif
|
||||
|
||||
fragColor.rgb *= lightColor;
|
||||
#ifdef _EnvLDR
|
||||
envl.rgb = pow(envl.rgb, vec3(2.2));
|
||||
#ifdef _Rad
|
||||
prefilteredColor = pow(prefilteredColor, vec3(2.2));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
envl.rgb *= albedo;
|
||||
|
||||
#ifdef _Rad // Indirect specular
|
||||
envl.rgb += prefilteredColor * (f0 * envBRDF.x + envBRDF.y) * 1.5 * occspec.y;
|
||||
#else
|
||||
#ifdef _EnvCol
|
||||
envl.rgb += backgroundCol * surfaceF0(g1.rgb, metrough.x); // f0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
envl.rgb *= envmapStrength * occspec.x;
|
||||
|
||||
#ifdef _VoxelAOvar
|
||||
|
||||
#ifdef _VoxelGICam
|
||||
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
#else
|
||||
vec3 voxpos = p / voxelgiHalfExtents;
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGITemporal
|
||||
envl.rgb *= 1.0 - (traceAO(voxpos, n, voxels) * voxelBlend + traceAO(voxpos, n, voxelsLast) * (1.0 - voxelBlend));
|
||||
#else
|
||||
envl.rgb *= 1.0 - traceAO(voxpos, n, voxels);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGI
|
||||
fragColor.rgb += envl * voxelgiEnv;
|
||||
#else
|
||||
fragColor.rgb = envl;
|
||||
#endif
|
||||
|
||||
#ifdef _SSAO
|
||||
#ifdef _RTGI
|
||||
fragColor.rgb *= texture(ssaotex, texCoord).rgb;
|
||||
#else
|
||||
fragColor.rgb *= texture(ssaotex, texCoord).r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Show voxels
|
||||
// vec3 origin = vec3(texCoord * 2.0 - 1.0, 0.99);
|
||||
// vec3 direction = vec3(0.0, 0.0, -1.0);
|
||||
// vec4 color = vec4(0.0f);
|
||||
// for(uint step = 0; step < 400 && color.a < 0.99f; ++step) {
|
||||
// vec3 point = origin + 0.005 * step * direction;
|
||||
// color += (1.0f - color.a) * textureLod(voxels, point * 0.5 + 0.5, 0);
|
||||
// }
|
||||
// fragColor.rgb += color.rgb;
|
||||
|
||||
// Show SSAO
|
||||
// fragColor.rgb = texture(ssaotex, texCoord).rrr;
|
||||
|
||||
#ifdef _Sun
|
||||
vec3 sh = normalize(v + sunDir);
|
||||
float sdotNH = dot(n, sh);
|
||||
float sdotVH = dot(v, sh);
|
||||
float sdotNL = dot(n, sunDir);
|
||||
float svisibility = 1.0;
|
||||
vec3 sdirect = lambertDiffuseBRDF(albedo, sdotNL) +
|
||||
specularBRDF(f0, metrough.y, sdotNL, sdotNH, dotNV, sdotVH) * occspec.y;
|
||||
|
||||
// #ifdef _SoftShadows
|
||||
// svisibility = texture(svisibility, texCoord).r;
|
||||
// #endif
|
||||
|
||||
// if (lightShadow == 1) {
|
||||
#ifdef _CSM
|
||||
svisibility = shadowTestCascade(shadowMap, eye, p + n * shadowsBias * 10, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0));
|
||||
#else
|
||||
vec4 lPos = LWVP * vec4(p + n * shadowsBias * 100, 1.0);
|
||||
if (lPos.w > 0.0) svisibility = shadowTest(shadowMap, lPos.xyz / lPos.w, shadowsBias, shadowmapSize);
|
||||
#endif
|
||||
// }
|
||||
|
||||
#ifdef _VoxelGIShadow // #else
|
||||
#ifdef _VoxelGICam
|
||||
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
#else
|
||||
vec3 voxpos = p / voxelgiHalfExtents;
|
||||
#endif
|
||||
if (dotNL > 0.0) svisibility = max(0, 1.0 - traceShadow(voxels, voxpos, l, 0.1, 10.0, n));
|
||||
#endif
|
||||
|
||||
fragColor.rgb += sdirect * svisibility * sunCol;
|
||||
#endif
|
||||
|
||||
// #ifdef _Hair // Aniso
|
||||
// if (texture(gbuffer2, texCoord).a == 2) {
|
||||
// const float shinyParallel = metrough.y;
|
||||
// const float shinyPerpendicular = 0.1;
|
||||
// const vec3 v = vec3(0.99146, 0.11664, 0.05832);
|
||||
// vec3 T = abs(dot(n, v)) > 0.99999 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, v);
|
||||
// fragColor.rgb = orenNayarDiffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH) + wardSpecular(n, h, dotNL, dotNV, dotNH, T, shinyParallel, shinyPerpendicular) * spec;
|
||||
// }
|
||||
// else fragColor.rgb = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH) * spec;
|
||||
// #endif
|
||||
|
||||
#ifdef _LightClouds
|
||||
visibility *= texture(texClouds, vec2(p.xy / 100.0 + time / 80.0)).r * dot(n, vec3(0,0,1));
|
||||
#endif
|
||||
|
||||
#ifdef _SSS
|
||||
if (texture(gbuffer2, texCoord).a == 2) {
|
||||
if (lightShadow == 1) fragColor.rgb += fragColor.rgb * SSSSTransmittance(LWVP, p, n, l, lightPlane.y, shadowMap);
|
||||
// else fragColor.rgb += fragColor.rgb * SSSSTransmittanceCube();
|
||||
#ifdef _CSM
|
||||
int casi, casindex;
|
||||
mat4 LWVP = getCascadeMat(distance(eye, p), casi, casindex);
|
||||
#endif
|
||||
fragColor.rgb += fragColor.rgb * SSSSTransmittance(LWVP, p, n, l, lightPlane.y, shadowMap);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -225,5 +361,102 @@ void main() {
|
|||
visibility *= tvis;
|
||||
#endif
|
||||
|
||||
fragColor.rgb *= visibility;
|
||||
#ifdef _Clusters
|
||||
|
||||
float depthl = linearize(depth * 0.5 + 0.5, cameraProj);
|
||||
int sliceZ = 0;
|
||||
if (depthl >= clusterNear) {
|
||||
float z = log(depthl - clusterNear + 1.0) / log(cameraPlane.y - clusterNear + 1.0);
|
||||
sliceZ = int(z * (clusterSlices.z - 1)) + 1;
|
||||
}
|
||||
int clusterI = int(texCoord.x * clusterSlices.x) +
|
||||
int(int(texCoord.y * clusterSlices.y) * clusterSlices.x) +
|
||||
int(sliceZ * clusterSlices.x * clusterSlices.y);
|
||||
|
||||
int numLights = int(texelFetch(clustersData, ivec2(clusterI, 0), 0).r * 255);
|
||||
|
||||
#ifdef _Spot
|
||||
int numSpots = int(texelFetch(clustersData, ivec2(clusterI, 1 + maxLightsCluster), 0).r * 255);
|
||||
int numPoints = numLights - numSpots;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < numLights; i++) {
|
||||
int li = int(texelFetch(clustersData, ivec2(clusterI, i + 1), 0).r * 255);
|
||||
|
||||
// pos
|
||||
// lightsArray[li * 2 ]
|
||||
// color
|
||||
// lightsArray[li * 2 + 1]
|
||||
// spot - dir
|
||||
// lightsArraySpot[li]
|
||||
|
||||
vec3 lp = lightsArray[li * 2].xyz;
|
||||
vec3 ld = lp - p;
|
||||
vec3 l = normalize(ld);
|
||||
vec3 h = normalize(v + l);
|
||||
float dotNH = dot(n, h);
|
||||
float dotVH = dot(v, h);
|
||||
float dotNL = dot(n, l);
|
||||
|
||||
vec3 direct = lambertDiffuseBRDF(albedo, dotNL) +
|
||||
specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH) * occspec.y;
|
||||
|
||||
direct *= lightsArray[li * 2 + 1].xyz;
|
||||
|
||||
float visibility = attenuate(distance(p, lp));
|
||||
|
||||
#ifdef _Spot
|
||||
if (i > numPoints - 1) {
|
||||
float spotEffect = dot(lightsArraySpot[li].xyz, l); // lightDir
|
||||
// x - cutoff, y - cutoff - exponent
|
||||
if (spotEffect < lightsArray[li * 2 + 1].w) {
|
||||
visibility *= smoothstep(lightsArraySpot[li].w, lightsArray[li * 2 + 1].w, spotEffect);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _LightIES
|
||||
visibility *= iesAttenuation(-l);
|
||||
#endif
|
||||
|
||||
// #ifdef _LTC
|
||||
// if (lightType == 3) { // Area
|
||||
// float theta = acos(dotNV);
|
||||
// vec2 tuv = vec2(metrough.y, theta / (0.5 * PI));
|
||||
// tuv = tuv * LUT_SCALE + LUT_BIAS;
|
||||
// vec4 t = texture(sltcMat, tuv);
|
||||
// mat3 invM = mat3(
|
||||
// vec3(1.0, 0.0, t.y),
|
||||
// vec3(0.0, t.z, 0.0),
|
||||
// vec3(t.w, 0.0, t.x));
|
||||
|
||||
// float ltcspec = ltcEvaluate(n, v, dotNV, p, invM, lightArea0, lightArea1, lightArea2, lightArea3);
|
||||
// ltcspec *= texture(sltcMag, tuv).a;
|
||||
// float ltcdiff = ltcEvaluate(n, v, dotNV, p, mat3(1.0), lightArea0, lightArea1, lightArea2, lightArea3);
|
||||
// fragColor.rgb = albedo * ltcdiff + ltcspec * spec;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
#ifdef _ShadowMap
|
||||
// if (lightShadow == 1) {
|
||||
float bias = lightsArray[li * 2].w;
|
||||
#ifdef _ShadowMapCube
|
||||
visibility *= PCFCube(shadowMap0, ld, -l, bias, lightProj, n);
|
||||
#else
|
||||
vec4 lPos = LWVP0 * vec4(p + n * shadowsBias * 10, 1.0);
|
||||
if (lPos.w > 0.0) {
|
||||
#ifdef _SMSizeUniform
|
||||
visibility *= shadowTest(shadowMap0, lPos.xyz / lPos.w, bias, smSizeUniform);
|
||||
#else
|
||||
visibility *= shadowTest(shadowMap0, lPos.xyz / lPos.w, bias, shadowmapSize);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
// }
|
||||
#endif // _ShadowMap
|
||||
|
||||
fragColor.rgb += direct * visibility;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,50 +1,113 @@
|
|||
{
|
||||
"variants": ["_VoxelAOvar"],
|
||||
"contexts": [
|
||||
{
|
||||
"name": "deferred_light",
|
||||
"depth_write": false,
|
||||
"color_write_alpha": false,
|
||||
"compare_mode": "greater",
|
||||
"cull_mode": "counter_clockwise",
|
||||
"blend_source": "blend_one",
|
||||
"blend_destination": "blend_one",
|
||||
"blend_operation": "add",
|
||||
"alpha_blend_source": "blend_one",
|
||||
"alpha_blend_destination": "blend_one",
|
||||
"alpha_blend_operation": "add",
|
||||
"compare_mode": "always",
|
||||
"cull_mode": "none",
|
||||
"links": [
|
||||
{
|
||||
"name": "VWVP",
|
||||
"link": "_lightVolumeWorldViewProjectionMatrix"
|
||||
"name": "eye",
|
||||
"link": "_cameraPosition"
|
||||
},
|
||||
{
|
||||
"name": "lightPos",
|
||||
"link": "_lightPosition"
|
||||
"name": "eyeSnap",
|
||||
"link": "_cameraPositionSnap",
|
||||
"ifdef": ["_VoxelGICam"]
|
||||
},
|
||||
{
|
||||
"name": "lightProj",
|
||||
"link": "_lightPlaneProj"
|
||||
"name": "voxelBlend",
|
||||
"link": "_voxelBlend",
|
||||
"ifdef": ["_VoxelGITemporal"]
|
||||
},
|
||||
{
|
||||
"name": "lightDir",
|
||||
"link": "_lightDirection"
|
||||
"name": "eyeLook",
|
||||
"link": "_cameraLook"
|
||||
},
|
||||
{
|
||||
"name": "lightType",
|
||||
"link": "_lightType"
|
||||
"name": "invVP",
|
||||
"link": "_inverseViewProjectionMatrix"
|
||||
},
|
||||
{
|
||||
"name": "lightColor",
|
||||
"link": "_lightColor"
|
||||
"name": "shirr",
|
||||
"link": "_envmapIrradiance",
|
||||
"ifdef": ["_Irr"]
|
||||
},
|
||||
{
|
||||
"name": "lightShadow",
|
||||
"link": "_lightCastShadow"
|
||||
"name": "senvmapRadiance",
|
||||
"link": "_envmapRadiance",
|
||||
"ifdef": ["_Rad"]
|
||||
},
|
||||
{
|
||||
"name": "texIES",
|
||||
"link": "_iesTexture",
|
||||
"ifdef": ["_LightIES"]
|
||||
"name": "envmapNumMipmaps",
|
||||
"link": "_envmapNumMipmaps",
|
||||
"ifdef": ["_Rad"]
|
||||
},
|
||||
{
|
||||
"name": "senvmapBrdf",
|
||||
"link": "_envmapBrdf",
|
||||
"ifdef": ["_Brdf"]
|
||||
},
|
||||
{
|
||||
"name": "cameraProj",
|
||||
"link": "_cameraPlaneProj"
|
||||
},
|
||||
{
|
||||
"name": "envmapStrength",
|
||||
"link": "_envmapStrength"
|
||||
},
|
||||
{
|
||||
"name": "backgroundCol",
|
||||
"link": "_backgroundCol",
|
||||
"ifdef": ["_EnvCol"]
|
||||
},
|
||||
{
|
||||
"name": "lightsArray",
|
||||
"link": "_lightsArray",
|
||||
"ifdef": ["_Clusters"]
|
||||
},
|
||||
{
|
||||
"name": "lightsArraySpot",
|
||||
"link": "_lightsArraySpot",
|
||||
"ifdef": ["_Spot"]
|
||||
},
|
||||
{
|
||||
"name": "clustersData",
|
||||
"link": "_clustersData",
|
||||
"ifdef": ["_Clusters"]
|
||||
},
|
||||
{
|
||||
"name": "cameraPlane",
|
||||
"link": "_cameraPlane",
|
||||
"ifdef": ["_Clusters"]
|
||||
},
|
||||
{
|
||||
"name": "sunDir",
|
||||
"link": "_sunDirection",
|
||||
"ifdef": ["_Sun"]
|
||||
},
|
||||
{
|
||||
"name": "sunCol",
|
||||
"link": "_sunColor",
|
||||
"ifdef": ["_Sun"]
|
||||
},
|
||||
{
|
||||
"name": "shadowsBias",
|
||||
"link": "_sunShadowsBias",
|
||||
"ifdef": ["_Sun", "_ShadowMap"]
|
||||
},
|
||||
{
|
||||
"name": "LWVP",
|
||||
"link": "_biasLightWorldViewProjectionMatrix",
|
||||
"ifndef": ["_CSM"],
|
||||
"ifdef": ["_Sun", "_ShadowMap"]
|
||||
},
|
||||
{
|
||||
"name": "casData",
|
||||
"link": "_cascadeData",
|
||||
"ifdef": ["_Sun", "_ShadowMap", "_CSM"]
|
||||
},
|
||||
{
|
||||
"name": "lightPlane",
|
||||
|
@ -52,12 +115,24 @@
|
|||
"ifdef": ["_SSS"]
|
||||
},
|
||||
{
|
||||
"name": "shadowsBias",
|
||||
"link": "_lightShadowsBias"
|
||||
"name": "VP",
|
||||
"link": "_viewProjectionMatrix",
|
||||
"ifdef": ["_SSRS"]
|
||||
},
|
||||
{
|
||||
"name": "spotlightData",
|
||||
"link": "_spotlightData"
|
||||
"name": "texClouds",
|
||||
"link": "_cloudsTexture",
|
||||
"ifdef": ["_LightClouds"]
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"link": "_time",
|
||||
"ifdef": ["_LightClouds"]
|
||||
},
|
||||
{
|
||||
"name": "texIES",
|
||||
"link": "_iesTexture",
|
||||
"ifdef": ["_LightIES"]
|
||||
},
|
||||
{
|
||||
"name": "lightArea0",
|
||||
|
@ -89,30 +164,18 @@
|
|||
"link": "_ltcMag",
|
||||
"ifdef": ["_LTC"]
|
||||
},
|
||||
{
|
||||
"name": "eye",
|
||||
"link": "_cameraPosition"
|
||||
},
|
||||
{
|
||||
"name": "invVP",
|
||||
"link": "_inverseViewProjectionMatrix"
|
||||
},
|
||||
{
|
||||
"name": "LWVP",
|
||||
"link": "_biasLightWorldViewProjectionMatrix"
|
||||
},
|
||||
{
|
||||
"name": "VP",
|
||||
"link": "_viewProjectionMatrix",
|
||||
"ifdef": ["_SSRS"]
|
||||
},
|
||||
{
|
||||
"name": "smSizeUniform",
|
||||
"link": "_shadowMapSize",
|
||||
"ifdef": ["_SMSizeUniform"]
|
||||
},
|
||||
{
|
||||
"name": "lightProj",
|
||||
"link": "_lightPlaneProj",
|
||||
"ifdef": ["_ShadowMapCube"]
|
||||
}
|
||||
],
|
||||
"vertex_shader": "../include/pass_volume.vert.glsl",
|
||||
"vertex_shader": "deferred_light.vert.glsl",
|
||||
"fragment_shader": "deferred_light.frag.glsl"
|
||||
}
|
||||
]
|
||||
|
|
12
Shaders/deferred_indirect/deferred_indirect.vert.glsl → Shaders/deferred_light/deferred_light.vert.glsl
Executable file → Normal file
12
Shaders/deferred_indirect/deferred_indirect.vert.glsl → Shaders/deferred_light/deferred_light.vert.glsl
Executable file → Normal file
|
@ -2,17 +2,13 @@
|
|||
|
||||
#include "compiled.inc"
|
||||
|
||||
#ifdef _IndPos
|
||||
uniform mat4 invVP;
|
||||
uniform vec3 eye;
|
||||
#endif
|
||||
uniform mat4 invVP;
|
||||
uniform vec3 eye;
|
||||
|
||||
in vec2 pos;
|
||||
|
||||
out vec2 texCoord;
|
||||
#ifdef _IndPos
|
||||
out vec3 viewRay;
|
||||
#endif
|
||||
out vec3 viewRay;
|
||||
|
||||
void main() {
|
||||
// Scale vertex attribute to [0-1] range
|
||||
|
@ -24,11 +20,9 @@ void main() {
|
|||
|
||||
gl_Position = vec4(pos.xy, 0.0, 1.0);
|
||||
|
||||
#ifdef _IndPos
|
||||
// NDC (at the back of cube)
|
||||
vec4 v = vec4(pos.x, pos.y, 1.0, 1.0);
|
||||
v = vec4(invVP * v);
|
||||
v.xyz /= v.w;
|
||||
viewRay = v.xyz - eye;
|
||||
#endif
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.inc"
|
||||
#include "std/brdf.glsl"
|
||||
#include "std/math.glsl"
|
||||
#ifdef _VoxelGIDirect
|
||||
#include "std/conetrace.glsl"
|
||||
#endif
|
||||
#ifndef _NoShadows
|
||||
#include "std/shadows.glsl"
|
||||
#endif
|
||||
#ifdef _SSS
|
||||
#include "std/sss.glsl"
|
||||
#endif
|
||||
#ifdef _SSRS
|
||||
#include "std/ssrs.glsl"
|
||||
#endif
|
||||
#include "std/gbuffer.glsl"
|
||||
|
||||
#ifdef _VoxelGIDirect
|
||||
uniform sampler3D voxels;
|
||||
#endif
|
||||
#ifdef _VoxelGICam
|
||||
uniform vec3 eyeSnap;
|
||||
#endif
|
||||
|
||||
// uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbuffer0;
|
||||
uniform sampler2D gbuffer1;
|
||||
#ifdef _gbuffer2direct
|
||||
uniform sampler2D gbuffer2;
|
||||
#endif
|
||||
|
||||
#ifdef _SSS
|
||||
vec2 lightPlane;
|
||||
#endif
|
||||
|
||||
#ifndef _NoShadows
|
||||
#ifdef _SoftShadows
|
||||
uniform sampler2D svisibility;
|
||||
#else
|
||||
uniform sampler2D shadowMap;
|
||||
#ifdef _CSM
|
||||
//!uniform vec4 casData[shadowmapCascades * 4 + 4];
|
||||
#else
|
||||
uniform mat4 LWVP;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef _LightClouds
|
||||
uniform sampler2D texClouds;
|
||||
uniform float time;
|
||||
#endif
|
||||
|
||||
uniform vec3 lightColor;
|
||||
uniform vec3 l; // lightDir
|
||||
uniform int lightShadow;
|
||||
uniform float shadowsBias;
|
||||
uniform vec3 eye;
|
||||
uniform vec3 eyeLook;
|
||||
uniform vec2 cameraProj;
|
||||
#ifdef _SSRS
|
||||
//!uniform mat4 VP;
|
||||
uniform mat4 invVP;
|
||||
#endif
|
||||
|
||||
in vec2 texCoord;
|
||||
in vec3 viewRay;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, depth
|
||||
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, spec/occ
|
||||
float spec = unpackFloat2(g1.a).g;
|
||||
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0; // 0 - 1 => -1 - 1
|
||||
// TODO: store_depth
|
||||
// TODO: Firefox throws feedback loop detected error, read depth from gbuffer0
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
|
||||
vec3 n;
|
||||
n.z = 1.0 - abs(g0.x) - abs(g0.y);
|
||||
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
|
||||
n = normalize(n);
|
||||
|
||||
vec3 p = getPos(eye, eyeLook, viewRay, depth, cameraProj);
|
||||
vec2 metrough = unpackFloat(g0.b);
|
||||
|
||||
vec3 v = normalize(eye - p);
|
||||
float dotNV = dot(n, v);
|
||||
|
||||
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
|
||||
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
|
||||
float dotNL = dot(n, l);
|
||||
|
||||
float visibility = 1.0;
|
||||
#ifndef _NoShadows
|
||||
|
||||
#ifdef _SoftShadows
|
||||
|
||||
visibility = texture(svisibility, texCoord).r;
|
||||
|
||||
#else
|
||||
|
||||
if (lightShadow == 1) {
|
||||
#ifdef _CSM
|
||||
visibility = shadowTestCascade(shadowMap, eye, p + n * shadowsBias * 10, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0));
|
||||
#else
|
||||
vec4 lPos = LWVP * vec4(p + n * shadowsBias * 100, 1.0);
|
||||
if (lPos.w > 0.0) visibility = shadowTest(shadowMap, lPos.xyz / lPos.w, shadowsBias, shadowmapSize);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGIShadow // #else
|
||||
#ifdef _VoxelGICam
|
||||
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
#else
|
||||
vec3 voxpos = p / voxelgiHalfExtents;
|
||||
#endif
|
||||
if (dotNL > 0.0) visibility = max(0, 1.0 - traceShadow(voxels, voxpos, l, 0.1, 10.0, n));
|
||||
#endif
|
||||
|
||||
// Per-light
|
||||
// vec3 l = lightDir; // lightType == 0 // Sun
|
||||
vec3 h = normalize(v + l);
|
||||
float dotNH = dot(n, h);
|
||||
float dotVH = dot(v, h);
|
||||
|
||||
#ifdef _Hair // Aniso
|
||||
if (texture(gbuffer2, texCoord).a == 2) {
|
||||
const float shinyParallel = metrough.y;
|
||||
const float shinyPerpendicular = 0.1;
|
||||
const vec3 v = vec3(0.99146, 0.11664, 0.05832);
|
||||
vec3 T = abs(dot(n, v)) > 0.99999 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, v);
|
||||
fragColor.rgb = orenNayarDiffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH) + wardSpecular(n, h, dotNL, dotNV, dotNH, T, shinyParallel, shinyPerpendicular) * spec;
|
||||
}
|
||||
else fragColor.rgb = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH) * spec;
|
||||
#else
|
||||
fragColor.rgb = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH) * spec;
|
||||
#endif
|
||||
|
||||
fragColor.rgb *= lightColor;
|
||||
|
||||
#ifdef _SSS
|
||||
if (texture(gbuffer2, texCoord).a == 2) {
|
||||
#ifdef _CSM
|
||||
int casi, casindex;
|
||||
mat4 LWVP = getCascadeMat(distance(eye, p), casi, casindex);
|
||||
#endif
|
||||
fragColor.rgb += fragColor.rgb * SSSSTransmittance(LWVP, p, n, l, lightPlane.y, shadowMap);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _SSRS
|
||||
float tvis = traceShadowSS(-l, p, gbuffer0, invVP, eye);
|
||||
// vec2 coords = getProjectedCoord(hitCoord);
|
||||
// vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
|
||||
// float screenEdgeFactor = clamp(1.0 - (deltaCoords.x + deltaCoords.y), 0.0, 1.0);
|
||||
// tvis *= screenEdgeFactor;
|
||||
visibility *= tvis;
|
||||
#endif
|
||||
|
||||
#ifdef _LightClouds
|
||||
visibility *= texture(texClouds, vec2(p.xy / 100.0 + time / 80.0)).r * dot(n, vec3(0,0,1));
|
||||
#endif
|
||||
|
||||
fragColor.rgb *= visibility;
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
{
|
||||
"contexts": [
|
||||
{
|
||||
"name": "deferred_light_quad",
|
||||
"depth_write": false,
|
||||
"color_write_alpha": false,
|
||||
"compare_mode": "always",
|
||||
"cull_mode": "none",
|
||||
"blend_source": "blend_one",
|
||||
"blend_destination": "blend_one",
|
||||
"blend_operation": "add",
|
||||
"alpha_blend_source": "blend_one",
|
||||
"alpha_blend_destination": "blend_one",
|
||||
"alpha_blend_operation": "add",
|
||||
"links": [
|
||||
{
|
||||
"name": "invVP",
|
||||
"link": "_inverseViewProjectionMatrix"
|
||||
},
|
||||
{
|
||||
"name": "l",
|
||||
"link": "_lightDirection"
|
||||
},
|
||||
{
|
||||
"name": "lightColor",
|
||||
"link": "_lightColor"
|
||||
},
|
||||
{
|
||||
"name": "lightShadow",
|
||||
"link": "_lightCastShadow"
|
||||
},
|
||||
{
|
||||
"name": "texClouds",
|
||||
"link": "_cloudsTexture",
|
||||
"ifdef": ["_LightClouds"]
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"link": "_time",
|
||||
"ifdef": ["_LightClouds"]
|
||||
},
|
||||
{
|
||||
"name": "shadowsBias",
|
||||
"link": "_lightShadowsBias"
|
||||
},
|
||||
{
|
||||
"name": "eye",
|
||||
"link": "_cameraPosition"
|
||||
},
|
||||
{
|
||||
"name": "eyeSnap",
|
||||
"link": "_cameraPositionSnap",
|
||||
"ifdef": ["_VoxelGICam"]
|
||||
},
|
||||
{
|
||||
"name": "eyeLook",
|
||||
"link": "_cameraLook"
|
||||
},
|
||||
{
|
||||
"name": "lightPlane",
|
||||
"link": "_lightPlane",
|
||||
"ifdef": ["_SSS"]
|
||||
},
|
||||
{
|
||||
"name": "LWVP",
|
||||
"link": "_biasLightWorldViewProjectionMatrix",
|
||||
"ifndef": ["_CSM"]
|
||||
},
|
||||
{
|
||||
"name": "casData",
|
||||
"link": "_cascadeData",
|
||||
"ifdef": ["_CSM"]
|
||||
},
|
||||
{
|
||||
"name": "VP",
|
||||
"link": "_viewProjectionMatrix",
|
||||
"ifdef": ["_SSRS"]
|
||||
},
|
||||
{
|
||||
"name": "cameraProj",
|
||||
"link": "_cameraPlaneProj"
|
||||
}
|
||||
],
|
||||
"vertex_shader": "../include/pass_viewray.vert.glsl",
|
||||
"fragment_shader": "deferred_light_quad.frag.glsl"
|
||||
}
|
||||
]
|
||||
}
|
3
Shaders/std/clusters.glsl
Normal file
3
Shaders/std/clusters.glsl
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
const int maxLights = 16;
|
||||
const int maxLightsCluster = 8;
|
|
@ -35,7 +35,7 @@ float attenuate(const float dist) {
|
|||
// float attenuate(float dist, float constant, float linear, float quadratic) {
|
||||
return 1.0 / (dist * dist);
|
||||
// 1.0 / (constant * 1.0)
|
||||
// 1.0 / (lienar * dist)
|
||||
// 1.0 / (linear * dist)
|
||||
// 1.0 / (quadratic * dist * dist);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,11 +30,6 @@
|
|||
"name": "LWVP",
|
||||
"link": "_biasLightWorldViewProjectionMatrix"
|
||||
},
|
||||
{
|
||||
"name": "lightType",
|
||||
"link": "_lightType",
|
||||
"ifdef": ["_Disabled"]
|
||||
},
|
||||
{
|
||||
"name": "lightShadow",
|
||||
"link": "_lightCastShadow"
|
||||
|
|
|
@ -14,7 +14,7 @@ uniform vec3 lightColor;
|
|||
uniform int lightType;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec2 spotData;
|
||||
#ifndef _NoShadows
|
||||
#ifdef _ShadowMap
|
||||
uniform int lightShadow;
|
||||
uniform vec2 lightProj;
|
||||
uniform float shadowsBias;
|
||||
|
@ -25,7 +25,7 @@ uniform layout(binding = 0, rgba8) readonly image3D voxelsOpac;
|
|||
uniform layout(binding = 1, r32ui) readonly uimage3D voxelsNor;
|
||||
// uniform layout(binding = 2, rgba8) writeonly image3D voxels;
|
||||
uniform layout(binding = 2, r32ui) uimage3D voxels;
|
||||
#ifndef _NoShadows
|
||||
#ifdef _ShadowMap
|
||||
uniform layout(binding = 3) sampler2D shadowMap;
|
||||
uniform layout(binding = 4) samplerCube shadowMapCube;
|
||||
#endif
|
||||
|
@ -52,7 +52,7 @@ void main() {
|
|||
float dotNL = max(dot(wnormal, l), 0.0);
|
||||
if (dotNL == 0.0) return;
|
||||
|
||||
#ifndef _NoShadows
|
||||
#ifdef _ShadowMap
|
||||
if (lightShadow == 1) {
|
||||
vec4 lightPosition = LVP * vec4(wposition, 1.0);
|
||||
vec3 lPos = lightPosition.xyz / lightPosition.w;
|
||||
|
|
|
@ -7,19 +7,8 @@
|
|||
#include "compiled.inc"
|
||||
#include "std/gbuffer.glsl"
|
||||
// #include "std/math.glsl"
|
||||
// #ifndef _NoShadows
|
||||
// #include "std/shadows.glsl"
|
||||
// #endif
|
||||
|
||||
uniform sampler2D gbufferD;
|
||||
// #ifndef _NoShadows
|
||||
// uniform mat4 LWVP;
|
||||
// uniform float shadowsBias;
|
||||
// uniform vec2 lightPlane;
|
||||
// uniform int lightShadow;
|
||||
//-!-uniform sampler2D shadowMap;
|
||||
//-!-uniform samplerCube shadowMapCube;
|
||||
// #endif
|
||||
// uniform sampler2D gbuffer0;
|
||||
// uniform sampler2D senvmapRadiance;
|
||||
uniform sampler2D snoise;
|
||||
|
@ -28,7 +17,6 @@ uniform float time;
|
|||
uniform vec3 eye;
|
||||
uniform vec3 eyeLook;
|
||||
uniform vec2 cameraProj;
|
||||
// uniform vec3 lightPos;
|
||||
uniform vec3 ld;
|
||||
uniform float envmapStrength;
|
||||
|
||||
|
@ -227,15 +215,6 @@ vec3 getSeaColor(vec3 p, vec3 n, vec3 l, vec3 eye, vec3 dist) {
|
|||
return color;
|
||||
}
|
||||
|
||||
// #ifndef _NoShadows
|
||||
// float shadowTest(const vec3 lPos) {
|
||||
// return PCF(shadowMap, lPos.xy, lPos.z - shadowsBias);
|
||||
// }
|
||||
// float shadowTestCube(const vec3 lp, const vec3 l) {
|
||||
// return PCFCube(shadowMapCube, lp, -l, shadowsBias, lightPlane);
|
||||
// }
|
||||
// #endif
|
||||
|
||||
void main() {
|
||||
float gdepth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
// vec4 colorOriginal = vec4(1.0);//texture(tex, texCoord);
|
||||
|
@ -326,16 +305,4 @@ void main() {
|
|||
|
||||
fragColor.rgb = color;
|
||||
fragColor.a = clamp(depthZ * seaFade, 0.0, 1.0);
|
||||
|
||||
// #ifndef _NoShadows
|
||||
// if (lightShadow == 1) {
|
||||
// vec4 lightPosition = LWVP * vec4(surfacePoint.xyz, 1.0);
|
||||
// if (lightPosition.w > 0.0) fragColor.rgb *= shadowTest(lightPosition.xyz / lightPosition.w);
|
||||
// }
|
||||
// else if (lightShadow == 2) { // Cube
|
||||
// vec3 lp = lightPos - surfacePoint.xyz;
|
||||
// vec3 l = normalize(lp);
|
||||
// fragColor.rgb *= shadowTestCube(lp, l);
|
||||
// }
|
||||
// #endif
|
||||
}
|
||||
|
|
|
@ -44,31 +44,6 @@
|
|||
"name": "envmapStrength",
|
||||
"link": "_envmapStrength"
|
||||
},
|
||||
{
|
||||
"name": "LWVP",
|
||||
"link": "_biasLightWorldViewProjectionMatrix",
|
||||
"ifdef": ["_Disabled"]
|
||||
},
|
||||
{
|
||||
"name": "shadowsBias",
|
||||
"link": "_lightShadowsBias",
|
||||
"ifdef": ["_Disabled"]
|
||||
},
|
||||
{
|
||||
"name": "lightPlane",
|
||||
"link": "_lightPlane",
|
||||
"ifdef": ["_Disabled"]
|
||||
},
|
||||
{
|
||||
"name": "lightShadow",
|
||||
"link": "_lightCastShadow",
|
||||
"ifdef": ["_Disabled"]
|
||||
},
|
||||
{
|
||||
"name": "lightPos",
|
||||
"link": "_lightPosition",
|
||||
"ifdef": ["_Disabled"]
|
||||
},
|
||||
{
|
||||
"name": "cameraProj",
|
||||
"link": "_cameraPlaneProj"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
uniform vec3 H;
|
||||
uniform vec3 I;
|
||||
uniform vec3 Z;
|
||||
uniform vec3 sunDirection;
|
||||
uniform vec3 hosekSunDirection;
|
||||
#endif
|
||||
#ifdef _EnvClouds
|
||||
uniform sampler2D snoise;
|
||||
|
@ -108,7 +108,7 @@ vec3 cloudsColor(vec3 R, vec3 pos, vec3 dir) {
|
|||
float d = traced.x / 200.0 * traced.y + traced.x / 1500.0 * cloudsSecondary;
|
||||
const float g = cloudsEccentricity;
|
||||
#ifdef _EnvSky
|
||||
float cosAngle = dot(sunDirection, dir);
|
||||
float cosAngle = dot(hosekSunDirection, dir);
|
||||
#else // Predefined sun direction
|
||||
float cosAngle = dot(vec3(0.0, -1.0, 0.0), dir);
|
||||
#endif
|
||||
|
@ -151,7 +151,7 @@ void main() {
|
|||
float theta = atan(-n.y, n.x) + PI;
|
||||
|
||||
float cos_theta = clamp(n.z, 0.0, 1.0);
|
||||
float cos_gamma = dot(n, sunDirection);
|
||||
float cos_gamma = dot(n, hosekSunDirection);
|
||||
float gamma_val = acos(cos_gamma);
|
||||
|
||||
fragColor.rgb = Z * hosekWilkie(cos_theta, gamma_val, cos_gamma) * envmapStrength;
|
||||
|
|
|
@ -66,8 +66,8 @@
|
|||
"ifdef": ["_EnvSky"]
|
||||
},
|
||||
{
|
||||
"name": "sunDirection",
|
||||
"link": "_sunDirection",
|
||||
"name": "hosekSunDirection",
|
||||
"link": "_hosekSunDirection",
|
||||
"ifdef": ["_EnvSky"]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -43,35 +43,47 @@ class Inc {
|
|||
}
|
||||
|
||||
public static function bindShadowMap() {
|
||||
var target = shadowMapName();
|
||||
if (target == "shadowMapCube") {
|
||||
#if kha_webgl
|
||||
// Bind empty map to non-cubemap sampler
|
||||
path.bindTarget("arm_empty", "shadowMap");
|
||||
#end
|
||||
path.bindTarget("shadowMapCube", "shadowMapCube");
|
||||
}
|
||||
else {
|
||||
#if kha_webgl
|
||||
// Bind empty map to cubemap sampler
|
||||
path.bindTarget("arm_empty_cube", "shadowMapCube");
|
||||
#end
|
||||
if (path.sun != null && path.sun.data.raw.cast_shadow) {
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
}
|
||||
|
||||
for (l in iron.Scene.active.lights) {
|
||||
if (!l.visible || !l.data.raw.cast_shadow) continue;
|
||||
var n = shadowMapName(l);
|
||||
path.bindTarget(n, n);
|
||||
}
|
||||
|
||||
// var target = shadowMapName(l);
|
||||
// if (target == "shadowMapCube") {
|
||||
// #if kha_webgl
|
||||
// // Bind empty map to non-cubemap sampler
|
||||
// path.bindTarget("arm_empty", "shadowMap");
|
||||
// #end
|
||||
// path.bindTarget("shadowMapCube", "shadowMapCube");
|
||||
// }
|
||||
// else {
|
||||
// #if kha_webgl
|
||||
// // Bind empty map to cubemap sampler
|
||||
// path.bindTarget("arm_empty_cube", "shadowMapCube");
|
||||
// #end
|
||||
// path.bindTarget("shadowMap", "shadowMap");
|
||||
// }
|
||||
}
|
||||
|
||||
public static function shadowMapName():String {
|
||||
return path.getLight(path.currentLightIndex).data.raw.shadowmap_cube ? "shadowMapCube" : "shadowMap";
|
||||
static function shadowMapName(l:iron.object.LightObject):String {
|
||||
if (l.data.raw.type == "sun") return "shadowMap";
|
||||
if (l.data.raw.type == "point") return "shadowMap0";
|
||||
else return "shadowMapSpot0";
|
||||
}
|
||||
|
||||
public static function getShadowMap():String {
|
||||
var target = shadowMapName();
|
||||
static function getShadowMap(l:iron.object.LightObject):String {
|
||||
var target = shadowMapName(l);
|
||||
var rt = path.renderTargets.get(target);
|
||||
// Create shadowmap on the fly
|
||||
if (rt == null) {
|
||||
if (path.getLight(path.currentLightIndex).data.raw.shadowmap_cube) {
|
||||
if (path.light.data.raw.shadowmap_cube) {
|
||||
// Cubemap size
|
||||
var size = Std.int(path.getLight(path.currentLightIndex).data.raw.shadowmap_size);
|
||||
var size = Std.int(path.light.data.raw.shadowmap_size);
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = target;
|
||||
t.width = size;
|
||||
|
@ -81,7 +93,7 @@ class Inc {
|
|||
rt = path.createRenderTarget(t);
|
||||
}
|
||||
else { // Non-cube sm
|
||||
var sizew = path.getLight(path.currentLightIndex).data.raw.shadowmap_size;
|
||||
var sizew = path.light.data.raw.shadowmap_size;
|
||||
var sizeh = sizew;
|
||||
#if arm_csm // Cascades - atlas on x axis
|
||||
sizew = sizeh * iron.object.LightObject.cascadeCount;
|
||||
|
@ -96,12 +108,66 @@ class Inc {
|
|||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public static function drawShadowMap() {
|
||||
#if (rp_shadowmap)
|
||||
|
||||
for (l in iron.Scene.active.lights) {
|
||||
if (!l.visible || !l.data.raw.cast_shadow) continue;
|
||||
path.light = l;
|
||||
|
||||
var faces = l.data.raw.shadowmap_cube ? 6 : 1;
|
||||
for (i in 0...faces) {
|
||||
if (faces > 1) path.currentFace = i;
|
||||
path.setTarget(Inc.getShadowMap(l));
|
||||
path.clearTarget(null, 1.0);
|
||||
path.drawMeshes("shadowmap");
|
||||
}
|
||||
path.currentFace = -1;
|
||||
}
|
||||
|
||||
// One light at a time for now, precompute all lights for tiled
|
||||
// #if rp_soft_shadows
|
||||
|
||||
// if (l.raw.type != "point") {
|
||||
// path.setTarget("visa"); // Merge using min blend
|
||||
// Inc.bindShadowMap();
|
||||
// path.drawShader("shader_datas/dilate_pass/dilate_pass_x");
|
||||
|
||||
// path.setTarget("visb");
|
||||
// path.bindTarget("visa", "shadowMap");
|
||||
// path.drawShader("shader_datas/dilate_pass/dilate_pass_y");
|
||||
// }
|
||||
|
||||
// path.setTarget("visa", ["dist"]);
|
||||
// //if (i == 0) path.clearTarget(0x00000000);
|
||||
// if (l.raw.type != "point") path.bindTarget("visb", "dilate");
|
||||
// Inc.bindShadowMap();
|
||||
// //path.bindTarget("_main", "gbufferD");
|
||||
// path.bindTarget("gbuffer0", "gbuffer0");
|
||||
// path.drawShader("shader_datas/visibility_pass/visibility_pass");
|
||||
|
||||
// path.setTarget("visb");
|
||||
// path.bindTarget("visa", "tex");
|
||||
// path.bindTarget("gbuffer0", "gbuffer0");
|
||||
// path.bindTarget("dist", "dist");
|
||||
// path.drawShader("shader_datas/blur_shadow_pass/blur_shadow_pass_x");
|
||||
|
||||
// path.setTarget("visa");
|
||||
// path.bindTarget("visb", "tex");
|
||||
// path.bindTarget("gbuffer0", "gbuffer0");
|
||||
// path.bindTarget("dist", "dist");
|
||||
// path.drawShader("shader_datas/blur_shadow_pass/blur_shadow_pass_y");
|
||||
// #end
|
||||
|
||||
#end // rp_shadowmap
|
||||
}
|
||||
|
||||
public static function applyConfig() {
|
||||
#if arm_config
|
||||
var config = armory.data.Config.raw;
|
||||
// Resize shadow map
|
||||
var l = path.getLight(path.currentLightIndex);
|
||||
var l = path.light;
|
||||
if (l.data.raw.shadowmap_size != config.rp_shadowmap) {
|
||||
l.data.raw.shadowmap_size = config.rp_shadowmap;
|
||||
var rt = path.renderTargets.get("shadowMap");
|
||||
|
@ -331,22 +397,13 @@ class Inc {
|
|||
// if (!l.visible) continue;
|
||||
// path.currentLightIndex = i;
|
||||
|
||||
// #if (rp_shadowmap)
|
||||
// {
|
||||
// TODO: merge with direct, drawing shadowmaps twice!
|
||||
// if (path.lightCastShadow()) {
|
||||
// drawShadowMap(l);
|
||||
// }
|
||||
// }
|
||||
// #end
|
||||
|
||||
kha.compute.Compute.setShader(voxel_sh);
|
||||
kha.compute.Compute.setTexture(voxel_ta, rts.get("voxelsOpac").image, kha.compute.Access.Read);
|
||||
kha.compute.Compute.setTexture(voxel_tb, rts.get("voxelsNor").image, kha.compute.Access.Read);
|
||||
kha.compute.Compute.setTexture(voxel_tc, rts.get("voxels").image, kha.compute.Access.Write);
|
||||
|
||||
#if (rp_shadowmap)
|
||||
if (Inc.shadowMapName() == "shadowMapCube") {
|
||||
if (Inc.shadowMapName(l) == "shadowMapCube") {
|
||||
// shadowMapCube
|
||||
kha.compute.Compute.setSampledCubeMap(voxel_te, rts.get("shadowMapCube").cubeMap);
|
||||
}
|
||||
|
@ -394,7 +451,6 @@ class Inc {
|
|||
|
||||
kha.compute.Compute.compute(res, res, res);
|
||||
// }
|
||||
// path.currentLightIndex = 0;
|
||||
}
|
||||
public static function computeVoxelsEnd() {
|
||||
var rts = path.renderTargets;
|
||||
|
@ -419,67 +475,4 @@ class Inc {
|
|||
#end
|
||||
}
|
||||
#end
|
||||
|
||||
#if (rp_renderer == "Forward")
|
||||
public static function drawShadowMap(l:iron.object.LightObject) {
|
||||
#if (rp_shadowmap)
|
||||
var faces = l.data.raw.shadowmap_cube ? 6 : 1;
|
||||
for (i in 0...faces) {
|
||||
if (faces > 1) path.currentFace = i;
|
||||
path.setTarget(Inc.getShadowMap());
|
||||
path.clearTarget(null, 1.0);
|
||||
path.drawMeshes("shadowmap");
|
||||
}
|
||||
path.currentFace = -1;
|
||||
#end
|
||||
}
|
||||
#else
|
||||
public static function drawShadowMap(l:iron.object.LightObject) {
|
||||
#if (rp_shadowmap)
|
||||
var faces = l.data.raw.shadowmap_cube ? 6 : 1;
|
||||
for (i in 0...faces) {
|
||||
if (faces > 1) path.currentFace = i;
|
||||
path.setTarget(Inc.getShadowMap());
|
||||
path.clearTarget(null, 1.0);
|
||||
path.drawMeshes("shadowmap");
|
||||
}
|
||||
path.currentFace = -1;
|
||||
|
||||
// One light at a time for now, precompute all lights for tiled
|
||||
#if rp_soft_shadows
|
||||
|
||||
if (l.raw.type != "point") {
|
||||
path.setTarget("visa"); // Merge using min blend
|
||||
Inc.bindShadowMap();
|
||||
path.drawShader("shader_datas/dilate_pass/dilate_pass_x");
|
||||
|
||||
path.setTarget("visb");
|
||||
path.bindTarget("visa", "shadowMap");
|
||||
path.drawShader("shader_datas/dilate_pass/dilate_pass_y");
|
||||
}
|
||||
|
||||
path.setTarget("visa", ["dist"]);
|
||||
//if (i == 0) path.clearTarget(0x00000000);
|
||||
if (l.raw.type != "point") path.bindTarget("visb", "dilate");
|
||||
Inc.bindShadowMap();
|
||||
//path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.drawShader("shader_datas/visibility_pass/visibility_pass");
|
||||
|
||||
path.setTarget("visb");
|
||||
path.bindTarget("visa", "tex");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("dist", "dist");
|
||||
path.drawShader("shader_datas/blur_shadow_pass/blur_shadow_pass_x");
|
||||
|
||||
path.setTarget("visa");
|
||||
path.bindTarget("visb", "tex");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("dist", "dist");
|
||||
path.drawShader("shader_datas/blur_shadow_pass/blur_shadow_pass_y");
|
||||
#end
|
||||
|
||||
#end
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class RenderPathDeferred {
|
|||
}
|
||||
#end
|
||||
#if (rp_gi == "Voxel AO")
|
||||
path.loadShader("shader_datas/deferred_indirect/deferred_indirect_VoxelAOvar");
|
||||
path.loadShader("shader_datas/deferred_light/deferred_light_VoxelAOvar");
|
||||
#end
|
||||
}
|
||||
#end
|
||||
|
@ -143,9 +143,7 @@ class RenderPathDeferred {
|
|||
}
|
||||
#end
|
||||
|
||||
path.loadShader("shader_datas/deferred_indirect/deferred_indirect");
|
||||
path.loadShader("shader_datas/deferred_light/deferred_light");
|
||||
path.loadShader("shader_datas/deferred_light_quad/deferred_light_quad");
|
||||
|
||||
#if rp_probes
|
||||
path.loadShader("shader_datas/probe_planar/probe_planar");
|
||||
|
@ -536,11 +534,32 @@ class RenderPathDeferred {
|
|||
}
|
||||
#end
|
||||
|
||||
// Indirect
|
||||
// ---
|
||||
// Deferred light
|
||||
// ---
|
||||
var lights = iron.Scene.active.lights;
|
||||
|
||||
// #if (rp_gi == "Voxel GI")
|
||||
// if (relight) Inc.computeVoxelsBegin();
|
||||
// #end
|
||||
// #if (rp_gi == "Voxel GI")
|
||||
// if (relight) Inc.computeVoxels(i);
|
||||
// #end
|
||||
// #if (rp_gi == "Voxel GI")
|
||||
// if (relight) Inc.computeVoxelsEnd();
|
||||
// #end
|
||||
|
||||
#if (rp_shadowmap)
|
||||
Inc.drawShadowMap();
|
||||
#end
|
||||
|
||||
path.setTarget("tex");
|
||||
// path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("gbuffer1", "gbuffer1");
|
||||
// #if rp_gbuffer2_direct
|
||||
// path.bindTarget("gbuffer2", "gbuffer2");
|
||||
// #end
|
||||
#if (rp_ssgi != "Off")
|
||||
{
|
||||
if (armory.data.Config.raw.rp_ssgi != false) {
|
||||
|
@ -566,15 +585,23 @@ class RenderPathDeferred {
|
|||
#end
|
||||
}
|
||||
#end
|
||||
|
||||
if (voxelao_pass) {
|
||||
path.drawShader("shader_datas/deferred_indirect/deferred_indirect_VoxelAOvar");
|
||||
}
|
||||
else {
|
||||
path.drawShader("shader_datas/deferred_indirect/deferred_indirect");
|
||||
}
|
||||
|
||||
#if rp_shadowmap
|
||||
{
|
||||
// if (path.lightCastShadow()) {
|
||||
#if rp_soft_shadows
|
||||
path.bindTarget("visa", "svisibility");
|
||||
#else
|
||||
Inc.bindShadowMap();
|
||||
#end
|
||||
// }
|
||||
}
|
||||
#end
|
||||
|
||||
voxelao_pass ?
|
||||
path.drawShader("shader_datas/deferred_light/deferred_light_VoxelAOvar") :
|
||||
path.drawShader("shader_datas/deferred_light/deferred_light");
|
||||
|
||||
#if rp_probes
|
||||
if (!path.isProbe) {
|
||||
var probes = iron.Scene.active.probes;
|
||||
|
@ -596,87 +623,27 @@ class RenderPathDeferred {
|
|||
}
|
||||
#end
|
||||
|
||||
// Direct
|
||||
var lights = iron.Scene.active.lights;
|
||||
#if (rp_gi == "Voxel GI")
|
||||
if (relight) Inc.computeVoxelsBegin();
|
||||
#end
|
||||
for (i in 0...lights.length) {
|
||||
var l = lights[i];
|
||||
if (!l.visible) continue;
|
||||
path.currentLightIndex = i;
|
||||
// #if rp_volumetriclight
|
||||
// {
|
||||
// path.setTarget("bufvola");
|
||||
// path.bindTarget("_main", "gbufferD");
|
||||
// Inc.bindShadowMap();
|
||||
// if (path.lightIsSun()) {
|
||||
// path.drawShader("shader_datas/volumetric_light_quad/volumetric_light_quad");
|
||||
// }
|
||||
// else {
|
||||
// path.drawLightVolume("shader_datas/volumetric_light/volumetric_light");
|
||||
// }
|
||||
|
||||
#if (rp_shadowmap)
|
||||
{
|
||||
if (path.lightCastShadow()) {
|
||||
Inc.drawShadowMap(l);
|
||||
}
|
||||
}
|
||||
#end
|
||||
// path.setTarget("bufvolb");
|
||||
// path.bindTarget("bufvola", "tex");
|
||||
// path.drawShader("shader_datas/blur_bilat_pass/blur_bilat_pass_x");
|
||||
|
||||
#if (rp_gi == "Voxel GI")
|
||||
if (relight) Inc.computeVoxels(i);
|
||||
#end
|
||||
|
||||
path.setTarget("tex");
|
||||
// path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("gbuffer1", "gbuffer1");
|
||||
#if rp_gbuffer2_direct
|
||||
path.bindTarget("gbuffer2", "gbuffer2");
|
||||
#end
|
||||
|
||||
#if rp_shadowmap
|
||||
{
|
||||
if (path.lightCastShadow()) {
|
||||
#if rp_soft_shadows
|
||||
path.bindTarget("visa", "svisibility");
|
||||
#else
|
||||
Inc.bindShadowMap();
|
||||
#end
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
#if (rp_voxelgi_shadows)
|
||||
{
|
||||
path.bindTarget(voxels, "voxels");
|
||||
}
|
||||
#end
|
||||
|
||||
if (path.lightIsSun()) {
|
||||
path.drawShader("shader_datas/deferred_light_quad/deferred_light_quad");
|
||||
}
|
||||
else {
|
||||
path.drawLightVolume("shader_datas/deferred_light/deferred_light");
|
||||
}
|
||||
|
||||
#if rp_volumetriclight
|
||||
{
|
||||
path.setTarget("bufvola");
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
Inc.bindShadowMap();
|
||||
if (path.lightIsSun()) {
|
||||
path.drawShader("shader_datas/volumetric_light_quad/volumetric_light_quad");
|
||||
}
|
||||
else {
|
||||
path.drawLightVolume("shader_datas/volumetric_light/volumetric_light");
|
||||
}
|
||||
|
||||
path.setTarget("bufvolb");
|
||||
path.bindTarget("bufvola", "tex");
|
||||
path.drawShader("shader_datas/blur_bilat_pass/blur_bilat_pass_x");
|
||||
|
||||
path.setTarget("tex");
|
||||
path.bindTarget("bufvolb", "tex");
|
||||
path.drawShader("shader_datas/blur_bilat_blend_pass/blur_bilat_blend_pass_y");
|
||||
}
|
||||
#end
|
||||
}
|
||||
path.currentLightIndex = 0;
|
||||
#if (rp_gi == "Voxel GI")
|
||||
if (relight) Inc.computeVoxelsEnd();
|
||||
#end
|
||||
// path.setTarget("tex");
|
||||
// path.bindTarget("bufvolb", "tex");
|
||||
// path.drawShader("shader_datas/blur_bilat_blend_pass/blur_bilat_blend_pass_y");
|
||||
// }
|
||||
// #end
|
||||
|
||||
#if (rp_background == "World")
|
||||
{
|
||||
|
|
|
@ -219,13 +219,9 @@ class RenderPathForward {
|
|||
|
||||
public static function commands() {
|
||||
|
||||
var hasLight = iron.Scene.active.lights.length > 0;
|
||||
|
||||
#if rp_shadowmap
|
||||
{
|
||||
if (hasLight) {
|
||||
Inc.drawShadowMap(iron.Scene.active.lights[0]);
|
||||
}
|
||||
Inc.drawShadowMap();
|
||||
}
|
||||
#end
|
||||
|
||||
|
@ -311,7 +307,7 @@ class RenderPathForward {
|
|||
|
||||
#if rp_shadowmap
|
||||
{
|
||||
if (hasLight) Inc.bindShadowMap();
|
||||
Inc.bindShadowMap();
|
||||
}
|
||||
#end
|
||||
|
||||
|
@ -338,27 +334,27 @@ class RenderPathForward {
|
|||
|
||||
#if rp_render_to_texture
|
||||
{
|
||||
#if rp_volumetriclight
|
||||
{
|
||||
path.setTarget("bufvola");
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
Inc.bindShadowMap();
|
||||
if (path.lightIsSun()) {
|
||||
path.drawShader("shader_datas/volumetric_light_quad/volumetric_light_quad");
|
||||
}
|
||||
else {
|
||||
path.drawLightVolume("shader_datas/volumetric_light/volumetric_light");
|
||||
}
|
||||
// #if rp_volumetriclight
|
||||
// {
|
||||
// path.setTarget("bufvola");
|
||||
// path.bindTarget("_main", "gbufferD");
|
||||
// Inc.bindShadowMap();
|
||||
// if (path.lightIsSun()) {
|
||||
// path.drawShader("shader_datas/volumetric_light_quad/volumetric_light_quad");
|
||||
// }
|
||||
// else {
|
||||
// path.drawLightVolume("shader_datas/volumetric_light/volumetric_light");
|
||||
// }
|
||||
|
||||
path.setTarget("bufvolb");
|
||||
path.bindTarget("bufvola", "tex");
|
||||
path.drawShader("shader_datas/blur_bilat_pass/blur_bilat_pass_x");
|
||||
// path.setTarget("bufvolb");
|
||||
// path.bindTarget("bufvola", "tex");
|
||||
// path.drawShader("shader_datas/blur_bilat_pass/blur_bilat_pass_x");
|
||||
|
||||
path.setTarget("lbuf");
|
||||
path.bindTarget("bufvolb", "tex");
|
||||
path.drawShader("shader_datas/blur_bilat_blend_pass/blur_bilat_blend_pass_y");
|
||||
}
|
||||
#end
|
||||
// path.setTarget("lbuf");
|
||||
// path.bindTarget("bufvolb", "tex");
|
||||
// path.drawShader("shader_datas/blur_bilat_blend_pass/blur_bilat_blend_pass_y");
|
||||
// }
|
||||
// #end
|
||||
|
||||
#if rp_bloom
|
||||
{
|
||||
|
@ -423,6 +419,12 @@ class RenderPathForward {
|
|||
#if rp_compositordepth
|
||||
{
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
}
|
||||
#end
|
||||
|
||||
#if rp_compositornodes
|
||||
{
|
||||
path.bindTarget("lbuf", "tex");
|
||||
path.drawShader("shader_datas/compositor_pass/compositor_pass");
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -1768,9 +1768,7 @@ class ArmoryExporter:
|
|||
o['shadows_bias'] *= 1 / (o['shadowmap_size'] / 1024) # Less bias for bigger maps
|
||||
if (objtype == 'POINT' or objtype == 'SPOT') and objref.shadow_soft_size > 0.1:
|
||||
o['light_size'] = objref.shadow_soft_size * 10 # Match to Cycles
|
||||
gapi = arm.utils.get_gapi()
|
||||
mobile_mat = rpdat.arm_material_model == 'Mobile' or rpdat.arm_material_model == 'Solid'
|
||||
if objtype == 'POINT' and not mobile_mat and objref.arm_shadows_cubemap:
|
||||
if objtype == 'POINT' and rpdat.arm_shadows_cubemap:
|
||||
o['fov'] = 1.5708 # pi/2
|
||||
o['shadowmap_cube'] = True
|
||||
o['shadows_bias'] *= 2.0
|
||||
|
@ -1805,7 +1803,7 @@ class ArmoryExporter:
|
|||
break
|
||||
else:
|
||||
o['color'] = [objref.color[0], objref.color[1], objref.color[2]]
|
||||
o['strength'] = 1000.0 * 0.026
|
||||
o['strength'] = 100.0 * 0.026
|
||||
o['type'] = 'point'
|
||||
|
||||
self.output['light_datas'].append(o)
|
||||
|
|
|
@ -44,16 +44,16 @@ def add_world_defs():
|
|||
elif rpdat.rp_gi == 'Voxel AO':
|
||||
voxelao = True
|
||||
# Shadows
|
||||
if rpdat.rp_shadowmap == 'Off':
|
||||
wrd.world_defs += '_NoShadows'
|
||||
assets.add_khafile_def('arm_no_shadows')
|
||||
else:
|
||||
if rpdat.rp_shadowmap != 'Off':
|
||||
wrd.world_defs += '_ShadowMap'
|
||||
if rpdat.rp_shadowmap_cascades != '1':
|
||||
if voxelgi:
|
||||
log.warn('Disabling shadow cascades - Voxel GI does not support cascades yet')
|
||||
else:
|
||||
wrd.world_defs += '_CSM'
|
||||
assets.add_khafile_def('arm_csm')
|
||||
if rpdat.arm_shadows_cubemap:
|
||||
wrd.world_defs += '_ShadowMapCube'
|
||||
# SS
|
||||
if rpdat.rp_ssgi == 'RTGI' or rpdat.rp_ssgi == 'RTAO':
|
||||
if rpdat.rp_ssgi == 'RTGI':
|
||||
|
@ -81,7 +81,6 @@ def add_world_defs():
|
|||
assets.add_khafile_def('rp_gi_bounces={0}'.format(rpdat.arm_voxelgi_bounces))
|
||||
assets.add_shader_external(arm.utils.get_sdk_path() + '/armory/Shaders/voxel_bounce/voxel_bounce.comp.glsl')
|
||||
if rpdat.arm_voxelgi_shadows:
|
||||
wrd.world_defs += '_VoxelGIDirect'
|
||||
wrd.world_defs += '_VoxelGIShadow'
|
||||
if rpdat.rp_voxelgi_relight:
|
||||
assets.add_khafile_def('rp_voxelgi_relight')
|
||||
|
@ -94,18 +93,24 @@ def add_world_defs():
|
|||
if arm.utils.get_legacy_shaders() and not state.is_viewport:
|
||||
wrd.world_defs += '_Legacy'
|
||||
|
||||
# Area lights
|
||||
# Light defines
|
||||
lights = bpy.data.lights if bpy.app.version >= (2, 80, 1) else bpy.data.lamps
|
||||
for light in lights:
|
||||
if light.type == 'AREA':
|
||||
if light.type == 'AREA' and '_LTC' not in wrd.world_defs:
|
||||
wrd.world_defs += '_LTC'
|
||||
assets.add_khafile_def('arm_ltc')
|
||||
break
|
||||
if light.type == 'SUN' and '_Sun' not in wrd.world_defs:
|
||||
wrd.world_defs += '_Sun'
|
||||
if light.type == 'POINT' or light.type == 'SPOT':
|
||||
if '_Clusters' not in wrd.world_defs:
|
||||
wrd.world_defs += '_Clusters'
|
||||
assets.add_khafile_def('arm_clusters')
|
||||
if light.type == 'SPOT' and '_Spot' not in wrd.world_defs:
|
||||
wrd.world_defs += '_Spot'
|
||||
assets.add_khafile_def('arm_spot')
|
||||
|
||||
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()
|
||||
|
@ -143,9 +148,9 @@ def build():
|
|||
assets.add_embedded_data('noise256.png')
|
||||
|
||||
if rpdat.rp_renderer == 'Deferred' and not rpdat.rp_compositornodes:
|
||||
assets.add_shader_pass('copy_pass')
|
||||
if rpdat.rp_renderer == 'Forward' and not rpdat.rp_compositornodes and rpdat.rp_render_to_texture:
|
||||
assets.add_shader_pass('copy_pass')
|
||||
assets.add_shader_pass('copy_pass')
|
||||
if rpdat.rp_renderer == 'Forward' and not rpdat.rp_compositornodes:
|
||||
assets.add_shader_pass('copy_pass')
|
||||
|
||||
if rpdat.rp_render_to_texture:
|
||||
assets.add_khafile_def('rp_render_to_texture')
|
||||
|
@ -262,9 +267,7 @@ def build():
|
|||
assets.add_shader_pass('ssgi_blur_pass')
|
||||
|
||||
if rpdat.rp_renderer == 'Deferred':
|
||||
assets.add_shader_pass('deferred_indirect')
|
||||
assets.add_shader_pass('deferred_light')
|
||||
assets.add_shader_pass('deferred_light_quad')
|
||||
|
||||
if bpy.app.version >= (2, 80, 1) and len(bpy.data.lightprobes) > 0:
|
||||
wrd.world_defs += '_Probes'
|
||||
|
@ -273,14 +276,14 @@ def build():
|
|||
assets.add_shader_pass('probe_cubemap')
|
||||
assets.add_shader_pass('copy_pass')
|
||||
|
||||
if rpdat.rp_volumetriclight:
|
||||
assets.add_khafile_def('rp_volumetriclight')
|
||||
assets.add_shader_pass('volumetric_light_quad')
|
||||
assets.add_shader_pass('volumetric_light')
|
||||
assets.add_shader_pass('blur_bilat_pass')
|
||||
assets.add_shader_pass('blur_bilat_blend_pass')
|
||||
assets.add(assets_path + 'blue_noise64.png')
|
||||
assets.add_embedded_data('blue_noise64.png')
|
||||
# if rpdat.rp_volumetriclight:
|
||||
# assets.add_khafile_def('rp_volumetriclight')
|
||||
# assets.add_shader_pass('volumetric_light_quad')
|
||||
# assets.add_shader_pass('volumetric_light')
|
||||
# assets.add_shader_pass('blur_bilat_pass')
|
||||
# assets.add_shader_pass('blur_bilat_blend_pass')
|
||||
# assets.add(assets_path + 'blue_noise64.png')
|
||||
# assets.add_embedded_data('blue_noise64.png')
|
||||
|
||||
if rpdat.rp_decals:
|
||||
assets.add_khafile_def('rp_decals')
|
||||
|
@ -325,17 +328,17 @@ def build():
|
|||
if rpdat.rp_dynres:
|
||||
assets.add_khafile_def('rp_dynres')
|
||||
|
||||
if rpdat.arm_soft_shadows == 'On':
|
||||
if rpdat.rp_shadowmap_cascades == '1':
|
||||
assets.add_shader_pass('dilate_pass')
|
||||
assets.add_shader_pass('visibility_pass')
|
||||
assets.add_shader_pass('blur_shadow_pass')
|
||||
assets.add_khafile_def('rp_soft_shadows')
|
||||
wrd.world_defs += '_SoftShadows'
|
||||
if rpdat.arm_soft_shadows_penumbra != 1:
|
||||
wrd.world_defs += '_PenumbraScale'
|
||||
else:
|
||||
log.warn('Disabling soft shadows - "Armory Render Path - Cascades" requires to be set to 1 for now')
|
||||
# if rpdat.arm_soft_shadows == 'On':
|
||||
# if rpdat.rp_shadowmap_cascades == '1':
|
||||
# assets.add_shader_pass('dilate_pass')
|
||||
# assets.add_shader_pass('visibility_pass')
|
||||
# assets.add_shader_pass('blur_shadow_pass')
|
||||
# assets.add_khafile_def('rp_soft_shadows')
|
||||
# wrd.world_defs += '_SoftShadows'
|
||||
# if rpdat.arm_soft_shadows_penumbra != 1:
|
||||
# wrd.world_defs += '_PenumbraScale'
|
||||
# else:
|
||||
# log.warn('Disabling soft shadows - "Armory Render Path - Cascades" requires to be set to 1 for now')
|
||||
|
||||
gbuffer2_direct = '_SSS' in wrd.world_defs or '_Hair' in wrd.world_defs
|
||||
gbuffer2 = '_Veloc' in wrd.world_defs or gbuffer2_direct
|
||||
|
|
|
@ -178,7 +178,7 @@ def make_base(con_mesh, parse_opacity):
|
|||
tese = None
|
||||
|
||||
vert.add_uniform('mat3 N', '_normalMatrix')
|
||||
vert.write_attrib(' vec4 spos = vec4(pos, 1.0);')
|
||||
vert.write_attrib('vec4 spos = vec4(pos, 1.0);')
|
||||
|
||||
vattr_written = False
|
||||
rpdat = arm.utils.get_rp()
|
||||
|
@ -469,37 +469,6 @@ def make_forward_mobile(con_mesh):
|
|||
|
||||
frag.add_include('std/math.glsl')
|
||||
frag.add_include('std/brdf.glsl')
|
||||
frag.add_uniform('vec3 lightColor', '_lightColor')
|
||||
frag.add_uniform('vec3 lightDir', '_lightDirection')
|
||||
frag.add_uniform('vec3 lightPos', '_lightPosition')
|
||||
frag.add_uniform('float envmapStrength', link='_envmapStrength')
|
||||
|
||||
is_shadows = not '_NoShadows' in wrd.world_defs
|
||||
|
||||
frag.write('float visibility = 1.0;')
|
||||
frag.write('float dotNL = max(dot(n, lightDir), 0.0);')
|
||||
|
||||
if is_shadows:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrix')
|
||||
vert.write('lightPosition = LWVP * spos;')
|
||||
frag.add_include('std/shadows.glsl')
|
||||
frag.add_uniform('sampler2D shadowMap')
|
||||
frag.add_uniform('float shadowsBias', '_lightShadowsBias')
|
||||
frag.write(' if (lightPosition.w > 0.0) {')
|
||||
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write(' const float texelSize = 1.0 / shadowmapSize.x;')
|
||||
frag.write(' visibility = 0.0;')
|
||||
# TODO: CSM
|
||||
frag.write(' visibility += float(texture(shadowMap, lPos.xy).r + shadowsBias > lPos.z);')
|
||||
frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.5;')
|
||||
frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(-texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.25;')
|
||||
frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(0.0, texelSize)).r + shadowsBias > lPos.z) * 0.5;')
|
||||
frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(0.0, -texelSize)).r + shadowsBias > lPos.z) * 0.25;')
|
||||
frag.write(' visibility /= 2.5;')
|
||||
frag.write(' visibility = max(visibility, 0.2);')
|
||||
# frag.write(' visibility = max(float(texture(shadowMap, lPos.xy).r + shadowsBias > lPos.z), 0.5);')
|
||||
frag.write(' }')
|
||||
|
||||
frag.add_out('vec4 fragColor')
|
||||
blend = mat_state.material.arm_blending
|
||||
|
@ -510,9 +479,66 @@ def make_forward_mobile(con_mesh):
|
|||
frag.write('fragColor = vec4(basecol, 1.0);')
|
||||
return
|
||||
|
||||
frag.write('vec3 direct = basecol * dotNL * lightColor;')
|
||||
# frag.write('direct += vec3(D_Approx(max(roughness, 0.3), dot(reflect(-vVec, n), lightDir)));')
|
||||
frag.write('direct *= attenuate(distance(wposition, lightPos));')
|
||||
is_shadows = '_ShadowMap' in wrd.world_defs
|
||||
if is_shadows:
|
||||
frag.add_include('std/shadows.glsl')
|
||||
|
||||
frag.write('vec3 direct = vec3(0.0);')
|
||||
|
||||
if '_Sun' in wrd.world_defs:
|
||||
frag.add_uniform('vec3 sunCol', '_sunColor')
|
||||
frag.add_uniform('vec3 sunDir', '_sunDirection')
|
||||
frag.write('float svisibility = 1.0;')
|
||||
frag.write('float sdotNL = max(dot(n, sunDir), 0.0);')
|
||||
if is_shadows:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrix')
|
||||
vert.write('lightPosition = LWVP * spos;')
|
||||
frag.add_uniform('sampler2D shadowMap')
|
||||
frag.add_uniform('float shadowsBias', '_sunShadowsBias')
|
||||
frag.write('if (lightPosition.w > 0.0) {')
|
||||
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write(' const float texelSize = 1.0 / shadowmapSize.x;')
|
||||
frag.write(' svisibility = 0.0;')
|
||||
frag.write(' svisibility += float(texture(shadowMap, lPos.xy).r + shadowsBias > lPos.z);')
|
||||
frag.write(' svisibility += float(texture(shadowMap, lPos.xy + vec2(texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.5;')
|
||||
frag.write(' svisibility += float(texture(shadowMap, lPos.xy + vec2(-texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.25;')
|
||||
frag.write(' svisibility += float(texture(shadowMap, lPos.xy + vec2(0.0, texelSize)).r + shadowsBias > lPos.z) * 0.5;')
|
||||
frag.write(' svisibility += float(texture(shadowMap, lPos.xy + vec2(0.0, -texelSize)).r + shadowsBias > lPos.z) * 0.25;')
|
||||
frag.write(' svisibility /= 2.5;')
|
||||
frag.write(' svisibility = max(svisibility, 0.2);')
|
||||
# frag.write(' svisibility = max(float(texture(shadowMap, lPos.xy).r + shadowsBias > lPos.z), 0.5);')
|
||||
frag.write('}')
|
||||
frag.write('direct += basecol * sdotNL * sunCol * svisibility;')
|
||||
|
||||
if '_Clusters' in wrd.world_defs and '_Sun' not in wrd.world_defs:
|
||||
frag.add_include('std/clusters.glsl')
|
||||
frag.add_uniform('vec3 lightPos', '_lightPosition')
|
||||
frag.add_uniform('vec3 lightCol', '_lightColor')
|
||||
frag.add_uniform('vec3 lightDir', '_lightDirection')
|
||||
frag.write('float visibility = 1.0;')
|
||||
frag.write('float dotNL = max(dot(n, lightDir), 0.0);')
|
||||
if is_shadows:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrix')
|
||||
vert.write('lightPosition = LWVP * spos;')
|
||||
frag.add_uniform('sampler2D shadowMap0')
|
||||
frag.add_uniform('float shadowsBias', '_lightShadowsBias')
|
||||
frag.write('if (lightPosition.w > 0.0) {')
|
||||
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write(' const float texelSize = 1.0 / shadowmapSize.x;')
|
||||
frag.write(' visibility = 0.0;')
|
||||
frag.write(' visibility += float(texture(shadowMap0, lPos.xy).r + shadowsBias > lPos.z);')
|
||||
frag.write(' visibility += float(texture(shadowMap0, lPos.xy + vec2(texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.5;')
|
||||
frag.write(' visibility += float(texture(shadowMap0, lPos.xy + vec2(-texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.25;')
|
||||
frag.write(' visibility += float(texture(shadowMap0, lPos.xy + vec2(0.0, texelSize)).r + shadowsBias > lPos.z) * 0.5;')
|
||||
frag.write(' visibility += float(texture(shadowMap0, lPos.xy + vec2(0.0, -texelSize)).r + shadowsBias > lPos.z) * 0.25;')
|
||||
frag.write(' visibility /= 2.5;')
|
||||
frag.write(' visibility = max(visibility, 0.2);')
|
||||
# frag.write(' visibility = max(float(texture(shadowMap0, lPos.xy).r + shadowsBias > lPos.z), 0.5);')
|
||||
frag.write('}')
|
||||
frag.write('direct += basecol * dotNL * lightCol * attenuate(distance(wposition, lightPos)) * visibility;')
|
||||
# frag.write('direct += vec3(D_Approx(max(roughness, 0.3), dot(reflect(-vVec, n), lightDir)));')
|
||||
|
||||
if '_Irr' in wrd.world_defs:
|
||||
frag.add_include('std/shirr.glsl')
|
||||
|
@ -520,7 +546,9 @@ def make_forward_mobile(con_mesh):
|
|||
env_str = 'shIrradiance(n)'
|
||||
else:
|
||||
env_str = '0.5'
|
||||
frag.write('fragColor = vec4(direct * visibility + basecol * {0} * envmapStrength, 1.0);'.format(env_str))
|
||||
|
||||
frag.add_uniform('float envmapStrength', link='_envmapStrength')
|
||||
frag.write('fragColor = vec4(direct + basecol * {0} * envmapStrength, 1.0);'.format(env_str))
|
||||
|
||||
if '_LDR' in wrd.world_defs:
|
||||
frag.write('fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));')
|
||||
|
@ -596,7 +624,7 @@ def make_forward(con_mesh):
|
|||
|
||||
if not blend:
|
||||
frag.add_out('vec4 fragColor')
|
||||
frag.write('fragColor = vec4(direct * lightColor * visibility + indirect * occlusion, 1.0);')
|
||||
frag.write('fragColor = vec4(direct * lightCol * visibility + indirect * occlusion, 1.0);')
|
||||
|
||||
if '_LDR' in wrd.world_defs:
|
||||
frag.add_include('std/tonemap.glsl')
|
||||
|
@ -622,6 +650,17 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
opac = mat_state.material.arm_discard_opacity
|
||||
frag.write('if (opacity < {0}) discard;'.format(opac))
|
||||
|
||||
blend = mat_state.material.arm_blending
|
||||
if blend:
|
||||
frag.add_out('vec4 fragColor')
|
||||
if parse_opacity:
|
||||
frag.write('fragColor = vec4(basecol, opacity);')
|
||||
else:
|
||||
# frag.write('fragColor = vec4(basecol * lightCol * visibility, 1.0);')
|
||||
frag.write('fragColor = vec4(basecol, 1.0);')
|
||||
# TODO: Fade out fragments near depth buffer here
|
||||
return
|
||||
|
||||
frag.write_init("""
|
||||
vec3 vVec = normalize(eyeDir);
|
||||
float dotNV = max(dot(n, vVec), 0.0);
|
||||
|
@ -632,152 +671,144 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
sh.add_uniform('vec3 eye', '_cameraPosition')
|
||||
sh.write('eyeDir = eye - wposition;')
|
||||
|
||||
frag.add_include('compiled.inc')
|
||||
frag.add_include('std/brdf.glsl')
|
||||
frag.add_include('std/math.glsl')
|
||||
frag.add_uniform('vec3 lightColor', '_lightColor')
|
||||
frag.add_uniform('vec3 lightDir', '_lightDirection')
|
||||
frag.add_uniform('vec3 lightPos', '_lightPosition')
|
||||
frag.add_uniform('int lightType', '_lightType')
|
||||
frag.add_uniform('vec2 spotlightData', '_spotlightData') # 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('int envmapNumMipmaps', link='_envmapNumMipmaps')
|
||||
|
||||
is_shadows = not '_NoShadows' in wrd.world_defs
|
||||
|
||||
frag.write('float visibility = 1.0;')
|
||||
frag.write('vec3 lp = lightPos - wposition;')
|
||||
frag.write('vec3 l;')
|
||||
frag.write('if (lightType == 0) l = lightDir;')
|
||||
frag.write('else { l = normalize(lp); visibility *= attenuate(distance(wposition, lightPos)); }')
|
||||
frag.write('vec3 h = normalize(vVec + l);')
|
||||
frag.write('float dotNL = dot(n, l);')
|
||||
frag.write('float dotNH = dot(n, h);')
|
||||
frag.write('float dotVH = dot(vVec, h);')
|
||||
|
||||
is_shadows = '_ShadowMap' in wrd.world_defs
|
||||
if is_shadows:
|
||||
if tese != None:
|
||||
tese.add_out('vec4 lightPosition')
|
||||
tese.add_uniform('mat4 LVP', '_biasLightViewProjectionMatrix')
|
||||
tese.add_uniform('int lightShadow', '_lightCastShadow')
|
||||
tese.write('if (lightShadow == 1) lightPosition = LVP * vec4(wposition, 1.0);')
|
||||
else:
|
||||
if is_displacement:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LVP', '_biasLightViewProjectionMatrix')
|
||||
vert.add_uniform('int lightShadow', '_lightCastShadow')
|
||||
vert.write('if (lightShadow == 1) lightPosition = LVP * vec4(wposition, 1.0);')
|
||||
else:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('int lightShadow', '_lightCastShadow')
|
||||
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrix')
|
||||
vert.write('if (lightShadow == 1) lightPosition = LWVP * spos;')
|
||||
|
||||
frag.add_include('std/shadows.glsl')
|
||||
frag.add_uniform('sampler2D shadowMap')
|
||||
frag.add_uniform('samplerCube shadowMapCube')
|
||||
frag.add_uniform('bool receiveShadow')
|
||||
frag.add_uniform('float shadowsBias', '_lightShadowsBias')
|
||||
frag.add_uniform('int lightShadow', '_lightCastShadow')
|
||||
frag.add_uniform('vec2 lightProj', '_lightPlaneProj')
|
||||
|
||||
frag.write('if (receiveShadow) {')
|
||||
frag.write(' if (lightShadow == 1) {')
|
||||
if '_CSM' in wrd.world_defs:
|
||||
frag.add_include('compiled.inc')
|
||||
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
|
||||
frag.add_uniform('vec3 eye', '_cameraPosition')
|
||||
frag.write('vec2 smSize;')
|
||||
frag.write('vec3 lPos;')
|
||||
frag.write('if (lightType == 0) {')
|
||||
frag.write(' int casi;')
|
||||
frag.write(' int casindex;')
|
||||
frag.write(' mat4 LWVP = getCascadeMat(distance(eye, wposition), casi, casindex);')
|
||||
frag.write(' vec4 lightPosition = LWVP * vec4(wposition, 1.0);')
|
||||
frag.write(' lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write(' smSize = shadowmapSize * vec2(shadowmapCascades, 1.0);')
|
||||
frag.write('}')
|
||||
frag.write('else {')
|
||||
frag.write(' lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write(' smSize = shadowmapSize;')
|
||||
frag.write('}')
|
||||
else:
|
||||
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write(' const vec2 smSize = shadowmapSize;')
|
||||
# frag.write('float bias = clamp(shadowsBias * 1.0 * tan(acos(clamp(dotNL, 0.0, 1.0))), 0.0, 0.01);')
|
||||
frag.write(' visibility *= PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize);')
|
||||
frag.write(' }')
|
||||
frag.write(' else if (lightShadow == 2) visibility *= PCFCube(shadowMapCube, lp, -l, shadowsBias, lightProj, n);')
|
||||
frag.write('}')
|
||||
|
||||
frag.write('if (lightType == 2) {')
|
||||
frag.write(' float spotEffect = dot(lightDir, l);')
|
||||
frag.write(' if (spotEffect < spotlightData.x) {')
|
||||
frag.write(' visibility *= smoothstep(spotlightData.y, spotlightData.x, spotEffect);')
|
||||
frag.write(' }')
|
||||
frag.write('}')
|
||||
|
||||
blend = mat_state.material.arm_blending
|
||||
if blend:
|
||||
frag.add_out('vec4 fragColor')
|
||||
if parse_opacity:
|
||||
frag.write('fragColor = vec4(basecol, opacity);')
|
||||
else:
|
||||
# frag.write('fragColor = vec4(basecol * lightColor * visibility, 1.0);')
|
||||
frag.write('fragColor = vec4(basecol, 1.0);')
|
||||
# TODO: Fade out fragments near depth buffer here
|
||||
return
|
||||
|
||||
frag.write('vec3 albedo = surfaceAlbedo(basecol, metallic);')
|
||||
frag.write('vec3 f0 = surfaceF0(basecol, metallic);')
|
||||
frag.write('vec3 direct;')
|
||||
frag.write('vec3 direct = vec3(0.0);')
|
||||
frag.add_uniform('bool receiveShadow')
|
||||
|
||||
if '_LTC' in wrd.world_defs:
|
||||
frag.add_include('std/ltc.glsl')
|
||||
frag.add_uniform('sampler2D sltcMat', link='_ltcMat')
|
||||
frag.add_uniform('sampler2D sltcMag', link='_ltcMag')
|
||||
frag.add_uniform('vec3 lightArea0', link='_lightArea0')
|
||||
frag.add_uniform('vec3 lightArea1', link='_lightArea1')
|
||||
frag.add_uniform('vec3 lightArea2', link='_lightArea2')
|
||||
frag.add_uniform('vec3 lightArea3', link='_lightArea3')
|
||||
frag.write('if (lightType == 3) {')
|
||||
frag.write(' float theta = acos(dotNV);')
|
||||
frag.write(' vec2 tuv = vec2(roughness, theta / (0.5 * PI));')
|
||||
frag.write(' tuv = tuv * LUT_SCALE + LUT_BIAS;')
|
||||
frag.write(' vec4 t = texture(sltcMat, tuv);')
|
||||
frag.write(' mat3 invM = mat3(vec3(1.0, 0.0, t.y), vec3(0.0, t.z, 0.0), vec3(t.w, 0.0, t.x));')
|
||||
frag.write(' float ltcspec = ltcEvaluate(n, vVec, dotNV, wposition, invM, lightArea0, lightArea1, lightArea2, lightArea3);')
|
||||
frag.write(' ltcspec *= texture(sltcMag, tuv).a;')
|
||||
frag.write(' float ltcdiff = ltcEvaluate(n, vVec, dotNV, wposition, mat3(1.0), lightArea0, lightArea1, lightArea2, lightArea3);')
|
||||
frag.write(' direct = albedo * ltcdiff + ltcspec * specular;')
|
||||
frag.write('}')
|
||||
frag.write('else {')
|
||||
frag.tab += 1
|
||||
if '_Sun' in wrd.world_defs:
|
||||
frag.add_uniform('vec3 lightCol', '_sunColor')
|
||||
frag.add_uniform('vec3 sunDir', '_sunDirection')
|
||||
frag.write('float visibility = 1.0;')
|
||||
frag.write('vec3 sh = normalize(vVec + sunDir);')
|
||||
frag.write('float sdotNL = dot(n, sunDir);')
|
||||
frag.write('float sdotNH = dot(n, sh);')
|
||||
frag.write('float sdotVH = dot(vVec, sh);')
|
||||
if is_shadows:
|
||||
frag.add_uniform('sampler2D shadowMap')
|
||||
frag.add_uniform('float shadowsBias', '_sunShadowsBias')
|
||||
frag.add_uniform('vec2 lightProj', '_lightPlaneProj')
|
||||
frag.write('if (receiveShadow) {')
|
||||
if '_CSM' in wrd.world_defs:
|
||||
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
|
||||
frag.add_uniform('vec3 eye', '_cameraPosition')
|
||||
frag.write('vec2 smSize;')
|
||||
frag.write('vec3 lPos;')
|
||||
frag.write('int casi;')
|
||||
frag.write('int casindex;')
|
||||
frag.write('mat4 LWVP = getCascadeMat(distance(eye, wposition), casi, casindex);')
|
||||
frag.write('vec4 lightPosition = LWVP * vec4(wposition, 1.0);')
|
||||
frag.write('lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write('smSize = shadowmapSize * vec2(shadowmapCascades, 1.0);')
|
||||
else:
|
||||
if tese != None:
|
||||
tese.add_out('vec4 lightPosition')
|
||||
tese.add_uniform('mat4 LVP', '_biasLightViewProjectionMatrix')
|
||||
tese.write('lightPosition = LVP * vec4(wposition, 1.0);')
|
||||
else:
|
||||
if is_displacement:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LVP', '_biasLightViewProjectionMatrix')
|
||||
vert.write('lightPosition = LVP * vec4(wposition, 1.0);')
|
||||
else:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrix')
|
||||
vert.write('lightPosition = LWVP * spos;')
|
||||
frag.write('vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write('const vec2 smSize = shadowmapSize;')
|
||||
frag.write('visibility = PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize);')
|
||||
frag.write('}') # receiveShadow
|
||||
# is_shadows
|
||||
frag.write('direct += lambertDiffuseBRDF(albedo, sdotNL);')
|
||||
frag.write('direct += specularBRDF(f0, roughness, sdotNL, sdotNH, dotNV, sdotVH) * specular;')
|
||||
# sun
|
||||
|
||||
frag.write('direct = lambertDiffuseBRDF(albedo, dotNL);')
|
||||
frag.write('direct += specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH) * specular;')
|
||||
if '_Clusters' in wrd.world_defs and '_Sun' not in wrd.world_defs:
|
||||
frag.add_uniform('vec3 lightCol', '_lightColor')
|
||||
frag.add_uniform('vec3 lightPos', '_lightPosition')
|
||||
frag.write('float visibility = 1.0;')
|
||||
frag.write('vec3 ld = lightPos - wposition;')
|
||||
frag.write('vec3 l = normalize(ld);')
|
||||
frag.write('vec3 h = normalize(vVec + l);')
|
||||
frag.write('float dotNL = dot(n, l);')
|
||||
frag.write('float dotNH = dot(n, h);')
|
||||
frag.write('float dotVH = dot(vVec, h);')
|
||||
frag.write('visibility *= attenuate(distance(wposition, lightPos));')
|
||||
|
||||
if is_shadows:
|
||||
if tese != None:
|
||||
tese.add_out('vec4 lightPosition')
|
||||
tese.add_uniform('mat4 LVP', '_biasLightViewProjectionMatrix')
|
||||
tese.write('lightPosition = LVP * vec4(wposition, 1.0);')
|
||||
else:
|
||||
if is_displacement:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LVP', '_biasLightViewProjectionMatrix')
|
||||
vert.write('lightPosition = LVP * vec4(wposition, 1.0);')
|
||||
else:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrix')
|
||||
vert.write('lightPosition = LWVP * spos;')
|
||||
|
||||
frag.add_uniform('samplerCube shadowMap0')
|
||||
frag.add_uniform('float shadowsBias', '_lightShadowsBias')
|
||||
frag.add_uniform('vec2 lightProj', '_lightPlaneProj')
|
||||
frag.write('if (receiveShadow) {')
|
||||
frag.write('visibility *= PCFCube(shadowMap0, ld, -l, shadowsBias, lightProj, n);')
|
||||
frag.write('}')
|
||||
|
||||
if '_LTC' in wrd.world_defs:
|
||||
frag.write('}')
|
||||
frag.tab -= 1
|
||||
# frag.write('if (lightType == 2) {')
|
||||
# frag.write(' float spotEffect = dot(lightDir, l);')
|
||||
# frag.write(' if (spotEffect < spotlightData.x) {')
|
||||
# frag.write(' visibility *= smoothstep(spotlightData.y, spotlightData.x, spotEffect);')
|
||||
# frag.write(' }')
|
||||
# frag.write('}')
|
||||
|
||||
# if '_LTC' in wrd.world_defs:
|
||||
# frag.add_include('std/ltc.glsl')
|
||||
# frag.add_uniform('sampler2D sltcMat', link='_ltcMat')
|
||||
# frag.add_uniform('sampler2D sltcMag', link='_ltcMag')
|
||||
# frag.add_uniform('vec3 lightArea0', link='_lightArea0')
|
||||
# frag.add_uniform('vec3 lightArea1', link='_lightArea1')
|
||||
# frag.add_uniform('vec3 lightArea2', link='_lightArea2')
|
||||
# frag.add_uniform('vec3 lightArea3', link='_lightArea3')
|
||||
# frag.write('if (lightType == 3) {')
|
||||
# frag.write(' float theta = acos(dotNV);')
|
||||
# frag.write(' vec2 tuv = vec2(roughness, theta / (0.5 * PI));')
|
||||
# frag.write(' tuv = tuv * LUT_SCALE + LUT_BIAS;')
|
||||
# frag.write(' vec4 t = texture(sltcMat, tuv);')
|
||||
# frag.write(' mat3 invM = mat3(vec3(1.0, 0.0, t.y), vec3(0.0, t.z, 0.0), vec3(t.w, 0.0, t.x));')
|
||||
# frag.write(' float ltcspec = ltcEvaluate(n, vVec, dotNV, wposition, invM, lightArea0, lightArea1, lightArea2, lightArea3);')
|
||||
# frag.write(' ltcspec *= texture(sltcMag, tuv).a;')
|
||||
# frag.write(' float ltcdiff = ltcEvaluate(n, vVec, dotNV, wposition, mat3(1.0), lightArea0, lightArea1, lightArea2, lightArea3);')
|
||||
# frag.write(' direct = albedo * ltcdiff + ltcspec * specular;')
|
||||
# frag.write('}')
|
||||
|
||||
frag.write('direct += lambertDiffuseBRDF(albedo, dotNL);')
|
||||
frag.write('direct += specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH) * specular;')
|
||||
|
||||
if '_Brdf' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D senvmapBrdf', link='_envmapBrdf')
|
||||
frag.write('vec2 envBRDF = texture(senvmapBrdf, vec2(roughness, 1.0 - dotNV)).xy;')
|
||||
|
||||
if '_Irr' in wrd.world_defs:
|
||||
frag.add_include('std/shirr.glsl')
|
||||
frag.add_uniform('vec4 shirr[7]', link='_envmapIrradiance', included=True)
|
||||
frag.write('vec3 indirect = shIrradiance(n);')
|
||||
if '_EnvTex' in wrd.world_defs:
|
||||
frag.write('indirect /= PI;')
|
||||
frag.write('indirect *= albedo;')
|
||||
|
||||
if '_Rad' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D senvmapRadiance', link='_envmapRadiance')
|
||||
frag.add_uniform('int envmapNumMipmaps', link='_envmapNumMipmaps')
|
||||
frag.write('vec3 reflectionWorld = reflect(-vVec, n);')
|
||||
frag.write('float lod = getMipFromRoughness(roughness, envmapNumMipmaps);')
|
||||
frag.write('vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;')
|
||||
|
@ -789,6 +820,8 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
frag.write('indirect += backgroundCol * f0;')
|
||||
else:
|
||||
frag.write('vec3 indirect = albedo;')
|
||||
|
||||
frag.add_uniform('float envmapStrength', link='_envmapStrength')
|
||||
frag.write('indirect *= envmapStrength;')
|
||||
|
||||
if '_VoxelGI' in wrd.world_defs or '_VoxelAO' in wrd.world_defs:
|
||||
|
|
|
@ -327,13 +327,11 @@ def init_properties():
|
|||
bpy.types.Light.arm_clip_end = FloatProperty(name="Clip End", default=50.0)
|
||||
bpy.types.Light.arm_fov = FloatProperty(name="Field of View", default=0.84)
|
||||
bpy.types.Light.arm_shadows_bias = FloatProperty(name="Bias", description="Depth offset to fight shadow acne", default=1.0)
|
||||
bpy.types.Light.arm_shadows_cubemap = BoolProperty(name="Cubemap", description="Use cubemap to capture point light shadows", default=True)
|
||||
else:
|
||||
bpy.types.Lamp.arm_clip_start = FloatProperty(name="Clip Start", default=0.1)
|
||||
bpy.types.Lamp.arm_clip_end = FloatProperty(name="Clip End", default=50.0)
|
||||
bpy.types.Lamp.arm_fov = FloatProperty(name="Field of View", default=0.84)
|
||||
bpy.types.Lamp.arm_shadows_bias = FloatProperty(name="Bias", description="Depth offset to fight shadow acne", default=1.0)
|
||||
bpy.types.Lamp.arm_shadows_cubemap = BoolProperty(name="Cubemap", description="Use cubemap to capture point light shadows", default=True)
|
||||
bpy.types.World.arm_light_ies_texture = StringProperty(name="IES Texture", default="")
|
||||
bpy.types.World.arm_light_clouds_texture = StringProperty(name="Clouds Texture", default="")
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ class ArmPropertyList(bpy.types.UIList):
|
|||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
# Make sure your code supports all 3 layout types
|
||||
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
||||
split = layout.row()
|
||||
split.prop(item, "name_prop", text="", emboss=False, icon="OBJECT_DATAMODE")
|
||||
split.prop(item, item.type_prop + "_prop", text="", emboss=(item.type_prop == 'boolean'))
|
||||
row = layout.row()
|
||||
row.prop(item, "name_prop", text="", emboss=False, icon="OBJECT_DATAMODE")
|
||||
row.prop(item, item.type_prop + "_prop", text="", emboss=(item.type_prop == 'boolean'))
|
||||
elif self.layout_type in {'GRID'}:
|
||||
layout.alignment = 'CENTER'
|
||||
layout.label(text="", icon="OBJECT_DATAMODE")
|
||||
|
|
|
@ -38,6 +38,7 @@ def update_preset(self, context):
|
|||
rpdat.arm_texture_filter = 'Anisotropic'
|
||||
rpdat.arm_radiance = True
|
||||
rpdat.arm_radiance_sky = True
|
||||
rpdat.arm_shadows_cubemap = True
|
||||
elif self.rp_preset == 'VR':
|
||||
rpdat.rp_renderer = 'Forward'
|
||||
rpdat.rp_depthprepass = False
|
||||
|
@ -69,6 +70,7 @@ def update_preset(self, context):
|
|||
rpdat.arm_texture_filter = 'Point'
|
||||
rpdat.arm_radiance = True
|
||||
rpdat.arm_radiance_sky = True
|
||||
rpdat.arm_shadows_cubemap = True
|
||||
elif self.rp_preset == 'Mobile':
|
||||
rpdat.rp_renderer = 'Forward'
|
||||
rpdat.rp_depthprepass = False
|
||||
|
@ -100,6 +102,7 @@ def update_preset(self, context):
|
|||
rpdat.arm_texture_filter = 'Linear'
|
||||
rpdat.arm_radiance = False
|
||||
rpdat.arm_radiance_sky = False
|
||||
rpdat.arm_shadows_cubemap = False
|
||||
elif self.rp_preset == 'Max':
|
||||
rpdat.rp_renderer = 'Deferred'
|
||||
rpdat.rp_shadowmap = '8192'
|
||||
|
@ -135,6 +138,7 @@ def update_preset(self, context):
|
|||
rpdat.arm_texture_filter = 'Anisotropic'
|
||||
rpdat.arm_radiance = True
|
||||
rpdat.arm_radiance_sky = True
|
||||
rpdat.arm_shadows_cubemap = True
|
||||
elif self.rp_preset == '2D/Baked':
|
||||
rpdat.rp_renderer = 'Forward'
|
||||
rpdat.rp_depthprepass = False
|
||||
|
@ -166,6 +170,7 @@ def update_preset(self, context):
|
|||
rpdat.arm_texture_filter = 'Linear'
|
||||
rpdat.arm_radiance = False
|
||||
rpdat.arm_radiance_sky = False
|
||||
rpdat.arm_shadows_cubemap = False
|
||||
update_renderpath(self, context)
|
||||
|
||||
def update_renderpath(self, context):
|
||||
|
@ -236,8 +241,8 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
rp_driver_list = CollectionProperty(type=bpy.types.PropertyGroup)
|
||||
rp_driver = StringProperty(name="Driver", default="Armory", update=assets.invalidate_compiled_data)
|
||||
rp_renderer = EnumProperty(
|
||||
items=[('Forward', 'Forward', 'Forward'),
|
||||
('Deferred', 'Deferred', 'Deferred'),
|
||||
items=[('Forward', 'Forward Clustered', 'Forward'),
|
||||
('Deferred', 'Deferred Clustered', 'Deferred'),
|
||||
# ('Raytracer', 'Raytracer', 'Raytracer'),
|
||||
],
|
||||
name="Renderer", description="Renderer type", default='Deferred', update=update_renderpath)
|
||||
|
@ -369,6 +374,7 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
name="Soft Shadows", description="Soft shadows with variable penumbra (spot and non-cascaded sun light supported)", default='Off', update=assets.invalidate_shader_cache)
|
||||
arm_soft_shadows_penumbra = IntProperty(name="Penumbra", description="Variable penumbra scale", default=1, min=0, max=10, update=assets.invalidate_shader_cache)
|
||||
arm_soft_shadows_distance = FloatProperty(name="Distance", description="Variable penumbra distance", default=1.0, min=0, max=10, update=assets.invalidate_shader_cache)
|
||||
arm_shadows_cubemap = BoolProperty(name="Cubemap", description="Use cubemap to capture point light shadows", default=True)
|
||||
arm_ssrs = BoolProperty(name="SSRS", description="Screen-space ray-traced shadows", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_texture_filter = EnumProperty(
|
||||
items=[('Anisotropic', 'Anisotropic', 'Anisotropic'),
|
||||
|
|
|
@ -138,8 +138,6 @@ class DataPropsPanel(bpy.types.Panel):
|
|||
col = row.column()
|
||||
col.prop(obj.data, 'arm_fov')
|
||||
col.prop(obj.data, 'arm_shadows_bias')
|
||||
if obj.data.type == 'POINT':
|
||||
layout.prop(obj.data, 'arm_shadows_cubemap')
|
||||
layout.prop(wrd, 'arm_light_ies_texture')
|
||||
layout.prop(wrd, 'arm_light_clouds_texture')
|
||||
elif obj.type == 'SPEAKER':
|
||||
|
@ -783,6 +781,7 @@ class ArmRenderPathPanel(bpy.types.Panel):
|
|||
row = self.row(col2, align=True, alignment='EXPAND')
|
||||
self.prop(row, rpdat, 'arm_soft_shadows_penumbra')
|
||||
self.prop(row, rpdat, 'arm_soft_shadows_distance')
|
||||
self.prop(col, rpdat, 'arm_shadows_cubemap')
|
||||
self.prop(col, rpdat, 'arm_pcfsize')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue