Tessellated height maps in forward path

This commit is contained in:
Lubos Lenco 2016-12-11 13:32:38 +01:00
parent fdd52bf738
commit 5eb7221953
19 changed files with 971 additions and 128 deletions

View file

@ -29,20 +29,10 @@
"link": "_prevWorldViewProjectionMatrix",
"ifdef": ["_Veloc"]
},
{
"name": "light",
"link": "_lampPosition",
"ifdef": ["_HeightTex"]
},
{
"name": "eye",
"link": "_cameraPosition",
"ifdef": ["_HeightTex"]
},
{
"name": "W",
"link": "_worldMatrix",
"ifdef": ["_Probes", "_HeightTex"]
"ifdef": ["_Probes"]
},
{
"name": "probeVolumeCenter",
@ -145,6 +135,7 @@
],
"vertex_shader": "meshheight.vert.glsl",
"fragment_shader": "meshheight.frag.glsl",
"fragment_shader_path": "mesh.frag.glsl",
"tesscontrol_shader": "meshheight.tesc.glsl",
"tesseval_shader": "meshheight.tese.glsl"
},
@ -272,10 +263,13 @@
}
],
"vertex_shader": "shadowmapheight.vert.glsl",
"vertex_shader_path": "../include/shadowmapheight.vert.glsl",
"fragment_shader": "shadowmapheight.frag.glsl",
"fragment_shader_path": "../include/shadowmap.frag.glsl",
"tesscontrol_shader": "shadowmapheight.tesc.glsl",
"tesseval_shader": "shadowmapheight.tese.glsl"
"tesscontrol_shader_path": "../include/shadowmapheight.tesc.glsl",
"tesseval_shader": "shadowmapheight.tese.glsl",
"tesseval_shader_path": "../include/shadowmapheight.tese.glsl"
},
{
"name": "decals",

View file

@ -103,10 +103,10 @@ void main() {
vec4 texel = texture(sbase, texCoord);
#endif
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
// #ifdef _AlphaTest
// if(texel.a < 0.4)
// discard;
// #endif
texel.rgb = pow(texel.rgb, vec3(2.2)); // Variant 1
baseColor *= texel.rgb;

View file

@ -1,101 +0,0 @@
// Merge with mesh.frag
#version 450
#ifdef GL_ES
precision mediump float;
#endif
#include "../std/gbuffer.glsl"
// octahedronWrap()
// packFloat()
uniform float mask;
#ifdef _BaseTex
uniform sampler2D sbase;
#endif
#ifdef _NorTex
uniform sampler2D snormal;
#endif
#ifdef _NorStr
uniform float normalStrength;
#endif
#ifdef _OccTex
uniform sampler2D socclusion;
#else
uniform float occlusion;
#endif
#ifdef _RoughTex
uniform sampler2D srough;
#else
uniform float roughness;
#endif
#ifdef _RoughStr
uniform float roughnessStrength;
#endif
#ifdef _MetTex
uniform sampler2D smetal;
#else
uniform float metalness;
#endif
uniform sampler2D sheight;
uniform float heightStrength;
in vec2 te_texCoord;
#ifdef _NorTex
in mat3 TBN;
#else
in vec3 te_normal;
#endif
out vec4[2] fragColor;
void main() {
vec2 newCoord = te_texCoord;
#ifdef _NorTex
vec3 n = (texture(snormal, newCoord).rgb * 2.0 - 1.0);
n = normalize(TBN * normalize(n));
#else
vec3 n = normalize(te_normal);
#endif
#ifdef _NorStr
n *= normalStrength;
#endif
vec3 baseColor = vec3(1.0);//matColor.rgb;
#ifdef _BaseTex
vec4 texel = texture(sbase, newCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
texel.rgb = pow(texel.rgb, vec3(2.2)); // Variant 1
baseColor *= texel.rgb;
#endif
#ifdef _MetTex
float metalness = texture(smetal, newCoord).r;
#endif
#ifdef _RoughTex
float roughness = texture(srough, newCoord).r;
#endif
#ifdef _RoughStr
roughness *= roughnessStrength;
#endif
#ifdef _OccTex
float occ = texture(socclusion, newCoord).r;
#else
float occ = occlusion;
#endif
// Pack normal
n /= (abs(n.x) + abs(n.y) + abs(n.z));
n.xy = n.z >= 0.0 ? n.xy : octahedronWrap(n.xy);
// fragColor[0] = vec4(n.xy, packFloat(metalness, roughness), mask);
// TODO: Can not read and test depth buffer at once, fetch depth from g0
fragColor[0] = vec4(n.xy, packFloat(metalness, roughness), 1.0 - gl_FragCoord.z);
fragColor[1] = vec4(baseColor.rgb, occ);
}

View file

@ -7,6 +7,9 @@ precision highp float;
layout(vertices = 3) out;
in vec3 v_position[];
in vec2 v_texCoord[];
#ifdef _Tex1
in vec2 v_texCoord1[];
#endif
in vec3 v_normal[];
#ifdef _NorTex
in vec3 v_tangent[];
@ -14,6 +17,9 @@ in vec3 v_normal[];
out vec3 tc_position[];
out vec2 tc_texCoord[];
#ifdef _Tex1
out vec2 tc_texCoord1[];
#endif
out vec3 tc_normal[];
#ifdef _NorTex
out vec3 tc_tangent[];
@ -27,6 +33,9 @@ uniform float outerLevel;
void main() {
tc_position[ID] = v_position[ID];
tc_texCoord[ID] = v_texCoord[ID];
#ifdef _Tex1
tc_texCoord1[ID] = v_texCoord1[ID];
#endif
tc_normal[ID] = v_normal[ID];
#ifdef _NorTex
tc_tangent[ID] = v_tangent[ID];

View file

@ -7,16 +7,23 @@ precision highp float;
layout(triangles, equal_spacing, ccw) in;
in vec3 tc_position[];
in vec2 tc_texCoord[];
#ifdef _Tex1
in vec2 tc_texCoord1[];
#endif
in vec3 tc_normal[];
#ifdef _NorTex
in vec3 tc_tangent[];
#endif
out vec2 te_texCoord;
out vec4 matColor;
out vec2 texCoord;
#ifdef _Tex1
out vec2 texCoord1;
#endif
#ifdef _NorTex
out mat3 TBN;
#else
out vec3 te_normal;
out vec3 normal;
#endif
uniform mat4 WVP;
@ -25,6 +32,8 @@ uniform sampler2D sheight;
uniform float heightStrength;
void main() {
matColor = vec4(1.0);
vec3 p0 = gl_TessCoord.x * tc_position[0];
vec3 p1 = gl_TessCoord.y * tc_position[1];
vec3 p2 = gl_TessCoord.z * tc_position[2];
@ -33,16 +42,27 @@ void main() {
vec3 n0 = gl_TessCoord.x * tc_normal[0];
vec3 n1 = gl_TessCoord.y * tc_normal[1];
vec3 n2 = gl_TessCoord.z * tc_normal[2];
vec3 _te_normal = normalize(n0 + n1 + n2);
vec3 _normal = normalize(n0 + n1 + n2);
vec2 tc0 = gl_TessCoord.x * tc_texCoord[0];
vec2 tc1 = gl_TessCoord.y * tc_texCoord[1];
vec2 tc2 = gl_TessCoord.z * tc_texCoord[2];
te_texCoord = tc0 + tc1 + tc2;
texCoord = tc0 + tc1 + tc2;
te_position += _te_normal * texture(sheight, te_texCoord).r * heightStrength;
#ifdef _Tex1
vec2 tc01 = gl_TessCoord.x * tc_texCoord1[0];
vec2 tc11 = gl_TessCoord.y * tc_texCoord1[1];
vec2 tc21 = gl_TessCoord.z * tc_texCoord1[2];
texCoord1 = tc01 + tc11 + tc21;
#endif
#ifdef _HeightTex1
te_position += _normal * texture(sheight, texCoord1).r * heightStrength;
#else
te_position += _normal * texture(sheight, texCoord).r * heightStrength;
#endif
_te_normal = normalize(mat3(N) * _te_normal);
_normal = normalize(mat3(N) * _normal);
#ifdef _NorTex
vec3 t0 = gl_TessCoord.x * tc_tangent[0];
@ -51,10 +71,10 @@ void main() {
vec3 te_tangent = normalize(t0 + t1 + t2);
vec3 tangent = normalize(mat3(N) * (te_tangent));
vec3 bitangent = normalize(cross(_te_normal, tangent));
TBN = mat3(tangent, bitangent, _te_normal);
vec3 bitangent = normalize(cross(_normal, tangent));
TBN = mat3(tangent, bitangent, _normal);
#else
te_normal = _te_normal;
normal = _normal;
#endif
gl_Position = WVP * vec4(te_position, 1.0);

View file

@ -9,6 +9,9 @@ precision highp float;
in vec3 pos;
in vec3 nor;
in vec2 tex;
#ifdef _Tex1
in vec2 tex1;
#endif
#ifdef _VCols
in vec3 col;
#endif
@ -24,11 +27,21 @@ in vec2 tex;
#endif
out vec3 v_position;
out vec2 v_texCoord;
out vec3 v_normal;
out vec2 v_texCoord;
#ifdef _Tex1
out vec2 v_texCoord1;
#endif
// #ifdef _VCols
// out vec3 v_color;
// #endif
#ifdef _NorTex
out vec3 v_tangent;
#endif
// #ifdef _Skinning
// out vec4 v_bone;
// out vec4 v_weight;
// #endif
// uniform sampler2D sheight;
// uniform float heightStrength;
@ -40,9 +53,21 @@ void main() {
#endif
v_texCoord = tex;
#ifdef _Tex1
v_texCoord1 = tex1;
#endif
v_normal = nor;
#ifdef _NorTex
v_tangent = tan;
#endif
// v_position += v_normal * texture(sheight, tex).r * heightStrength;
// #ifdef _VCols
// v_color = col;
// #endif
// #ifdef _Skinning
// v_bone = bone;
// v_weight = weight;
// #endif
}

View file

@ -145,6 +145,158 @@
"vertex_shader": "mesh.vert.glsl",
"fragment_shader": "mesh.frag.glsl"
},
{
"name": "meshheight",
"depth_write": true,
"compare_mode": "less",
"cull_mode": "clockwise",
"links": [
{
"name": "WVP",
"link": "_worldViewProjectionMatrix"
},
{
"name": "W",
"link": "_worldMatrix"
},
{
"name": "N",
"link": "_normalMatrix"
},
{
"name": "V",
"link": "_viewMatrix"
},
{
"name": "P",
"link": "_projectionMatrix"
},
{
"name": "LWVP",
"link": "_lampWorldViewProjectionMatrix",
"ifndef": "_NoShadows"
},
{
"name": "lightPos",
"link": "_lampPosition"
},
{
"name": "lightDir",
"link": "_lampDirection"
},
{
"name": "lightColor",
"link": "_lampColor"
},
{
"name": "lightStrength",
"link": "_lampStrength"
},
{
"name": "shadowsBias",
"link": "_lampShadowsBias"
},
{
"name": "spotlightCutoff",
"link": "_spotlampCutoff"
},
{
"name": "spotlightExponent",
"link": "_spotlampExponent"
},
{
"name": "lightType",
"link": "_lampType"
},
{
"name": "eye",
"link": "_cameraPosition"
},
{
"name": "skinBones",
"link": "_skinBones",
"ifdef": ["_Skinning"]
},
{
"name": "shirr",
"link": "_envmapIrradiance"
},
{
"name": "senvmapRadiance",
"link": "_envmapRadiance",
"ifdef": ["_Rad"]
},
{
"name": "envmapNumMipmaps",
"link": "_envmapNumMipmaps",
"ifdef": ["_Rad"]
},
{
"name": "senvmapBrdf",
"link": "_envmapBrdf",
"ifdef": ["_Rad"]
},
{
"name": "envmapStrength",
"link": "_envmapStrength"
},
{
"name": "U",
"link": "_undistortionMatrix",
"ifdef": ["_VR"]
},
{
"name": "maxRadSq",
"link": "_maxRadiusSq",
"ifdef": ["_VR"]
},
{
"name": "snoise",
"link": "_noise64",
"ifdef": ["_PCSS"]
},
{
"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": "meshheight.vert.glsl",
"fragment_shader": "meshheight.frag.glsl",
"fragment_shader_path": "mesh.frag.glsl",
"tesscontrol_shader": "meshheight.tesc.glsl",
"tesseval_shader": "meshheight.tese.glsl"
},
{
"name": "overlay",
"depth_write": true,
@ -252,6 +404,31 @@
"fragment_shader": "shadowmap.frag.glsl",
"fragment_shader_path": "../include/shadowmap.frag.glsl"
},
{
"name": "shadowmapheight",
"depth_write": true,
"compare_mode": "less_equal",
"cull_mode": "clockwise",
"links": [
{
"name": "LWVP",
"link": "_lampWorldViewProjectionMatrix"
},
{
"name": "skinBones",
"link": "_skinBones",
"ifdef": ["_Skinning"]
}
],
"vertex_shader": "shadowmapheight.vert.glsl",
"vertex_shader_path": "../include/shadowmapheight.vert.glsl",
"fragment_shader": "shadowmapheight.frag.glsl",
"fragment_shader_path": "../include/shadowmap.frag.glsl",
"tesscontrol_shader": "shadowmapheight.tesc.glsl",
"tesscontrol_shader_path": "../include/shadowmapheight.tesc.glsl",
"tesseval_shader": "shadowmapheight.tese.glsl",
"tesseval_shader_path": "../include/shadowmapheight.tese.glsl"
},
{
"name": "translucent",
"depth_write": false,

View file

@ -0,0 +1,54 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
layout(vertices = 3) out;
in vec3 v_position[];
in vec2 v_texCoord[];
#ifdef _Tex1
in vec2 v_texCoord1[];
#endif
in vec3 v_normal[];
#ifdef _NorTex
in vec3 v_tangent[];
#endif
out vec3 tc_position[];
out vec2 tc_texCoord[];
#ifdef _Tex1
out vec2 tc_texCoord1[];
#endif
out vec3 tc_normal[];
#ifdef _NorTex
out vec3 tc_tangent[];
#endif
uniform float innerLevel;
uniform float outerLevel;
#define ID gl_InvocationID
void main() {
tc_position[ID] = v_position[ID];
tc_texCoord[ID] = v_texCoord[ID];
#ifdef _Tex1
tc_texCoord1[ID] = v_texCoord1[ID];
#endif
tc_normal[ID] = v_normal[ID];
#ifdef _NorTex
tc_tangent[ID] = v_tangent[ID];
#endif
if (ID == 0) {
gl_TessLevelInner[0] = innerLevel;
gl_TessLevelInner[1] = innerLevel;
gl_TessLevelOuter[0] = outerLevel;
gl_TessLevelOuter[1] = outerLevel;
gl_TessLevelOuter[2] = outerLevel;
gl_TessLevelOuter[3] = outerLevel;
}
}

View file

@ -0,0 +1,98 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
layout(triangles, equal_spacing, ccw) in;
in vec3 tc_position[];
in vec2 tc_texCoord[];
#ifdef _Tex1
in vec2 tc_texCoord1[];
#endif
in vec3 tc_normal[];
#ifdef _NorTex
in vec3 tc_tangent[];
#endif
out vec3 position;
out vec2 texCoord;
#ifdef _Tex1
out vec2 texCoord1;
#endif
#ifndef _NoShadows
out vec4 lampPos;
#endif
out vec4 matColor;
out vec3 eyeDir;
#ifdef _NorTex
out mat3 TBN;
#else
out vec3 normal;
#endif
uniform mat4 WVP;
uniform mat4 N;
uniform sampler2D sheight;
uniform float heightStrength;
#ifndef _NoShadows
uniform mat4 LWVP;
#endif
uniform mat4 W;
uniform vec3 eye;
uniform vec4 baseCol;
void main() {
vec3 p0 = gl_TessCoord.x * tc_position[0];
vec3 p1 = gl_TessCoord.y * tc_position[1];
vec3 p2 = gl_TessCoord.z * tc_position[2];
vec3 s_position = p0 + p1 + p2;
vec3 n0 = gl_TessCoord.x * tc_normal[0];
vec3 n1 = gl_TessCoord.y * tc_normal[1];
vec3 n2 = gl_TessCoord.z * tc_normal[2];
vec3 _te_normal = normalize(n0 + n1 + n2);
vec2 tc0 = gl_TessCoord.x * tc_texCoord[0];
vec2 tc1 = gl_TessCoord.y * tc_texCoord[1];
vec2 tc2 = gl_TessCoord.z * tc_texCoord[2];
texCoord = tc0 + tc1 + tc2;
#ifdef _Tex1
vec2 tc01 = gl_TessCoord.x * tc_texCoord1[0];
vec2 tc11 = gl_TessCoord.y * tc_texCoord1[1];
vec2 tc21 = gl_TessCoord.z * tc_texCoord1[2];
texCoord1 = tc01 + tc11 + tc21;
#endif
s_position += _te_normal * texture(sheight, texCoord).r * heightStrength;
position = vec4(W * vec4(s_position, 1.0)).xyz;
_te_normal = normalize(mat3(N) * _te_normal);
#ifdef _NorTex
vec3 t0 = gl_TessCoord.x * tc_tangent[0];
vec3 t1 = gl_TessCoord.y * tc_tangent[1];
vec3 t2 = gl_TessCoord.z * tc_tangent[2];
vec3 te_tangent = normalize(t0 + t1 + t2);
vec3 tangent = normalize(mat3(N) * (te_tangent));
vec3 bitangent = normalize(cross(_te_normal, tangent));
TBN = mat3(tangent, bitangent, _te_normal);
#else
normal = _te_normal;
#endif
#ifndef _NoShadows
lampPos = LWVP * vec4(s_position, 1.0);
#endif
matColor = baseCol;
// #ifdef _VCols
// matColor.rgb *= col;
// #endif
eyeDir = eye - position;
gl_Position = WVP * vec4(s_position, 1.0);
}

View file

@ -0,0 +1,107 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
#include "../compiled.glsl"
#ifdef _Skinning
#include "../std/skinning.glsl"
// getSkinningDualQuat()
#endif
#ifdef _VR
#include "../std/vr.glsl"
// undistort()
#endif
in vec3 pos;
in vec3 nor;
in vec2 tex;
#ifdef _Tex1
in vec2 tex1;
#endif
#ifdef _VCols
in vec3 col;
#endif
#ifdef _NorTex
in vec3 tan;
#endif
#ifdef _Skinning
in vec4 bone;
in vec4 weight;
#endif
#ifdef _Instancing
in vec3 off;
#endif
uniform mat4 N;
#ifdef _Billboard
uniform mat4 WV;
uniform mat4 P;
#endif
uniform mat4 W;
uniform mat4 V;
uniform mat4 P;
#ifndef _NoShadows
uniform mat4 LWVP;
#endif
#ifdef _Skinning
//!uniform float skinBones[skinMaxBones * 8];
#endif
#ifdef _VR
// !uniform mat4 U;
// !uniform float maxRadSq;
#endif
out vec3 v_position;
out vec2 v_texCoord;
#ifdef _Tex1
out vec2 v_texCoord1;
#endif
out vec3 v_normal;
#ifdef _NorTex
out vec3 v_tangent;
#endif
void main() {
vec4 sPos = vec4(pos, 1.0);
#ifdef _Skinning
vec4 skinA;
vec4 skinB;
getSkinningDualQuat(ivec4(bone), weight, skinA, skinB);
sPos.xyz += 2.0 * cross(skinA.xyz, cross(skinA.xyz, sPos.xyz) + skinA.w * sPos.xyz); // Rotate
sPos.xyz += 2.0 * (skinA.w * skinB.xyz - skinB.w * skinA.xyz + cross(skinA.xyz, skinB.xyz)); // Translate
vec3 _normal = normalize(mat3(N) * (nor + 2.0 * cross(skinA.xyz, cross(skinA.xyz, nor) + skinA.w * nor)));
#else
vec3 _normal = normalize(mat3(N) * nor);
#endif
#ifdef _Instancing
sPos.xyz += off;
#endif
// mat4 WV = V * W;
// #ifdef _Billboard
// // Spherical
// WV[0][0] = 1.0; WV[0][1] = 0.0; WV[0][2] = 0.0;
// WV[1][0] = 0.0; WV[1][1] = 1.0; WV[1][2] = 0.0;
// WV[2][0] = 0.0; WV[2][1] = 0.0; WV[2][2] = 1.0;
// // Cylindrical
// //WV[0][0] = 1.0; WV[0][1] = 0.0; WV[0][2] = 0.0;
// //WV[2][0] = 0.0; WV[2][1] = 0.0; WV[2][2] = 1.0;
// #endif
v_texCoord = tex;
#ifdef _Tex1
v_texCoord1 = tex1;
#endif
v_position = sPos.xyz;
v_normal = nor;
#ifdef _NorTex
v_tangent = tan;
#endif
}

View file

@ -110,6 +110,119 @@
"vertex_shader": "mesh.vert.glsl",
"fragment_shader": "mesh.frag.glsl"
},
{
"name": "meshheight",
"depth_write": false,
"compare_mode": "less_equal",
"cull_mode": "clockwise",
"links": [
{
"name": "W",
"link": "_worldMatrix"
},
{
"name": "N",
"link": "_normalMatrix"
},
{
"name": "WV",
"link": "_worldViewMatrix",
"ifdef": ["_Billboard"]
},
{
"name": "P",
"link": "_projectionMatrix",
"ifdef": ["_Billboard"]
},
{
"name": "WVP",
"link": "_worldViewProjectionMatrix"
},
{
"name": "LWVP",
"link": "_lampWorldViewProjectionMatrix"
},
{
"name": "lightPos",
"link": "_lampPosition"
},
{
"name": "lightDir",
"link": "_lampDirection"
},
{
"name": "lightColor",
"link": "_lampColor"
},
{
"name": "lightStrength",
"link": "_lampStrength"
},
{
"name": "shadowsBias",
"link": "_lampShadowsBias"
},
{
"name": "spotlightCutoff",
"link": "_spotlampCutoff"
},
{
"name": "spotlightExponent",
"link": "_spotlampExponent"
},
{
"name": "lightType",
"link": "_lampType"
},
{
"name": "eye",
"link": "_cameraPosition"
},
{
"name": "skinBones",
"link": "_skinBones",
"ifdef": ["_Skinning"]
},
{
"name": "shirr",
"link": "_envmapIrradiance"
},
{
"name": "senvmapRadiance",
"link": "_envmapRadiance",
"ifdef": ["_Rad"]
},
{
"name": "envmapNumMipmaps",
"link": "_envmapNumMipmaps",
"ifdef": ["_Rad"]
},
{
"name": "senvmapBrdf",
"link": "_envmapBrdf",
"ifdef": ["_Rad"]
},
{
"name": "envmapStrength",
"link": "_envmapStrength"
},
{
"name": "snoise",
"link": "_noise64",
"ifdef": ["_PCSS"]
},
{
"name": "lampSizeUV",
"link": "_lampSizeUV",
"ifdef": ["_PCSS"]
}
],
"vertex_shader": "meshheight.vert.glsl",
"fragment_shader": "meshheight.frag.glsl",
"fragment_shader_path": "mesh.frag.glsl",
"tesscontrol_shader": "meshheight.tesc.glsl",
"tesseval_shader": "meshheight.tese.glsl"
},
{
"name": "overlay",
"depth_write": true,
@ -207,6 +320,31 @@
"fragment_shader": "shadowmap.frag.glsl",
"fragment_shader_path": "../include/shadowmap.frag.glsl"
},
{
"name": "shadowmapheight",
"depth_write": true,
"compare_mode": "less_equal",
"cull_mode": "clockwise",
"links": [
{
"name": "LWVP",
"link": "_lampWorldViewProjectionMatrix"
},
{
"name": "skinBones",
"link": "_skinBones",
"ifdef": ["_Skinning"]
}
],
"vertex_shader": "shadowmapheight.vert.glsl",
"vertex_shader_path": "../include/shadowmapheight.vert.glsl",
"fragment_shader": "shadowmapheight.frag.glsl",
"fragment_shader_path": "../include/shadowmap.frag.glsl",
"tesscontrol_shader": "shadowmapheight.tesc.glsl",
"tesscontrol_shader_path": "../include/shadowmapheight.tesc.glsl",
"tesseval_shader": "shadowmapheight.tese.glsl",
"tesseval_shader_path": "../include/shadowmapheight.tese.glsl"
},
{
"name": "depthwrite",
"depth_write": true,
@ -242,6 +380,45 @@
"fragment_shader": "depthwrite.frag.glsl",
"fragment_shader_path": "../include/shadowmap.frag.glsl"
},
{
"name": "depthwriteheight",
"depth_write": true,
"compare_mode": "less",
"cull_mode": "clockwise",
"color_write_red": false,
"color_write_green": false,
"color_write_blue": false,
"color_write_alpha": false,
"links": [
{
"name": "LWVP",
"link": "_worldViewProjectionMatrix"
},
{
"name": "P",
"link": "_projectionMatrix",
"ifdef": ["_Billboard"]
},
{
"name": "WV",
"link": "_worldViewMatrix",
"ifdef": ["_Billboard"]
},
{
"name": "skinBones",
"link": "_skinBones",
"ifdef": ["_Skinning"]
}
],
"vertex_shader": "depthwriteheight.vert.glsl",
"vertex_shader_path": "../include/shadowmapheight.vert.glsl",
"fragment_shader": "depthwriteheight.frag.glsl",
"fragment_shader_path": "../include/shadowmap.frag.glsl",
"tesscontrol_shader": "depthwriteheight.tesc.glsl",
"tesscontrol_shader_path": "../include/shadowmapheight.tesc.glsl",
"tesseval_shader": "depthwriteheight.tese.glsl",
"tesseval_shader_path": "../include/shadowmapheight.tese.glsl"
},
{
"name": "translucent",
"depth_write": false,

View file

@ -0,0 +1,54 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
layout(vertices = 3) out;
in vec3 v_position[];
in vec2 v_texCoord[];
#ifdef _Tex1
in vec2 v_texCoord1[];
#endif
in vec3 v_normal[];
#ifdef _NorTex
in vec3 v_tangent[];
#endif
out vec3 tc_position[];
out vec2 tc_texCoord[];
#ifdef _Tex1
out vec2 tc_texCoord1[];
#endif
out vec3 tc_normal[];
#ifdef _NorTex
out vec3 tc_tangent[];
#endif
uniform float innerLevel;
uniform float outerLevel;
#define ID gl_InvocationID
void main() {
tc_position[ID] = v_position[ID];
tc_texCoord[ID] = v_texCoord[ID];
#ifdef _Tex1
tc_texCoord1[ID] = v_texCoord1[ID];
#endif
tc_normal[ID] = v_normal[ID];
#ifdef _NorTex
tc_tangent[ID] = v_tangent[ID];
#endif
if (ID == 0) {
gl_TessLevelInner[0] = innerLevel;
gl_TessLevelInner[1] = innerLevel;
gl_TessLevelOuter[0] = outerLevel;
gl_TessLevelOuter[1] = outerLevel;
gl_TessLevelOuter[2] = outerLevel;
gl_TessLevelOuter[3] = outerLevel;
}
}

View file

@ -0,0 +1,98 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
layout(triangles, equal_spacing, ccw) in;
in vec3 tc_position[];
in vec2 tc_texCoord[];
#ifdef _Tex1
in vec2 tc_texCoord1[];
#endif
in vec3 tc_normal[];
#ifdef _NorTex
in vec3 tc_tangent[];
#endif
out vec3 position;
out vec2 texCoord;
#ifdef _Tex1
out vec2 texCoord1;
#endif
// #ifndef _NoShadows
out vec4 lampPos;
// #endif
out vec4 matColor;
out vec3 eyeDir;
#ifdef _NorTex
out mat3 TBN;
#else
out vec3 normal;
#endif
uniform mat4 WVP;
uniform mat4 N;
uniform sampler2D sheight;
uniform float heightStrength;
// #ifndef _NoShadows
uniform mat4 LWVP;
// #endif
uniform mat4 W;
uniform vec3 eye;
uniform vec4 baseCol;
void main() {
vec3 p0 = gl_TessCoord.x * tc_position[0];
vec3 p1 = gl_TessCoord.y * tc_position[1];
vec3 p2 = gl_TessCoord.z * tc_position[2];
vec3 s_position = p0 + p1 + p2;
vec3 n0 = gl_TessCoord.x * tc_normal[0];
vec3 n1 = gl_TessCoord.y * tc_normal[1];
vec3 n2 = gl_TessCoord.z * tc_normal[2];
vec3 _te_normal = normalize(n0 + n1 + n2);
vec2 tc0 = gl_TessCoord.x * tc_texCoord[0];
vec2 tc1 = gl_TessCoord.y * tc_texCoord[1];
vec2 tc2 = gl_TessCoord.z * tc_texCoord[2];
texCoord = tc0 + tc1 + tc2;
#ifdef _Tex1
vec2 tc01 = gl_TessCoord.x * tc_texCoord1[0];
vec2 tc11 = gl_TessCoord.y * tc_texCoord1[1];
vec2 tc21 = gl_TessCoord.z * tc_texCoord1[2];
texCoord1 = tc01 + tc11 + tc21;
#endif
s_position += _te_normal * texture(sheight, texCoord).r * heightStrength;
position = vec4(W * vec4(s_position, 1.0)).xyz;
_te_normal = normalize(mat3(N) * _te_normal);
#ifdef _NorTex
vec3 t0 = gl_TessCoord.x * tc_tangent[0];
vec3 t1 = gl_TessCoord.y * tc_tangent[1];
vec3 t2 = gl_TessCoord.z * tc_tangent[2];
vec3 te_tangent = normalize(t0 + t1 + t2);
vec3 tangent = normalize(mat3(N) * (te_tangent));
vec3 bitangent = normalize(cross(_te_normal, tangent));
TBN = mat3(tangent, bitangent, _te_normal);
#else
normal = _te_normal;
#endif
// #ifndef _NoShadows
lampPos = LWVP * vec4(s_position, 1.0);
// #endif
matColor = baseCol;
// #ifdef _VCols
// matColor.rgb *= col;
// #endif
eyeDir = eye - position;
gl_Position = WVP * vec4(s_position, 1.0);
}

View file

@ -0,0 +1,107 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
#include "../compiled.glsl"
#ifdef _Skinning
#include "../std/skinning.glsl"
// getSkinningDualQuat()
#endif
#ifdef _VR
#include "../std/vr.glsl"
// undistort()
#endif
in vec3 pos;
in vec3 nor;
in vec2 tex;
#ifdef _Tex1
in vec2 tex1;
#endif
#ifdef _VCols
in vec3 col;
#endif
#ifdef _NorTex
in vec3 tan;
#endif
#ifdef _Skinning
in vec4 bone;
in vec4 weight;
#endif
#ifdef _Instancing
in vec3 off;
#endif
uniform mat4 N;
#ifdef _Billboard
uniform mat4 WV;
uniform mat4 P;
#endif
uniform mat4 W;
uniform mat4 V;
uniform mat4 P;
#ifndef _NoShadows
uniform mat4 LWVP;
#endif
#ifdef _Skinning
//!uniform float skinBones[skinMaxBones * 8];
#endif
#ifdef _VR
// !uniform mat4 U;
// !uniform float maxRadSq;
#endif
out vec3 v_position;
out vec2 v_texCoord;
#ifdef _Tex1
out vec2 v_texCoord1;
#endif
out vec3 v_normal;
#ifdef _NorTex
out vec3 v_tangent;
#endif
void main() {
vec4 sPos = vec4(pos, 1.0);
#ifdef _Skinning
vec4 skinA;
vec4 skinB;
getSkinningDualQuat(ivec4(bone), weight, skinA, skinB);
sPos.xyz += 2.0 * cross(skinA.xyz, cross(skinA.xyz, sPos.xyz) + skinA.w * sPos.xyz); // Rotate
sPos.xyz += 2.0 * (skinA.w * skinB.xyz - skinB.w * skinA.xyz + cross(skinA.xyz, skinB.xyz)); // Translate
vec3 _normal = normalize(mat3(N) * (nor + 2.0 * cross(skinA.xyz, cross(skinA.xyz, nor) + skinA.w * nor)));
#else
vec3 _normal = normalize(mat3(N) * nor);
#endif
#ifdef _Instancing
sPos.xyz += off;
#endif
// mat4 WV = V * W;
// #ifdef _Billboard
// // Spherical
// WV[0][0] = 1.0; WV[0][1] = 0.0; WV[0][2] = 0.0;
// WV[1][0] = 0.0; WV[1][1] = 1.0; WV[1][2] = 0.0;
// WV[2][0] = 0.0; WV[2][1] = 0.0; WV[2][2] = 1.0;
// // Cylindrical
// //WV[0][0] = 1.0; WV[0][1] = 0.0; WV[0][2] = 0.0;
// //WV[2][0] = 0.0; WV[2][1] = 0.0; WV[2][2] = 1.0;
// #endif
v_texCoord = tex;
#ifdef _Tex1
v_texCoord1 = tex1;
#endif
v_position = sPos.xyz;
v_normal = nor;
#ifdef _NorTex
v_tangent = tan;
#endif
}

View file

@ -2873,6 +2873,28 @@ class ArmoryExporter:
if ArmoryExporter.mesh_context_empty != '' and '_Translucent' not in defs:
c2 = {}
c2['name'] = ArmoryExporter.mesh_context_empty
# Depth pre-pass for height context
if '_HeightTex' in defs:
c2['name'] += 'height'
c2['bind_constants'] = []
c2['bind_textures'] = []
for bc in c['bind_constants']:
if bc['name'] == 'heightStrength':
c2['bind_constants'].append(bc)
break
for bt in c['bind_textures']:
if bt['name'] == 'sheight':
c2['bind_textures'].append(bt)
break
const = {}
const['name'] = 'innerLevel'
const['float'] = material.height_tess_inner
c2['bind_constants'].append(const)
const = {}
const['name'] = 'outerLevel'
const['float'] = material.height_tess_outer
c2['bind_constants'].append(const)
o['contexts'].append(c2)
# Material users
@ -3129,6 +3151,8 @@ class ArmoryExporter:
# Process all passes from render path
if with_tess: # TODO: properly handle adding height pass shaders to khafile
rpasses = [ArmoryExporter.mesh_context + 'height']
if ArmoryExporter.mesh_context_empty != '':
rpasses.append(ArmoryExporter.mesh_context_empty + 'height')
if bpy.data.worlds['Arm'].generate_shadows == True:
rpasses.append(ArmoryExporter.shadows_context + 'height')
else:

View file

@ -303,7 +303,7 @@ def parse_bsdf_diffuse(self, material, c, defs, tree, node, factor):
normal_map_node = nodes.find_node_by_link(tree, node, normal_input)
if normal_map_node.type == 'NORMAL_MAP':
normal_map_input = normal_map_node.inputs[1]
parse_normal_map_socket(self, normal_map_input, material, c, defs, tree, node, factor)
parse_normal_map_socket(self, normal_map_input, material, c, defs, tree, normal_map_node, factor)
def parse_emission(self, material, c, defs, tree, node, factor):
# Color