mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 13:44:56 +00:00
Refactor for blender 2.8 and new shader model
This commit is contained in:
@@ -2,7 +2,7 @@ include_directories(../hecl/include
|
||||
../hecl/extern/boo/include
|
||||
../hecl/extern/boo/logvisor/include
|
||||
../hecl/extern/athena/include
|
||||
../specter/zeus/include
|
||||
../DataSpec
|
||||
../Runtime)
|
||||
add_shader(CAABoxShader)
|
||||
add_shader(CCameraBlurFilter)
|
||||
@@ -35,3 +35,7 @@ add_special_shader(shader_CFluidPlaneShader
|
||||
shader_CFluidPlaneShaderGLSL.cpp
|
||||
shader_CFluidPlaneShaderHLSL.cpp
|
||||
shader_CFluidPlaneShaderMetal.cpp)
|
||||
add_special_shader(shader_CModelShaders
|
||||
shader_CModelShadersGLSL.cpp
|
||||
shader_CModelShadersHLSL.cpp
|
||||
shader_CModelShadersMetal.cpp)
|
||||
18
Shaders/CModelShaders.common.glsl
Normal file
18
Shaders/CModelShaders.common.glsl
Normal file
@@ -0,0 +1,18 @@
|
||||
#extension GL_ARB_enhanced_layouts: enable
|
||||
#extension GL_ARB_shader_image_load_store: enable
|
||||
|
||||
struct VertToFrag {
|
||||
vec4 mvPos;
|
||||
vec4 mvNorm;
|
||||
vec4 color;
|
||||
vec2 lightmapUv;
|
||||
vec2 diffuseUv;
|
||||
vec2 emissiveUv;
|
||||
vec2 specularUv;
|
||||
vec2 extendedSpecularUv;
|
||||
vec2 reflectionUv;
|
||||
vec2 alphaUv;
|
||||
vec2 extUvs[3];
|
||||
vec2 dynReflectionUvs[2];
|
||||
float dynReflectionAlpha;
|
||||
};
|
||||
348
Shaders/CModelShaders.frag.glsl
Normal file
348
Shaders/CModelShaders.frag.glsl
Normal file
@@ -0,0 +1,348 @@
|
||||
#if !defined(URDE_ALPHA_TEST) && defined(GL_ARB_shader_image_load_store)
|
||||
layout(early_fragment_tests) in;
|
||||
#endif
|
||||
|
||||
SBINDING(0) in VertToFrag vtf;
|
||||
TBINDING0 uniform sampler2D lightmap;
|
||||
TBINDING1 uniform sampler2D diffuse;
|
||||
TBINDING2 uniform sampler2D emissive;
|
||||
TBINDING3 uniform sampler2D specular;
|
||||
TBINDING4 uniform sampler2D extendedSpecular;
|
||||
TBINDING5 uniform sampler2D reflection;
|
||||
TBINDING6 uniform sampler2D alpha;
|
||||
TBINDING7 uniform sampler2D reflectionIndTex;
|
||||
TBINDING8 uniform sampler2D extTex0;
|
||||
TBINDING9 uniform sampler2D extTex1;
|
||||
TBINDING10 uniform sampler2D extTex2;
|
||||
TBINDING11 uniform sampler2D reflectionTex;
|
||||
|
||||
const vec3 kRGBToYPrime = vec3(0.257, 0.504, 0.098);
|
||||
|
||||
/*
|
||||
#if defined(ALPHA_%s)
|
||||
vec3 SampleTexture_%s() { return texture(%s, vtf.%sUv).aaa; }
|
||||
float SampleTextureAlpha_%s() { return texture(%s, vtf.%sUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_%s() { return texture(%s, vtf.%sUv).rgb; }
|
||||
float SampleTextureAlpha_%s() { return dot(texture(%s, vtf.%sUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
*/
|
||||
|
||||
#if defined(ALPHA_lightmap)
|
||||
vec3 SampleTexture_lightmap() { return texture(lightmap, vtf.lightmapUv).aaa; }
|
||||
float SampleTextureAlpha_lightmap() { return texture(lightmap, vtf.lightmapUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_lightmap() { return texture(lightmap, vtf.lightmapUv).rgb; }
|
||||
float SampleTextureAlpha_lightmap() { return dot(texture(lightmap, vtf.lightmapUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA_diffuse)
|
||||
vec3 SampleTexture_diffuse() { return texture(diffuse, vtf.diffuseUv).aaa; }
|
||||
float SampleTextureAlpha_diffuse() { return texture(diffuse, vtf.diffuseUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_diffuse() { return texture(diffuse, vtf.diffuseUv).rgb; }
|
||||
float SampleTextureAlpha_diffuse() { return dot(texture(diffuse, vtf.diffuseUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA_emissive)
|
||||
vec3 SampleTexture_emissive() { return texture(emissive, vtf.emissiveUv).aaa; }
|
||||
float SampleTextureAlpha_emissive() { return texture(emissive, vtf.emissiveUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_emissive() { return texture(emissive, vtf.emissiveUv).rgb; }
|
||||
float SampleTextureAlpha_emissive() { return dot(texture(emissive, vtf.emissiveUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA_specular)
|
||||
vec3 SampleTexture_specular() { return texture(specular, vtf.specularUv).aaa; }
|
||||
float SampleTextureAlpha_specular() { return texture(specular, vtf.specularUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_specular() { return texture(specular, vtf.specularUv).rgb; }
|
||||
float SampleTextureAlpha_specular() { return dot(texture(specular, vtf.specularUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA_extendedSpecular)
|
||||
vec3 SampleTexture_extendedSpecular() { return texture(extendedSpecular, vtf.extendedSpecularUv).aaa; }
|
||||
float SampleTextureAlpha_extendedSpecular() { return texture(extendedSpecular, vtf.extendedSpecularUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_extendedSpecular() { return texture(extendedSpecular, vtf.extendedSpecularUv).rgb; }
|
||||
float SampleTextureAlpha_extendedSpecular() { return dot(texture(extendedSpecular, vtf.extendedSpecularUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA_reflection)
|
||||
vec3 SampleTexture_reflection() { return texture(reflection, vtf.reflectionUv).aaa; }
|
||||
float SampleTextureAlpha_reflection() { return texture(reflection, vtf.reflectionUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_reflection() { return texture(reflection, vtf.reflectionUv).rgb; }
|
||||
float SampleTextureAlpha_reflection() { return dot(texture(reflection, vtf.reflectionUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA_alpha)
|
||||
vec3 SampleTexture_alpha() { return texture(alpha, vtf.alphaUv).aaa; }
|
||||
float SampleTextureAlpha_alpha() { return texture(alpha, vtf.alphaUv).a; }
|
||||
#else
|
||||
vec3 SampleTexture_alpha() { return texture(alpha, vtf.alphaUv).rgb; }
|
||||
float SampleTextureAlpha_alpha() { return dot(texture(alpha, vtf.alphaUv).rgb, kRGBToYPrime); }
|
||||
#endif
|
||||
|
||||
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_DISINTEGRATE)
|
||||
struct Fog {
|
||||
vec4 color;
|
||||
float A;
|
||||
float B;
|
||||
float C;
|
||||
int mode;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW)
|
||||
struct Light {
|
||||
vec4 pos;
|
||||
vec4 dir;
|
||||
vec4 color;
|
||||
vec4 linAtt;
|
||||
vec4 angAtt;
|
||||
};
|
||||
|
||||
UBINDING2 uniform LightingUniform {
|
||||
Light lights[URDE_MAX_LIGHTS];
|
||||
vec4 ambient;
|
||||
vec4 colorReg0;
|
||||
vec4 colorReg1;
|
||||
vec4 colorReg2;
|
||||
vec4 mulColor;
|
||||
vec4 addColor;
|
||||
Fog fog;
|
||||
};
|
||||
#else
|
||||
const vec4 colorReg0 = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
const vec4 colorReg1 = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
const vec4 colorReg2 = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
#endif
|
||||
|
||||
#if defined(URDE_LIGHTING)
|
||||
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
|
||||
vec4 ret = ambient;
|
||||
|
||||
for (int i = 0; i < URDE_MAX_LIGHTS; ++i) {
|
||||
vec3 delta = mvPosIn - lights[i].pos.xyz;
|
||||
float dist = length(delta);
|
||||
vec3 deltaNorm = delta / dist;
|
||||
float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0);
|
||||
float att = 1.0 / (lights[i].linAtt[2] * dist * dist +
|
||||
lights[i].linAtt[1] * dist +
|
||||
lights[i].linAtt[0]);
|
||||
float angAtt = lights[i].angAtt[2] * angDot * angDot +
|
||||
lights[i].angAtt[1] * angDot +
|
||||
lights[i].angAtt[0];
|
||||
ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0);
|
||||
}
|
||||
|
||||
return clamp(ret.rgb, vec3(0.0), vec3(1.0));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_THERMAL_HOT)
|
||||
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
|
||||
return vec3(1.0,1.0,1.0);
|
||||
}
|
||||
UBINDING2 uniform ThermalUniform {
|
||||
vec4 tmulColor;
|
||||
vec4 taddColor;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(URDE_THERMAL_COLD)
|
||||
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
|
||||
return vec3(1.0,1.0,1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_SOLID)
|
||||
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
|
||||
return vec3(1.0,1.0,1.0);
|
||||
}
|
||||
UBINDING2 uniform SolidUniform {
|
||||
vec4 solidColor;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(URDE_MB_SHADOW)
|
||||
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
|
||||
return vec3(1.0,1.0,1.0);
|
||||
}
|
||||
UBINDING2 uniform MBShadowUniform {
|
||||
vec4 shadowUp;
|
||||
float shadowId;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(URDE_LIGHTING_SHADOW)
|
||||
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
|
||||
vec2 shadowUV = vtf.extUvs[0];
|
||||
shadowUV.y = 1.0 - shadowUV.y;
|
||||
|
||||
vec4 ret = ambient;
|
||||
|
||||
vec3 delta = mvPosIn - lights[0].pos.xyz;
|
||||
float dist = length(delta);
|
||||
vec3 deltaNorm = delta / dist;
|
||||
float angDot = max(dot(deltaNorm, lights[0].dir.xyz), 0.0);
|
||||
float att = 1.0 / (lights[0].linAtt[2] * dist * dist +
|
||||
lights[0].linAtt[1] * dist +
|
||||
lights[0].linAtt[0]);
|
||||
float angAtt = lights[0].angAtt[2] * angDot * angDot +
|
||||
lights[0].angAtt[1] * angDot +
|
||||
lights[0].angAtt[0];
|
||||
ret += lights[0].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0) *
|
||||
texture(extTex0, shadowUV).r;
|
||||
|
||||
for (int i = 1; i < URDE_MAX_LIGHTS; ++i) {
|
||||
vec3 delta = mvPosIn - lights[i].pos.xyz;
|
||||
float dist = length(delta);
|
||||
vec3 deltaNorm = delta / dist;
|
||||
float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0);
|
||||
float att = 1.0 / (lights[i].linAtt[2] * dist * dist +
|
||||
lights[i].linAtt[1] * dist +
|
||||
lights[i].linAtt[0]);
|
||||
float angAtt = lights[i].angAtt[2] * angDot * angDot +
|
||||
lights[i].angAtt[1] * angDot +
|
||||
lights[i].angAtt[0];
|
||||
ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0);
|
||||
}
|
||||
|
||||
return clamp(ret.rgb, vec3(0.0), vec3(1.0));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_DISINTEGRATE)
|
||||
UBINDING2 uniform DisintegrateUniform {
|
||||
vec4 daddColor;
|
||||
Fog fog;
|
||||
};
|
||||
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
|
||||
return vec3(1.0,1.0,1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_DISINTEGRATE)
|
||||
vec4 FogFunc(vec4 colorIn) {
|
||||
float fogZ;
|
||||
float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0);
|
||||
switch (fog.mode) {
|
||||
case 2:
|
||||
fogZ = fogF;
|
||||
break;
|
||||
case 4:
|
||||
fogZ = 1.0 - exp2(-8.0 * fogF);
|
||||
break;
|
||||
case 5:
|
||||
fogZ = 1.0 - exp2(-8.0 * fogF * fogF);
|
||||
break;
|
||||
case 6:
|
||||
fogZ = exp2(-8.0 * (1.0 - fogF));
|
||||
break;
|
||||
case 7:
|
||||
fogF = 1.0 - fogF;
|
||||
fogZ = exp2(-8.0 * fogF * fogF);
|
||||
break;
|
||||
default:
|
||||
fogZ = 0.0;
|
||||
break;
|
||||
}
|
||||
#ifdef BLEND_DST_ONE
|
||||
return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);
|
||||
#else
|
||||
return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW)
|
||||
vec4 PostFunc(vec4 colorIn) {
|
||||
return FogFunc(colorIn) * mulColor + addColor;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_THERMAL_HOT)
|
||||
vec4 PostFunc(vec4 colorIn) {
|
||||
return texture(extTex0, vtf.extUvs[0]).rrrr * tmulColor + taddColor;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_THERMAL_COLD)
|
||||
vec4 PostFunc(vec4 colorIn) {
|
||||
return colorIn * vec4(0.75);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_SOLID)
|
||||
vec4 PostFunc(vec4 colorIn) {
|
||||
return solidColor;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_MB_SHADOW)
|
||||
vec4 PostFunc(vec4 colorIn) {
|
||||
float idTexel = texture(extTex0, vtf.extUvs[0]).a;
|
||||
float sphereTexel = texture(extTex1, vtf.extUvs[1]).a;
|
||||
float fadeTexel = texture(extTex2, vtf.extUvs[2]).a;
|
||||
float val = ((abs(idTexel - shadowId) < 0.001) ?
|
||||
(dot(vtf.mvNorm.xyz, shadowUp.xyz) * shadowUp.w) : 0.0) *
|
||||
sphereTexel * fadeTexel;
|
||||
return vec4(0.0, 0.0, 0.0, val);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_DISINTEGRATE)
|
||||
vec4 PostFunc(vec4 colorIn) {
|
||||
vec4 texel0 = texture(extTex0, vtf.extUvs[0]);
|
||||
vec4 texel1 = texture(extTex0, vtf.extUvs[1]);
|
||||
colorIn = mix(vec4(0.0), texel1, texel0);
|
||||
colorIn.rgb += daddColor.rgb;
|
||||
return FogFunc(colorIn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(URDE_REFLECTION_SIMPLE)
|
||||
vec3 ReflectionFunc() { return texture(reflectionTex, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; }
|
||||
#elif defined(URDE_REFLECTION_INDIRECT)
|
||||
vec3 ReflectionFunc() { return texture(reflectionTex, (texture(reflectionIndTex, vtf.dynReflectionUvs[0]).ab -
|
||||
vec2(0.5, 0.5)) * vec2(0.5, 0.5) + vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; }
|
||||
#else
|
||||
vec3 ReflectionFunc() { return vec3(0.0, 0.0, 0.0); }
|
||||
#endif
|
||||
|
||||
layout(location=0) out vec4 colorOut;
|
||||
void main() {
|
||||
vec3 lighting = LightingFunc(vtf.mvPos.xyz, vtf.mvNorm.xyz);
|
||||
vec4 tmp;
|
||||
#if defined(URDE_DIFFUSE_ONLY)
|
||||
tmp.rgb = SampleTexture_diffuse();
|
||||
tmp.a = SampleTextureAlpha_alpha();
|
||||
#elif defined(RETRO_SHADER)
|
||||
tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() +
|
||||
SampleTexture_emissive() + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) *
|
||||
SampleTexture_reflection() + ReflectionFunc();
|
||||
tmp.a = SampleTextureAlpha_alpha();
|
||||
#elif defined(RETRO_DYNAMIC_SHADER)
|
||||
tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() * colorReg1.rgb +
|
||||
SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) *
|
||||
SampleTexture_reflection() + ReflectionFunc();
|
||||
tmp.a = SampleTextureAlpha_alpha();
|
||||
#elif defined(RETRO_DYNAMIC_ALPHA_SHADER)
|
||||
tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() * colorReg1.rgb +
|
||||
SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) *
|
||||
SampleTexture_reflection() + ReflectionFunc();
|
||||
tmp.a = SampleTextureAlpha_alpha() * colorReg1.a;
|
||||
#elif defined(RETRO_DYNAMIC_CHARACTER_SHADER)
|
||||
tmp.rgb = (SampleTexture_lightmap() + lighting) * SampleTexture_diffuse() +
|
||||
SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) *
|
||||
SampleTexture_reflection() + ReflectionFunc();
|
||||
tmp.a = SampleTextureAlpha_alpha();
|
||||
#endif
|
||||
colorOut = PostFunc(tmp);
|
||||
#if defined(URDE_ALPHA_TEST)
|
||||
if (colorOut.a < 0.25)
|
||||
discard;
|
||||
#endif
|
||||
}
|
||||
61
Shaders/CModelShaders.vert.glsl
Normal file
61
Shaders/CModelShaders.vert.glsl
Normal file
@@ -0,0 +1,61 @@
|
||||
UBINDING0 uniform HECLVertUniform {
|
||||
#if URDE_SKIN_SLOTS
|
||||
mat4 objs[URDE_SKIN_SLOTS];
|
||||
mat4 objsInv[URDE_SKIN_SLOTS];
|
||||
#endif
|
||||
mat4 mv;
|
||||
mat4 mvInv;
|
||||
mat4 proj;
|
||||
};
|
||||
|
||||
struct HECLTCGMatrix {
|
||||
mat4 mtx;
|
||||
mat4 postMtx;
|
||||
};
|
||||
UBINDING1 uniform HECLTexMtxUniform {
|
||||
HECLTCGMatrix texMtxs[8];
|
||||
};
|
||||
|
||||
UBINDING3 uniform HECLReflectMtx {
|
||||
mat4 indMtx;
|
||||
mat4 reflectMtx;
|
||||
float reflectAlpha;
|
||||
};
|
||||
|
||||
layout(location=0) in vec3 posIn;
|
||||
layout(location=1) in vec3 normIn;
|
||||
#if URDE_COL_SLOTS
|
||||
layout(location=2) in vec4 colIn[URDE_COL_SLOTS];
|
||||
#endif
|
||||
#if URDE_UV_SLOTS
|
||||
layout(location=2 + URDE_COL_SLOTS) in vec2 uvIn[URDE_UV_SLOTS];
|
||||
#endif
|
||||
#if URDE_WEIGHT_SLOTS
|
||||
layout(location=2 + URDE_COL_SLOTS + URDE_UV_SLOTS) in vec4 weightIn[URDE_WEIGHT_SLOTS];
|
||||
#endif
|
||||
|
||||
SBINDING(0) out VertToFrag vtf;
|
||||
void main() {
|
||||
#if URDE_SKIN_SLOTS
|
||||
vec4 objPos = vec4(0.0,0.0,0.0,0.0);
|
||||
vec4 objNorm = vec4(0.0,0.0,0.0,0.0);
|
||||
for (int i = 0; i < URDE_SKIN_SLOTS; ++i) {
|
||||
objPos += (objs[i] * vec4(posIn, 1.0)) * weightIn[i / 4][i % 4];
|
||||
objNorm += (objsInv[i] * vec4(normIn, 1.0)) * weightIn[i / 4][i % 4];
|
||||
}
|
||||
objPos[3] = 1.0;
|
||||
objNorm = vec4(normalize(objNorm.xyz), 0.0);
|
||||
vtf.mvPos = mv * objPos;
|
||||
vtf.mvNorm = vec4(normalize((mvInv * objNorm).xyz), 0.0);
|
||||
gl_Position = proj * vtf.mvPos;
|
||||
#else
|
||||
vec4 objPos = vec4(posIn, 1.0);
|
||||
vec4 objNorm = vec4(normIn, 0.0);
|
||||
vtf.mvPos = mv * objPos;
|
||||
vtf.mvNorm = mvInv * objNorm;
|
||||
gl_Position = proj * vtf.mvPos;
|
||||
#endif
|
||||
|
||||
vec4 tmpProj;
|
||||
URDE_TCG_EXPR
|
||||
}
|
||||
59
Shaders/shader_CModelShaders.hpp
Normal file
59
Shaders/shader_CModelShaders.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
#include "hecl/PipelineBase.hpp"
|
||||
#include "hecl/hecl.hpp"
|
||||
#include "DataSpec/DNAMP1/CMDLMaterials.hpp"
|
||||
|
||||
struct SModelShadersInfo {
|
||||
uint64_t m_hash;
|
||||
using Material = DataSpec::DNAMP1::HMDLMaterialSet::Material;
|
||||
const Material& m_material;
|
||||
const hecl::Backend::ShaderTag& m_tag;
|
||||
const hecl::Backend::ExtensionSlot& m_extension;
|
||||
std::vector<boo::VertexElementDescriptor> m_vtxFmtData;
|
||||
boo::VertexFormatInfo m_vtxFmt;
|
||||
boo::AdditionalPipelineInfo m_additionalInfo;
|
||||
|
||||
explicit SModelShadersInfo(const Material& material,
|
||||
const hecl::Backend::ShaderTag& tag,
|
||||
const hecl::Backend::ExtensionSlot& extension)
|
||||
: m_material(material), m_tag(tag), m_extension(extension) {
|
||||
m_hash = m_tag.val64();
|
||||
hecl::hash_combine_impl(m_hash, std::hash<uint64_t>()(m_extension.hash()));
|
||||
|
||||
m_vtxFmtData = tag.vertexFormat();
|
||||
m_vtxFmt = boo::VertexFormatInfo(m_vtxFmtData.size(), m_vtxFmtData.data());
|
||||
|
||||
m_additionalInfo = m_tag.additionalInfo(extension, material.blendFactors());
|
||||
}
|
||||
|
||||
static constexpr bool HasHash = true;
|
||||
uint64_t Hash() const { return m_hash; }
|
||||
};
|
||||
|
||||
class Shader_CModelShaders : public hecl::GeneralShader {
|
||||
const SModelShadersInfo& m_info;
|
||||
public:
|
||||
Shader_CModelShaders(const SModelShadersInfo& in)
|
||||
: m_info(in)
|
||||
, VtxFmt(in.m_vtxFmt)
|
||||
, PipelineInfo(in.m_additionalInfo) {}
|
||||
|
||||
const boo::VertexFormatInfo VtxFmt;
|
||||
const boo::AdditionalPipelineInfo PipelineInfo;
|
||||
static constexpr bool HasHash = true;
|
||||
uint64_t Hash() const { return m_info.m_hash; }
|
||||
const SModelShadersInfo& info() const { return m_info; }
|
||||
};
|
||||
|
||||
template <typename P, typename S>
|
||||
class StageObject_CModelShaders : public hecl::StageBinary<P, S> {
|
||||
static std::string BuildShader(const SModelShadersInfo& in);
|
||||
|
||||
public:
|
||||
StageObject_CModelShaders(hecl::StageConverter<P, S>& conv, hecl::FactoryCtx& ctx,
|
||||
const Shader_CModelShaders& in)
|
||||
: hecl::StageBinary<P, S>(conv, ctx, hecl::StageSourceText<P, S>(BuildShader(in.info()))) {}
|
||||
};
|
||||
|
||||
#define UNIVERSAL_PIPELINES_shader_CModelShaders ::Shader_CModelShaders
|
||||
#define STAGES_shader_CModelShaders(P, S) ::StageObject_CModelShaders<P, S>,
|
||||
217
Shaders/shader_CModelShadersGLSL.cpp
Normal file
217
Shaders/shader_CModelShadersGLSL.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include "shader_CModelShaders.hpp"
|
||||
#include "Runtime/Graphics/Shaders/CModelShaders.hpp"
|
||||
|
||||
extern "C" const uint8_t CMODELSHADERS_COMMON_GLSL[];
|
||||
extern "C" size_t CMODELSHADERS_COMMON_GLSL_SZ;
|
||||
static std::string_view CMODELSHADERS_COMMON_GLSL_SV((char*)CMODELSHADERS_COMMON_GLSL, CMODELSHADERS_COMMON_GLSL_SZ);
|
||||
|
||||
extern "C" const uint8_t CMODELSHADERS_VERT_GLSL[];
|
||||
extern "C" size_t CMODELSHADERS_VERT_GLSL_SZ;
|
||||
static std::string_view CMODELSHADERS_VERT_GLSL_SV((char*)CMODELSHADERS_VERT_GLSL, CMODELSHADERS_VERT_GLSL_SZ);
|
||||
|
||||
extern "C" const uint8_t CMODELSHADERS_FRAG_GLSL[];
|
||||
extern "C" size_t CMODELSHADERS_FRAG_GLSL_SZ;
|
||||
static std::string_view CMODELSHADERS_FRAG_GLSL_SV((char*)CMODELSHADERS_FRAG_GLSL, CMODELSHADERS_FRAG_GLSL_SZ);
|
||||
|
||||
using BlendMaterial = SModelShadersInfo::Material::BlendMaterial;
|
||||
using TexCoordSource = BlendMaterial::TexCoordSource;
|
||||
|
||||
static std::string_view EmitTexGenSource2(TexCoordSource src) {
|
||||
switch (src) {
|
||||
case TexCoordSource::Position:
|
||||
return "objPos.xy"sv;
|
||||
case TexCoordSource::Normal:
|
||||
return "objNorm.xy"sv;
|
||||
case TexCoordSource::Tex0:
|
||||
return "uvIn[0]"sv;
|
||||
case TexCoordSource::Tex1:
|
||||
return "uvIn[1]"sv;
|
||||
case TexCoordSource::Tex2:
|
||||
return "uvIn[2]"sv;
|
||||
case TexCoordSource::Tex3:
|
||||
return "uvIn[3]"sv;
|
||||
case TexCoordSource::Tex4:
|
||||
return "uvIn[4]"sv;
|
||||
case TexCoordSource::Tex5:
|
||||
return "uvIn[5]"sv;
|
||||
case TexCoordSource::Tex6:
|
||||
return "uvIn[6]"sv;
|
||||
case TexCoordSource::Tex7:
|
||||
return "uvIn[7]"sv;
|
||||
default:
|
||||
assert(false && "Unknown source type");
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string_view EmitTexGenSource4(TexCoordSource src) {
|
||||
switch (src) {
|
||||
case TexCoordSource::Position:
|
||||
return "vec4(objPos.xyz, 1.0)"sv;
|
||||
case TexCoordSource::Normal:
|
||||
return "vec4(objNorm.xyz, 1.0)"sv;
|
||||
case TexCoordSource::Tex0:
|
||||
return "vec4(uvIn[0], 0.0, 1.0)"sv;
|
||||
case TexCoordSource::Tex1:
|
||||
return "vec4(uvIn[1], 0.0, 1.0)"sv;
|
||||
case TexCoordSource::Tex2:
|
||||
return "vec4(uvIn[2], 0.0, 1.0)"sv;
|
||||
case TexCoordSource::Tex3:
|
||||
return "vec4(uvIn[3], 0.0, 1.0)"sv;
|
||||
case TexCoordSource::Tex4:
|
||||
return "vec4(uvIn[4], 0.0, 1.0)"sv;
|
||||
case TexCoordSource::Tex5:
|
||||
return "vec4(uvIn[5], 0.0, 1.0)"sv;
|
||||
case TexCoordSource::Tex6:
|
||||
return "vec4(uvIn[6], 0.0, 1.0)"sv;
|
||||
case TexCoordSource::Tex7:
|
||||
return "vec4(uvIn[7], 0.0, 1.0)"sv;
|
||||
default:
|
||||
assert(false && "Unknown source type");
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string _BuildVS(const SModelShadersInfo& info) {
|
||||
std::stringstream vertOut;
|
||||
vertOut << CMODELSHADERS_COMMON_GLSL_SV;
|
||||
vertOut << "#define URDE_COL_SLOTS "sv << unsigned(info.m_tag.getColorCount()) << '\n';
|
||||
vertOut << "#define URDE_UV_SLOTS "sv << unsigned(info.m_tag.getUvCount()) << '\n';
|
||||
vertOut << "#define URDE_SKIN_SLOTS "sv << unsigned(info.m_tag.getSkinSlotCount()) << '\n';
|
||||
vertOut << "#define URDE_WEIGHT_SLOTS "sv << unsigned(info.m_tag.getWeightCount()) << '\n';
|
||||
vertOut << "#define URDE_TCG_EXPR "sv;
|
||||
|
||||
using UVAnimType = BlendMaterial::UVAnimType;
|
||||
using PassType = BlendMaterial::PassType;
|
||||
int mtxIdx = 0;
|
||||
for (const auto& chunk : info.m_material.chunks) {
|
||||
if (auto passChunk = chunk.get_if<SModelShadersInfo::Material::PASS>()) {
|
||||
if (passChunk->type != PassType::IndirectTex) {
|
||||
std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type);
|
||||
if (passChunk->uvAnimType == UVAnimType::Invalid) {
|
||||
vertOut << "vtf."sv << tpStr << "Uv = "sv << EmitTexGenSource2(passChunk->source) << ";"sv;
|
||||
} else {
|
||||
vertOut << "tmpProj = texMtxs["sv << mtxIdx << "].postMtx * vec4("sv <<
|
||||
(passChunk->shouldNormalizeUv() ? "normalize"sv : ""sv) << "((texMtxs["sv << mtxIdx << "].mtx * "sv <<
|
||||
EmitTexGenSource4(passChunk->source) << ").xyz), 1.0);"sv <<
|
||||
"vtf."sv << tpStr << "Uv = (tmpProj / tmpProj.w).xy;"sv;
|
||||
}
|
||||
}
|
||||
} else if (auto clrChunk = chunk.get_if<SModelShadersInfo::Material::CLR>()) {
|
||||
std::string_view tpStr = BlendMaterial::PassTypeToString(clrChunk->type);
|
||||
vertOut << "vtf."sv << tpStr << "Uv = vec2(0.0,0.0);"sv;
|
||||
}
|
||||
}
|
||||
if (!info.m_extension.noReflection && info.m_tag.getReflectionType() != hecl::Backend::ReflectionType::None)
|
||||
vertOut << "vtf.dynReflectionUvs[0] = normalize((indMtx * vec4(objPos.xyz, 1.0)).xz) * vec2(0.5, 0.5) + vec2(0.5, 0.5);"
|
||||
"vtf.dynReflectionUvs[1] = (reflectMtx * vec4(objPos.xyz, 1.0)).xy;"
|
||||
"vtf.dynReflectionAlpha = reflectAlpha;";
|
||||
|
||||
for (int i = 0; i < info.m_extension.texCount; ++i) {
|
||||
const auto& extTex = info.m_extension.texs[i];
|
||||
if (extTex.mtxIdx < 0)
|
||||
vertOut << "vtf.extUvs["sv << i << "] = "sv << EmitTexGenSource2(extTex.src) << ";"sv;
|
||||
else
|
||||
vertOut << "tmpProj = texMtxs["sv << unsigned(extTex.mtxIdx) << "].postMtx * vec4("sv <<
|
||||
(extTex.normalize ? "normalize"sv : ""sv) << "((texMtxs["sv << unsigned(extTex.mtxIdx) << "].mtx * "sv <<
|
||||
EmitTexGenSource4(extTex.src) << ").xyz), 1.0);"sv <<
|
||||
"vtf.extUvs["sv << i << "] = (tmpProj / tmpProj.w).xy;"sv;
|
||||
}
|
||||
vertOut << '\n';
|
||||
|
||||
vertOut << CMODELSHADERS_VERT_GLSL_SV;
|
||||
return vertOut.str();
|
||||
}
|
||||
|
||||
static std::string _BuildFS(const SModelShadersInfo& info) {
|
||||
std::stringstream fragOut;
|
||||
fragOut << CMODELSHADERS_COMMON_GLSL_SV;
|
||||
fragOut << "#define URDE_MAX_LIGHTS " _XSTR(URDE_MAX_LIGHTS) "\n";
|
||||
fragOut << "#define " << info.m_extension.shaderMacro << "\n";
|
||||
|
||||
using ShaderType = BlendMaterial::ShaderType;
|
||||
switch (info.m_material.shaderType) {
|
||||
case ShaderType::RetroShader:
|
||||
fragOut << "#define RETRO_SHADER\n"; break;
|
||||
case ShaderType::RetroDynamicShader:
|
||||
fragOut << "#define RETRO_DYNAMIC_SHADER\n"; break;
|
||||
case ShaderType::RetroDynamicAlphaShader:
|
||||
fragOut << "#define RETRO_DYNAMIC_ALPHA_SHADER\n"; break;
|
||||
case ShaderType::RetroDynamicCharacterShader:
|
||||
fragOut << "#define RETRO_DYNAMIC_CHARACTER_SHADER\n"; break;
|
||||
default:
|
||||
assert(false && "Unknown shader type");
|
||||
break;
|
||||
}
|
||||
|
||||
fragOut << "#define BLEND_SRC_"sv << hecl::Backend::BlendFactorToDefine(
|
||||
hecl::Backend::BlendFactor(info.m_additionalInfo.srcFac), hecl::Backend::BlendFactor::One) << '\n';
|
||||
fragOut << "#define BLEND_DST_"sv << hecl::Backend::BlendFactorToDefine(
|
||||
hecl::Backend::BlendFactor(info.m_additionalInfo.dstFac), hecl::Backend::BlendFactor::Zero) << '\n';
|
||||
|
||||
using PassType = BlendMaterial::PassType;
|
||||
for (const auto& chunk : info.m_material.chunks) {
|
||||
if (auto passChunk = chunk.get_if<SModelShadersInfo::Material::PASS>()) {
|
||||
if (passChunk->alpha) {
|
||||
std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type);
|
||||
fragOut << "#define ALPHA_" << tpStr << '\n';
|
||||
}
|
||||
} else if (auto clrChunk = chunk.get_if<SModelShadersInfo::Material::CLR>()) {
|
||||
if (clrChunk->type == PassType::Alpha)
|
||||
fragOut << "#define ALPHA_alpha\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (info.m_tag.getAlphaTest() || info.m_extension.forceAlphaTest)
|
||||
fragOut << "#define URDE_ALPHA_TEST\n";
|
||||
|
||||
if (info.m_extension.diffuseOnly)
|
||||
fragOut << "#define URDE_DIFFUSE_ONLY\n";
|
||||
|
||||
if (!info.m_extension.noReflection) {
|
||||
if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Indirect)
|
||||
fragOut << "#define URDE_REFLECTION_INDIRECT\n"sv;
|
||||
else if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Simple)
|
||||
fragOut << "#define URDE_REFLECTION_SIMPLE\n"sv;
|
||||
}
|
||||
|
||||
fragOut << CMODELSHADERS_FRAG_GLSL_SV;
|
||||
return fragOut.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string StageObject_CModelShaders<hecl::PlatformType::OpenGL, hecl::PipelineStage::Vertex>::BuildShader(
|
||||
const SModelShadersInfo& in) {
|
||||
return _BuildVS(in);
|
||||
}
|
||||
template <>
|
||||
std::string StageObject_CModelShaders<hecl::PlatformType::Vulkan, hecl::PipelineStage::Vertex>::BuildShader(
|
||||
const SModelShadersInfo& in) {
|
||||
return _BuildVS(in);
|
||||
}
|
||||
template <>
|
||||
std::string StageObject_CModelShaders<hecl::PlatformType::NX, hecl::PipelineStage::Vertex>::BuildShader(
|
||||
const SModelShadersInfo& in) {
|
||||
return _BuildVS(in);
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string StageObject_CModelShaders<hecl::PlatformType::OpenGL, hecl::PipelineStage::Fragment>::BuildShader(
|
||||
const SModelShadersInfo& in) {
|
||||
return _BuildFS(in);
|
||||
}
|
||||
template <>
|
||||
std::string StageObject_CModelShaders<hecl::PlatformType::Vulkan, hecl::PipelineStage::Fragment>::BuildShader(
|
||||
const SModelShadersInfo& in) {
|
||||
return _BuildFS(in);
|
||||
}
|
||||
template <>
|
||||
std::string StageObject_CModelShaders<hecl::PlatformType::NX, hecl::PipelineStage::Fragment>::BuildShader(
|
||||
const SModelShadersInfo& in) {
|
||||
return _BuildFS(in);
|
||||
}
|
||||
0
Shaders/shader_CModelShadersHLSL.cpp
Normal file
0
Shaders/shader_CModelShadersHLSL.cpp
Normal file
0
Shaders/shader_CModelShadersMetal.cpp
Normal file
0
Shaders/shader_CModelShadersMetal.cpp
Normal file
Reference in New Issue
Block a user