Area lamps.
This commit is contained in:
parent
bcc6dbdf91
commit
f5cdac1c7c
|
@ -7,6 +7,9 @@ precision mediump float;
|
|||
#include "../compiled.glsl"
|
||||
#include "../std/brdf.glsl"
|
||||
#include "../std/math.glsl"
|
||||
// #ifdef _PolyLight
|
||||
#include "../std/ltc.glsl"
|
||||
// #endif
|
||||
// ...
|
||||
#ifndef _NoShadows
|
||||
#ifdef _PCSS
|
||||
|
@ -40,6 +43,11 @@ uniform sampler2D gbuffer1;
|
|||
//!uniform sampler3D voxels;
|
||||
#endif
|
||||
|
||||
// #ifdef _PolyLight
|
||||
//! uniform sampler2D sltcMat;
|
||||
//! uniform sampler2D sltcMag;
|
||||
// #endif
|
||||
|
||||
uniform mat4 invVP;
|
||||
uniform mat4 LWVP;
|
||||
uniform vec3 lightPos;
|
||||
|
@ -50,11 +58,17 @@ uniform float lightStrength;
|
|||
uniform float shadowsBias;
|
||||
uniform float spotlightCutoff;
|
||||
uniform float spotlightExponent;
|
||||
// #ifdef _PolyLight
|
||||
uniform vec3 lampArea0;
|
||||
uniform vec3 lampArea1;
|
||||
uniform vec3 lampArea2;
|
||||
uniform vec3 lampArea3;
|
||||
// #endif
|
||||
uniform vec3 eye;
|
||||
// uniform vec3 eyeLook;
|
||||
// uniform vec2 screenSize;
|
||||
|
||||
#ifdef _LampTex
|
||||
#ifdef _LampColTex
|
||||
uniform sampler2D texlampcolor;
|
||||
#else
|
||||
uniform vec3 lightColor;
|
||||
|
@ -151,18 +165,41 @@ void main() {
|
|||
#endif
|
||||
|
||||
// Direct
|
||||
vec3 direct;
|
||||
// #ifdef _PolyLight
|
||||
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 Minv = mat3(
|
||||
vec3(1.0, 0.0, t.y),
|
||||
vec3(0.0, t.z, 0.0),
|
||||
vec3(t.w, 0.0, t.x));
|
||||
|
||||
vec3 ltcspec = ltcEvaluate(n, v, dotNV, p, Minv, lampArea0, lampArea1, lampArea2, lampArea3, false);
|
||||
ltcspec *= texture(sltcMag, tuv).a;
|
||||
|
||||
vec3 ltcdiff = ltcEvaluate(n, v, dotNV, p, mat3(1.0), lampArea0, lampArea1, lampArea2, lampArea3, false);
|
||||
direct = ltcdiff * albedo;// + ltcspec;
|
||||
}
|
||||
else {
|
||||
// #endif
|
||||
|
||||
#ifdef _OrenNayar
|
||||
vec3 direct = orenNayarDiffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH);
|
||||
direct = orenNayarDiffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH);
|
||||
#else
|
||||
vec3 direct = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH);
|
||||
direct = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH);
|
||||
#endif
|
||||
|
||||
if (lightType == 2) { // Spot
|
||||
float spotEffect = dot(lightDir, l);
|
||||
if (spotEffect < spotlightCutoff) {
|
||||
float spotEffect = smoothstep(spotlightCutoff - spotlightExponent, spotlightCutoff, spotEffect);
|
||||
direct *= spotEffect;
|
||||
if (lightType == 2) { // Spot
|
||||
float spotEffect = dot(lightDir, l);
|
||||
if (spotEffect < spotlightCutoff) {
|
||||
float spotEffect = smoothstep(spotlightCutoff - spotlightExponent, spotlightCutoff, spotEffect);
|
||||
direct *= spotEffect;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Aniso spec
|
||||
|
@ -173,10 +210,11 @@ void main() {
|
|||
// vec3 direct = diffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH, dotLV) + wardSpecular(n, h, dotNL, dotNV, dotNH, fiberDirection, shinyParallel, shinyPerpendicular);
|
||||
// #endif
|
||||
|
||||
direct = direct * lightStrength;
|
||||
#ifdef _LampTex
|
||||
direct *= texture(texlampcolor, envMapEquirect(l)).rgb;
|
||||
// direct *= texture(texlampcolor, l.xy).rgb;
|
||||
direct *= lightStrength;
|
||||
|
||||
#ifdef _LampColTex
|
||||
// direct *= texture(texlampcolor, envMapEquirect(l)).rgb;
|
||||
direct *= pow(texture(texlampcolor, l.xy).rgb, vec3(2.2));
|
||||
#else
|
||||
direct *= lightColor;
|
||||
#endif
|
||||
|
@ -224,41 +262,4 @@ void main() {
|
|||
indirect1 *= texture(ssaotex, texCoord).r;
|
||||
fragColor.rgb += indirect1;
|
||||
#endif
|
||||
|
||||
|
||||
// LTC
|
||||
// float sinval = (sin(time) * 0.5 + 0.5);
|
||||
// vec4 fragColor = vec4(1.0);
|
||||
// float rectSizeX = 4.000 + sin(time) * 4.0;
|
||||
// float rectSizeY = 1.2;// + sin(time * 2.0);
|
||||
// vec3 ex = vec3(1, 0, 0)*rectSizeX;
|
||||
// vec3 ey = vec3(0, 0, 1)*rectSizeY;
|
||||
// vec3 p1 = lightPos - ex + ey;
|
||||
// vec3 p2 = lightPos + ex + ey;
|
||||
// vec3 p3 = lightPos + ex - ey;
|
||||
// vec3 p4 = lightPos - ex - ey;
|
||||
// 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 Minv = mat3(
|
||||
// vec3( 1, t.y, 0),
|
||||
// vec3( 0, 0, t.z),
|
||||
// vec3(t.w, 0, t.x)
|
||||
// );
|
||||
|
||||
// vec3 ltcspec = LTC_Evaluate(n, v, p, Minv, p1, p2, p3, p4, true);
|
||||
// ltcspec *= vec3(1.0, 1.0 - sinval, 1.0 - sinval);
|
||||
// ltcspec *= texture(sltcMag, tuv).a;
|
||||
// vec3 ltcdiff = LTC_Evaluate(n, v, p, mat3(1), p1, p2, p3, p4, true);
|
||||
// ltcdiff *= vec3(1.0, 1.0 - sinval, 1.0 - sinval);
|
||||
// vec3 ltccol = ltcspec + ltcdiff * albedo;
|
||||
// ltccol /= 2.0*PI;
|
||||
// fragColor.rgb = ltccol * 5.0 * visibility + (indirect / 14.0 * ao * (rectSizeX / 6.0) );
|
||||
// // fragColor.rgb = ltccol * visibility + (indirect / 2.0 * ao);
|
||||
|
||||
// fragColor = vec4(pow(fragColor.rgb, vec3(1.0 / 2.2)), fragColor.a);
|
||||
// outputColor = vec4(fragColor.rgb, fragColor.a);
|
||||
//gl_FragColor = vec4(fragColor.rgb, fragColor.a);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,36 @@
|
|||
"name": "spotlightExponent",
|
||||
"link": "_spotlampExponent"
|
||||
},
|
||||
{
|
||||
"name": "lampArea0",
|
||||
"link": "_lampArea0",
|
||||
"ifndef": ["_ifndefPolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "lampArea1",
|
||||
"link": "_lampArea1",
|
||||
"ifndef": ["_ifndefPolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "lampArea2",
|
||||
"link": "_lampArea2",
|
||||
"ifndef": ["_ifndefPolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "lampArea3",
|
||||
"link": "_lampArea3",
|
||||
"ifndef": ["_ifndefPolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "sltcMat",
|
||||
"link": "_ltcMat",
|
||||
"ifndef": ["_ifndefPolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "sltcMag",
|
||||
"link": "_ltcMag",
|
||||
"ifndef": ["_ifndefPolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "eye",
|
||||
"link": "_cameraPosition"
|
||||
|
@ -106,21 +136,6 @@
|
|||
"link": "_envmapStrength",
|
||||
"ifdef": ["_Disabled"]
|
||||
},
|
||||
{
|
||||
"name": "sltcMat",
|
||||
"link": "_ltcMat",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "sltcMag",
|
||||
"link": "_ltcMag",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"link": "_time",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "snoise",
|
||||
"link": "_noise64",
|
||||
|
|
|
@ -90,16 +90,6 @@
|
|||
"name": "envmapStrength",
|
||||
"link": "_envmapStrength"
|
||||
},
|
||||
{
|
||||
"name": "sltcMat",
|
||||
"link": "_ltcMat",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "sltcMag",
|
||||
"link": "_ltcMag",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "U",
|
||||
"link": "_undistortionMatrix",
|
||||
|
@ -124,6 +114,36 @@
|
|||
"name": "lampSizeUV",
|
||||
"link": "_lampSizeUV",
|
||||
"ifdef": ["_PCSS"]
|
||||
},
|
||||
{
|
||||
"name": "lampArea0",
|
||||
"link": "_lampArea0",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "lampArea1",
|
||||
"link": "_lampArea1",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "lampArea2",
|
||||
"link": "_lampArea2",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "lampArea3",
|
||||
"link": "_lampArea3",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "sltcMat",
|
||||
"link": "_ltcMat",
|
||||
"ifdef": ["_PolyLight"]
|
||||
},
|
||||
{
|
||||
"name": "sltcMag",
|
||||
"link": "_ltcMag",
|
||||
"ifdef": ["_PolyLight"]
|
||||
}
|
||||
],
|
||||
"vertex_shader": "mesh.vert.glsl",
|
||||
|
|
|
@ -6,14 +6,11 @@ precision mediump float;
|
|||
|
||||
#include "../compiled.glsl"
|
||||
#include "../std/brdf.glsl"
|
||||
// surfaceAlbedo()
|
||||
// surfaceF0()
|
||||
// orenNayarDiffuseBRDF()
|
||||
// lambertDiffuseBRDF()
|
||||
// specularBRDF()
|
||||
// #ifdef _PolyLight
|
||||
//#include "../std/ltc.glsl"
|
||||
// #endif
|
||||
#ifdef _Rad
|
||||
#include "../std/math.glsl"
|
||||
// envMapEquirect()
|
||||
#endif
|
||||
#ifndef _NoShadows
|
||||
#ifdef _PCSS
|
||||
|
@ -28,6 +25,11 @@ precision mediump float;
|
|||
// shIrradiance()
|
||||
//!uniform float shirr[27];
|
||||
|
||||
// #ifdef _PolyLight
|
||||
//-! uniform sampler2D sltcMat;
|
||||
//-! uniform sampler2D sltcMag;
|
||||
// #endif
|
||||
|
||||
#ifdef _BaseTex
|
||||
uniform sampler2D sbase;
|
||||
#endif
|
||||
|
@ -80,6 +82,12 @@ uniform float spotlightCutoff;
|
|||
uniform float spotlightExponent;
|
||||
uniform float shadowsBias;
|
||||
uniform vec3 eye;
|
||||
// #ifdef _PolyLight
|
||||
// uniform vec3 lampArea0;
|
||||
// uniform vec3 lampArea1;
|
||||
// uniform vec3 lampArea2;
|
||||
// uniform vec3 lampArea3;
|
||||
// #endif
|
||||
|
||||
#ifdef _VoxelGI
|
||||
uniform sampler2D ssaotex;
|
||||
|
@ -276,37 +284,34 @@ void main() {
|
|||
// #endif
|
||||
|
||||
|
||||
// LTC
|
||||
// const float rectSizeX = 2.5;
|
||||
// const float rectSizeY = 1.2;
|
||||
// vec3 ex = vec3(1, 0, 0)*rectSizeX;
|
||||
// vec3 ey = vec3(0, 0, 1)*rectSizeY;
|
||||
// vec3 p1 = light - ex + ey;
|
||||
// vec3 p2 = light + ex + ey;
|
||||
// vec3 p3 = light + ex - ey;
|
||||
// vec3 p4 = light - ex - ey;
|
||||
// float theta = acos(dotNV);
|
||||
// vec2 tuv = vec2(roughness, theta/(0.5*PI));
|
||||
// tuv = tuv*LUT_SCALE + LUT_BIAS;
|
||||
|
||||
// vec4 t = texture(sltcMat, tuv);
|
||||
// mat3 Minv = mat3(
|
||||
// vec3( 1, t.y, 0),
|
||||
// vec3( 0, 0, t.z),
|
||||
// vec3(t.w, 0, t.x)
|
||||
// );
|
||||
|
||||
// vec3 ltcspec = LTC_Evaluate(n, v, position, Minv, p1, p2, p3, p4, true);
|
||||
// ltcspec *= texture(sltcMag, tuv).a;
|
||||
// vec3 ltcdiff = LTC_Evaluate(n, v, position, mat3(1), p1, p2, p3, p4, true);
|
||||
// vec3 ltccol = ltcspec + ltcdiff * albedo;
|
||||
// ltccol /= 2.0*PI;
|
||||
// Direct
|
||||
vec3 direct;
|
||||
|
||||
// #ifdef _PolyLight
|
||||
// if (lightType == 3) { // Area
|
||||
// float theta = acos(dotNV);
|
||||
// vec2 tuv = vec2(roughness, theta / (0.5 * PI));
|
||||
// tuv = tuv * LUT_SCALE + LUT_BIAS;
|
||||
// vec4 t = texture(sltcMat, tuv);
|
||||
// mat3 Minv = mat3(
|
||||
// vec3(1.0, 0.0, t.y),
|
||||
// vec3(0.0, t.z, 0.0),
|
||||
// vec3(t.w, 0.0, t.x));
|
||||
|
||||
// vec3 ltcspec = ltcEvaluate(n, v, dotNV, position, Minv, lampArea0, lampArea1, lampArea2, lampArea3, true);
|
||||
// ltcspec *= texture(sltcMag, tuv).a;
|
||||
|
||||
// vec3 ltcdiff = ltcEvaluate(n, v, dotNV, position, mat3(1.0), lampArea0, lampArea1, lampArea2, lampArea3, true);
|
||||
// direct = ltcspec + ltcdiff * albedo;
|
||||
// }
|
||||
// else {
|
||||
|
||||
// Direct
|
||||
#ifdef _OrenNayar
|
||||
vec3 direct = orenNayarDiffuseBRDF(albedo, roughness, dotNV, dotNL, dotVH) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
|
||||
direct = orenNayarDiffuseBRDF(albedo, roughness, dotNV, dotNL, dotVH) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
|
||||
#else
|
||||
vec3 direct = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
|
||||
direct = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
|
||||
#endif
|
||||
|
||||
if (lightType == 2) { // Spot
|
||||
|
@ -316,6 +321,9 @@ void main() {
|
|||
direct *= spotEffect;
|
||||
}
|
||||
}
|
||||
|
||||
//} ////
|
||||
|
||||
|
||||
direct = direct * lightColor * lightStrength;
|
||||
|
||||
|
@ -379,9 +387,6 @@ void main() {
|
|||
#else
|
||||
fragColor.rgb *= occlusion;
|
||||
#endif
|
||||
|
||||
// LTC
|
||||
// fragColor.rgb = ltccol * 10.0 * visibility + indirect / 14.0;
|
||||
|
||||
#ifdef _LDR
|
||||
fragColor = vec4(pow(fragColor.rgb, vec3(1.0 / 2.2)), fragColor.a);
|
||||
|
|
|
@ -1,188 +1,164 @@
|
|||
// #ifdef _LTC
|
||||
// uniform sampler2D sltcMat;
|
||||
// uniform sampler2D sltcMag;
|
||||
// uniform float time;
|
||||
// const float roughness = 0.25;
|
||||
// const vec3 dcolor = vec3(1.0, 1.0, 1.0);
|
||||
// const vec3 scolor = vec3(1.0, 1.0, 1.0);
|
||||
// const float intensity = 4.0; // 0-10
|
||||
// const float width = 4.0;
|
||||
// const float height = 4.0;
|
||||
// const int sampleCount = 0;
|
||||
// const int NUM_SAMPLES = 8;
|
||||
// const float LUT_SIZE = 64.0;
|
||||
// const float LUT_SCALE = (LUT_SIZE - 1.0)/LUT_SIZE;
|
||||
// const float LUT_BIAS = 0.5/LUT_SIZE;
|
||||
// vec2 mys[NUM_SAMPLES];
|
||||
// vec3 L0 = vec3(0.0);
|
||||
// vec3 L1 = vec3(0.0);
|
||||
// vec3 L2 = vec3(0.0);
|
||||
// vec3 L3 = vec3(0.0);
|
||||
// vec3 L4 = vec3(0.0);
|
||||
// #endif
|
||||
|
||||
// Linearly Transformed Cosines
|
||||
// https://eheitzresearch.wordpress.com/415-2/
|
||||
// vec3 mul(mat3 m, vec3 v) {
|
||||
// return m * v;
|
||||
// }
|
||||
// mat3 mul(mat3 m1, mat3 m2) {
|
||||
// return m1 * m2;
|
||||
// }
|
||||
// mat3 transpose2(mat3 v) {
|
||||
// mat3 tmp;
|
||||
// tmp[0] = vec3(v[0].x, v[1].x, v[2].x);
|
||||
// tmp[1] = vec3(v[0].y, v[1].y, v[2].y);
|
||||
// tmp[2] = vec3(v[0].z, v[1].z, v[2].z);
|
||||
uniform sampler2D sltcMat;
|
||||
uniform sampler2D sltcMag;
|
||||
|
||||
// return tmp;
|
||||
// }
|
||||
// float IntegrateEdge(vec3 v1, vec3 v2) {
|
||||
// float cosTheta = dot(v1, v2);
|
||||
// cosTheta = clamp(cosTheta, -0.9999, 0.9999);
|
||||
// float theta = acos(cosTheta);
|
||||
// float res = cross(v1, v2).z * theta / sin(theta);
|
||||
// return res;
|
||||
// }
|
||||
// int ClipQuadToHorizon(/*inout vec3 L[5], out int n*/) {
|
||||
// // detect clipping config
|
||||
// int config = 0;
|
||||
// if (L0.z > 0.0) config += 1;
|
||||
// if (L1.z > 0.0) config += 2;
|
||||
// if (L2.z > 0.0) config += 4;
|
||||
// if (L3.z > 0.0) config += 8;
|
||||
const float LUT_SIZE = 64.0;
|
||||
const float LUT_SCALE = (LUT_SIZE - 1.0) / LUT_SIZE;
|
||||
const float LUT_BIAS = 0.5 / LUT_SIZE;
|
||||
|
||||
// // clip
|
||||
// int n = 0;
|
||||
// if (config == 0) {
|
||||
// // clip all
|
||||
// }
|
||||
// else if (config == 1) { // V1 clip V2 V3 V4
|
||||
// n = 3;
|
||||
// L1 = -L1.z * L0 + L0.z * L1;
|
||||
// L2 = -L3.z * L0 + L0.z * L3;
|
||||
// }
|
||||
// else if (config == 2) { // V2 clip V1 V3 V4
|
||||
// n = 3;
|
||||
// L0 = -L0.z * L1 + L1.z * L0;
|
||||
// L2 = -L2.z * L1 + L1.z * L2;
|
||||
// }
|
||||
// else if (config == 3) { // V1 V2 clip V3 V4
|
||||
// n = 4;
|
||||
// L2 = -L2.z * L1 + L1.z * L2;
|
||||
// L3 = -L3.z * L0 + L0.z * L3;
|
||||
// }
|
||||
// else if (config == 4) { // V3 clip V1 V2 V4
|
||||
// n = 3;
|
||||
// L0 = -L3.z * L2 + L2.z * L3;
|
||||
// L1 = -L1.z * L2 + L2.z * L1;
|
||||
// }
|
||||
// else if (config == 5) { // V1 V3 clip V2 V4) impossible
|
||||
// n = 0;
|
||||
// }
|
||||
// else if (config == 6) { // V2 V3 clip V1 V4
|
||||
// n = 4;
|
||||
// L0 = -L0.z * L1 + L1.z * L0;
|
||||
// L3 = -L3.z * L2 + L2.z * L3;
|
||||
// }
|
||||
// else if (config == 7) { // V1 V2 V3 clip V4
|
||||
// n = 5;
|
||||
// L4 = -L3.z * L0 + L0.z * L3;
|
||||
// L3 = -L3.z * L2 + L2.z * L3;
|
||||
// }
|
||||
// else if (config == 8) { // V4 clip V1 V2 V3
|
||||
// n = 3;
|
||||
// L0 = -L0.z * L3 + L3.z * L0;
|
||||
// L1 = -L2.z * L3 + L3.z * L2;
|
||||
// L2 = L3;
|
||||
// }
|
||||
// else if (config == 9) { // V1 V4 clip V2 V3
|
||||
// n = 4;
|
||||
// L1 = -L1.z * L0 + L0.z * L1;
|
||||
// L2 = -L2.z * L3 + L3.z * L2;
|
||||
// }
|
||||
// else if (config == 10) { // V2 V4 clip V1 V3) impossible
|
||||
// n = 0;
|
||||
// }
|
||||
// else if (config == 11) { // V1 V2 V4 clip V3
|
||||
// n = 5;
|
||||
// L4 = L3;
|
||||
// L3 = -L2.z * L3 + L3.z * L2;
|
||||
// L2 = -L2.z * L1 + L1.z * L2;
|
||||
// }
|
||||
// else if (config == 12) { // V3 V4 clip V1 V2
|
||||
// n = 4;
|
||||
// L1 = -L1.z * L2 + L2.z * L1;
|
||||
// L0 = -L0.z * L3 + L3.z * L0;
|
||||
// }
|
||||
// else if (config == 13) { // V1 V3 V4 clip V2
|
||||
// n = 5;
|
||||
// L4 = L3;
|
||||
// L3 = L2;
|
||||
// L2 = -L1.z * L2 + L2.z * L1;
|
||||
// L1 = -L1.z * L0 + L0.z * L1;
|
||||
// }
|
||||
// else if (config == 14) { // V2 V3 V4 clip V1
|
||||
// n = 5;
|
||||
// L4 = -L0.z * L3 + L3.z * L0;
|
||||
// L0 = -L0.z * L1 + L1.z * L0;
|
||||
// }
|
||||
// else if (config == 15) { // V1 V2 V3 V4
|
||||
// n = 4;
|
||||
// }
|
||||
vec3 L0;
|
||||
vec3 L1;
|
||||
vec3 L2;
|
||||
vec3 L3;
|
||||
vec3 L4;
|
||||
|
||||
mat3 transpose2(mat3 v) {
|
||||
mat3 tmp;
|
||||
tmp[0] = vec3(v[0].x, v[1].x, v[2].x);
|
||||
tmp[1] = vec3(v[0].y, v[1].y, v[2].y);
|
||||
tmp[2] = vec3(v[0].z, v[1].z, v[2].z);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
float integrateEdge(vec3 v1, vec3 v2) {
|
||||
float cosTheta = dot(v1, v2);
|
||||
cosTheta = clamp(cosTheta, -0.9999, 0.9999);
|
||||
float theta = acos(cosTheta);
|
||||
float res = cross(v1, v2).z * theta / sin(theta);
|
||||
return res;
|
||||
}
|
||||
|
||||
int clipQuadToHorizon(/*inout vec3 L[5], out int n*/) {
|
||||
int n;
|
||||
// Detect clipping config
|
||||
int config = 0;
|
||||
if (L0.z > 0.0) config += 1;
|
||||
if (L1.z > 0.0) config += 2;
|
||||
if (L2.z > 0.0) config += 4;
|
||||
if (L3.z > 0.0) config += 8;
|
||||
|
||||
// Clip
|
||||
if (config == 0) {
|
||||
// Clip all
|
||||
}
|
||||
else if (config == 1) { // V1 clip V2 V3 V4
|
||||
n = 3;
|
||||
L1 = -L1.z * L0 + L0.z * L1;
|
||||
L2 = -L3.z * L0 + L0.z * L3;
|
||||
}
|
||||
else if (config == 2) { // V2 clip V1 V3 V4
|
||||
n = 3;
|
||||
L0 = -L0.z * L1 + L1.z * L0;
|
||||
L2 = -L2.z * L1 + L1.z * L2;
|
||||
}
|
||||
else if (config == 3) { // V1 V2 clip V3 V4
|
||||
n = 4;
|
||||
L2 = -L2.z * L1 + L1.z * L2;
|
||||
L3 = -L3.z * L0 + L0.z * L3;
|
||||
}
|
||||
else if (config == 4) { // V3 clip V1 V2 V4
|
||||
n = 3;
|
||||
L0 = -L3.z * L2 + L2.z * L3;
|
||||
L1 = -L1.z * L2 + L2.z * L1;
|
||||
}
|
||||
else if (config == 5) { // V1 V3 clip V2 V4) impossible
|
||||
n = 0;
|
||||
}
|
||||
else if (config == 6) { // V2 V3 clip V1 V4
|
||||
n = 4;
|
||||
L0 = -L0.z * L1 + L1.z * L0;
|
||||
L3 = -L3.z * L2 + L2.z * L3;
|
||||
}
|
||||
else if (config == 7) { // V1 V2 V3 clip V4
|
||||
n = 5;
|
||||
L4 = -L3.z * L0 + L0.z * L3;
|
||||
L3 = -L3.z * L2 + L2.z * L3;
|
||||
}
|
||||
else if (config == 8) { // V4 clip V1 V2 V3
|
||||
n = 3;
|
||||
L0 = -L0.z * L3 + L3.z * L0;
|
||||
L1 = -L2.z * L3 + L3.z * L2;
|
||||
L2 = L3;
|
||||
}
|
||||
else if (config == 9) { // V1 V4 clip V2 V3
|
||||
n = 4;
|
||||
L1 = -L1.z * L0 + L0.z * L1;
|
||||
L2 = -L2.z * L3 + L3.z * L2;
|
||||
}
|
||||
else if (config == 10) { // V2 V4 clip V1 V3) impossible
|
||||
n = 0;
|
||||
}
|
||||
else if (config == 11) { // V1 V2 V4 clip V3
|
||||
n = 5;
|
||||
L4 = L3;
|
||||
L3 = -L2.z * L3 + L3.z * L2;
|
||||
L2 = -L2.z * L1 + L1.z * L2;
|
||||
}
|
||||
else if (config == 12) { // V3 V4 clip V1 V2
|
||||
n = 4;
|
||||
L1 = -L1.z * L2 + L2.z * L1;
|
||||
L0 = -L0.z * L3 + L3.z * L0;
|
||||
}
|
||||
else if (config == 13) { // V1 V3 V4 clip V2
|
||||
n = 5;
|
||||
L4 = L3;
|
||||
L3 = L2;
|
||||
L2 = -L1.z * L2 + L2.z * L1;
|
||||
L1 = -L1.z * L0 + L0.z * L1;
|
||||
}
|
||||
else if (config == 14) { // V2 V3 V4 clip V1
|
||||
n = 5;
|
||||
L4 = -L0.z * L3 + L3.z * L0;
|
||||
L0 = -L0.z * L1 + L1.z * L0;
|
||||
}
|
||||
else if (config == 15) { // V1 V2 V3 V4
|
||||
n = 4;
|
||||
}
|
||||
|
||||
// if (n == 3)
|
||||
// L3 = L0;
|
||||
// if (n == 4)
|
||||
// L4 = L0;
|
||||
// return n;
|
||||
// }
|
||||
// vec3 LTC_Evaluate(vec3 N, vec3 V, vec3 P, mat3 Minv, vec3 points0, vec3 points1, vec3 points2, vec3 points3, bool twoSided) {
|
||||
// // construct orthonormal basis around N
|
||||
// vec3 T1, T2;
|
||||
// T1 = normalize(V - N*dot(V, N));
|
||||
// T2 = cross(N, T1);
|
||||
if (n == 3) L3 = L0;
|
||||
if (n == 4) L4 = L0;
|
||||
return n;
|
||||
}
|
||||
|
||||
// // rotate area light in (T1, T2, R) basis
|
||||
// Minv = mul(Minv, transpose2(mat3(T1, T2, N)));
|
||||
vec3 ltcEvaluate(vec3 N, vec3 V, float dotNV, vec3 P, mat3 Minv, vec3 points0, vec3 points1, vec3 points2, vec3 points3, bool twoSided) {
|
||||
// Construct orthonormal basis around N
|
||||
vec3 T1, T2;
|
||||
T1 = normalize(V - N * dotNV);
|
||||
T2 = cross(N, T1);
|
||||
|
||||
// // polygon (allocate 5 vertices for clipping)
|
||||
// // vec3 L[5];
|
||||
// L0 = mul(Minv, points0 - P);
|
||||
// L1 = mul(Minv, points1 - P);
|
||||
// L2 = mul(Minv, points2 - P);
|
||||
// L3 = mul(Minv, points3 - P);
|
||||
// Rotate area light in (T1, T2, R) basis
|
||||
Minv = Minv * transpose2(mat3(T1, T2, N));
|
||||
|
||||
// int n = ClipQuadToHorizon(/*L, n*/);
|
||||
// Polygon (allocate 5 vertices for clipping)
|
||||
// vec3 L[5];
|
||||
L0 = Minv * (points0 - P);
|
||||
L1 = Minv * (points1 - P);
|
||||
L2 = Minv * (points2 - P);
|
||||
L3 = Minv * (points3 - P);
|
||||
|
||||
// int n;
|
||||
int n = clipQuadToHorizon(/*L, n*/);
|
||||
|
||||
// if (n == 0) {
|
||||
// return vec3(0, 0, 0);
|
||||
// }
|
||||
if (n == 0) return vec3(0.0);
|
||||
|
||||
// // project onto sphere
|
||||
// L0 = normalize(L0);
|
||||
// L1 = normalize(L1);
|
||||
// L2 = normalize(L2);
|
||||
// L3 = normalize(L3);
|
||||
// L4 = normalize(L4);
|
||||
// Project onto sphere
|
||||
L0 = normalize(L0);
|
||||
L1 = normalize(L1);
|
||||
L2 = normalize(L2);
|
||||
L3 = normalize(L3);
|
||||
L4 = normalize(L4);
|
||||
|
||||
// // integrate
|
||||
// float sum = 0.0;
|
||||
// Integrate
|
||||
float sum = 0.0;
|
||||
|
||||
// sum += IntegrateEdge(L0, L1);
|
||||
// sum += IntegrateEdge(L1, L2);
|
||||
// sum += IntegrateEdge(L2, L3);
|
||||
sum += integrateEdge(L0, L1);
|
||||
sum += integrateEdge(L1, L2);
|
||||
sum += integrateEdge(L2, L3);
|
||||
|
||||
// if (n >= 4) {
|
||||
// sum += IntegrateEdge(L3, L4);
|
||||
// }
|
||||
// if (n == 5) {
|
||||
// sum += IntegrateEdge(L4, L0);
|
||||
// }
|
||||
if (n >= 4) sum += integrateEdge(L3, L4);
|
||||
if (n == 5) sum += integrateEdge(L4, L0);
|
||||
|
||||
// sum = twoSided ? abs(sum) : max(0.0, -sum);
|
||||
|
||||
// vec3 Lo_i = vec3(sum, sum, sum);
|
||||
|
||||
// return Lo_i;
|
||||
// }
|
||||
sum = twoSided ? abs(sum) : max(0.0, -sum);
|
||||
return vec3(sum);
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -244,8 +244,7 @@ class ArmoryExporter:
|
|||
return kNodeTypeMesh
|
||||
elif bobject.type == "LAMP":
|
||||
type = bobject.data.type
|
||||
if type == "SUN" or type == "POINT" or type == "SPOT":
|
||||
return kNodeTypeLamp
|
||||
return kNodeTypeLamp
|
||||
elif bobject.type == "CAMERA":
|
||||
return kNodeTypeCamera
|
||||
elif bobject.type == "SPEAKER":
|
||||
|
@ -1925,7 +1924,11 @@ class ArmoryExporter:
|
|||
o['type'] = 'spot'
|
||||
o['spot_size'] = math.cos(objref.spot_size / 2)
|
||||
o['spot_blend'] = objref.spot_blend / 10 # Cycles defaults to 0.15
|
||||
else: # Hemi, area
|
||||
elif objtype == 'AREA':
|
||||
o['type'] = 'area'
|
||||
o['size'] = objref.size
|
||||
o['size_y'] = objref.size_y
|
||||
else: # Hemi
|
||||
o['type'] = 'sun'
|
||||
|
||||
o['cast_shadow'] = objref.cycles.cast_shadow
|
||||
|
|
|
@ -50,7 +50,9 @@ def parse_lamp(tree, o):
|
|||
o['color'] = [col[0], col[1], col[2]]
|
||||
o['strength'] = n.inputs[1].default_value
|
||||
# Normalize point/spot strength
|
||||
if o['type'] != 'sun':
|
||||
if o['type'] == 'point' or o['type'] == 'spot':
|
||||
o['strength'] /= 1000.0
|
||||
elif o['type'] == 'area':
|
||||
o['strength'] /= 1000.0
|
||||
|
||||
# Texture test..
|
||||
|
@ -59,7 +61,7 @@ def parse_lamp(tree, o):
|
|||
if color_node.type == 'TEX_IMAGE':
|
||||
o['color_texture'] = color_node.image.name
|
||||
make_texture(None, '', color_node, None)
|
||||
# bpy.data.worlds['Arm'].world_defs += '_LampTex'
|
||||
# bpy.data.worlds['Arm'].world_defs += '_LampColTex'
|
||||
|
||||
break
|
||||
|
||||
|
|
Loading…
Reference in a new issue