Windows fixes

This commit is contained in:
Jack Andersen 2019-05-09 18:09:01 -10:00
parent 80d334ec69
commit 5f4ebcb2f5
13 changed files with 698 additions and 49 deletions

View File

@ -248,7 +248,12 @@ endif()
bintoc(CModelShaders.common.glsl.cpp Shaders/CModelShaders.common.glsl CMODELSHADERS_COMMON_GLSL) bintoc(CModelShaders.common.glsl.cpp Shaders/CModelShaders.common.glsl CMODELSHADERS_COMMON_GLSL)
bintoc(CModelShaders.vert.glsl.cpp Shaders/CModelShaders.vert.glsl CMODELSHADERS_VERT_GLSL) bintoc(CModelShaders.vert.glsl.cpp Shaders/CModelShaders.vert.glsl CMODELSHADERS_VERT_GLSL)
bintoc(CModelShaders.frag.glsl.cpp Shaders/CModelShaders.frag.glsl CMODELSHADERS_FRAG_GLSL) bintoc(CModelShaders.frag.glsl.cpp Shaders/CModelShaders.frag.glsl CMODELSHADERS_FRAG_GLSL)
add_library(CModelShaders CModelShaders.common.glsl.cpp CModelShaders.vert.glsl.cpp CModelShaders.frag.glsl.cpp) bintoc(CModelShaders.common.hlsl.cpp Shaders/CModelShaders.common.hlsl CMODELSHADERS_COMMON_HLSL)
bintoc(CModelShaders.vert.hlsl.cpp Shaders/CModelShaders.vert.hlsl CMODELSHADERS_VERT_HLSL)
bintoc(CModelShaders.frag.hlsl.cpp Shaders/CModelShaders.frag.hlsl CMODELSHADERS_FRAG_HLSL)
add_library(CModelShaders
CModelShaders.common.glsl.cpp CModelShaders.vert.glsl.cpp CModelShaders.frag.glsl.cpp
CModelShaders.common.hlsl.cpp CModelShaders.vert.hlsl.cpp CModelShaders.frag.hlsl.cpp)
if(NOT TARGET atdna) if(NOT TARGET atdna)
# Import native atdna if cross-compiling # Import native atdna if cross-compiling
@ -264,8 +269,9 @@ add_subdirectory(amuse)
add_subdirectory(specter) add_subdirectory(specter)
add_subdirectory(assetnameparser) add_subdirectory(assetnameparser)
include_directories(${ATHENA_INCLUDE_DIR} ${LOGVISOR_INCLUDE_DIR} ${HECL_INCLUDE_DIR} include_directories(${ATHENA_INCLUDE_DIR} ${LOGVISOR_INCLUDE_DIR} ${HECL_INCLUDE_DIR}
${BOO_INCLUDE_DIR} ${AMUSE_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${BOO_INCLUDE_DIR} ${AMUSE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/NESEmulator
${CMAKE_CURRENT_SOURCE_DIR}/NESEmulator) ${ZLIB_INCLUDE_DIR})
add_definitions(-DURDE_ZIP_INPUT_STREAM=1) # Enable CZipInputStream now that zlib header is known
add_subdirectory(NESEmulator) add_subdirectory(NESEmulator)
add_subdirectory(DataSpec) add_subdirectory(DataSpec)
add_subdirectory(kabufuda) add_subdirectory(kabufuda)

View File

@ -107,9 +107,8 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = {
{0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One,
hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::Backface, true, true, false}, hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::Backface, true, true, false},
/* MorphBall shadow shading */ /* MorphBall shadow shading */
{3, BallFadeTextures, hecl::Backend::BlendFactor::SrcAlpha, {3, BallFadeTextures, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Equal, hecl::Backend::CullMode::Backface, false, hecl::Backend::ZTest::Equal, hecl::Backend::CullMode::Backface, false, false, true, false, true},
false, true, false, true},
/* World shadow shading (modified lighting) */ /* World shadow shading (modified lighting) */
{1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, {1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true},
@ -135,9 +134,8 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = {
{0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
hecl::Backend::ZTest::GEqual, hecl::Backend::CullMode::Backface, true, false, true}, hecl::Backend::ZTest::GEqual, hecl::Backend::CullMode::Backface, true, false, true},
/* Disintegration */ /* Disintegration */
{2, DisintegrateTextures, hecl::Backend::BlendFactor::SrcAlpha, {2, DisintegrateTextures, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false, hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false, false, true, false, false, true},
false, true, false, false, true},
/* Forced additive shading without culling or Z-write and greater depth test */ /* Forced additive shading without culling or Z-write and greater depth test */
{0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One,
hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true}, hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true},
@ -149,7 +147,7 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = {
{0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface}}; hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface}};
const char* ShaderMacros[] = { static const char* ShaderMacros[] = {
"URDE_LIGHTING", "URDE_LIGHTING",
"URDE_LIGHTING", "URDE_LIGHTING",
"URDE_THERMAL_HOT", "URDE_THERMAL_HOT",

View File

@ -1,11 +1,13 @@
#pragma once #pragma once
#include "GCNTypes.hpp" #include "GCNTypes.hpp"
#include <athena/IStreamReader.hpp> #include "athena/IStreamReader.hpp"
#include <athena/IStreamWriter.hpp> #include "athena/IStreamWriter.hpp"
#include <athena/MemoryReader.hpp> #include "athena/MemoryReader.hpp"
#include <athena/MemoryWriter.hpp> #include "athena/MemoryWriter.hpp"
#ifdef URDE_ZIP_INPUT_STREAM
#include <zlib.h> #include <zlib.h>
#endif
namespace urde { namespace urde {
using CInputStream = athena::io::IStreamReader; using CInputStream = athena::io::IStreamReader;
@ -50,6 +52,7 @@ public:
using CMemoryInStream = athena::io::MemoryReader; using CMemoryInStream = athena::io::MemoryReader;
using CMemoryOutStream = athena::io::MemoryWriter; using CMemoryOutStream = athena::io::MemoryWriter;
#ifdef URDE_ZIP_INPUT_STREAM
class CZipInputStream : public CInputStream { class CZipInputStream : public CInputStream {
std::unique_ptr<u8[]> x24_compBuf; std::unique_ptr<u8[]> x24_compBuf;
std::unique_ptr<CInputStream> x28_strm; std::unique_ptr<CInputStream> x28_strm;
@ -63,5 +66,6 @@ public:
atUint64 position() const { return 0; } atUint64 position() const { return 0; }
atUint64 length() const { return 0; } atUint64 length() const { return 0; }
}; };
#endif
} // namespace urde } // namespace urde

View File

@ -4,7 +4,6 @@
struct VertToFrag { struct VertToFrag {
vec4 mvPos; vec4 mvPos;
vec4 mvNorm; vec4 mvNorm;
vec4 color;
vec2 lightmapUv; vec2 lightmapUv;
vec2 diffuseUv; vec2 diffuseUv;
vec2 emissiveUv; vec2 emissiveUv;

View File

@ -0,0 +1,15 @@
struct VertToFrag {
float4 mvpPos : SV_Position;
float4 mvPos : POSITION;
float4 mvNorm : NORMAL;
float2 lightmapUv : UV0;
float2 diffuseUv : UV1;
float2 emissiveUv : UV2;
float2 specularUv : UV3;
float2 extendedSpecularUv : UV4;
float2 reflectionUv : UV5;
float2 alphaUv : UV6;
float2 extUvs[3] : EXTUV;
float2 dynReflectionUvs[2] : REFLECTUV;
float dynReflectionAlpha : REFLECTALPHA;
};

View File

@ -114,17 +114,17 @@ UBINDING2 uniform LightingUniform {
Fog fog; Fog fog;
}; };
#else #else
const vec4 colorReg0 = vec4(1.0, 1.0, 1.0, 1.0); const vec4 colorReg0 = vec4(1.0);
const vec4 colorReg1 = vec4(1.0, 1.0, 1.0, 1.0); const vec4 colorReg1 = vec4(1.0);
const vec4 colorReg2 = vec4(1.0, 1.0, 1.0, 1.0); const vec4 colorReg2 = vec4(1.0);
#endif #endif
#if defined(URDE_LIGHTING) #if defined(URDE_LIGHTING)
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) { vec3 LightingFunc() {
vec4 ret = ambient; vec4 ret = ambient;
for (int i = 0; i < URDE_MAX_LIGHTS; ++i) { for (int i = 0; i < URDE_MAX_LIGHTS; ++i) {
vec3 delta = mvPosIn - lights[i].pos.xyz; vec3 delta = vtf.mvPos.xyz - lights[i].pos.xyz;
float dist = length(delta); float dist = length(delta);
vec3 deltaNorm = delta / dist; vec3 deltaNorm = delta / dist;
float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0); float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0);
@ -134,7 +134,7 @@ vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
float angAtt = lights[i].angAtt[2] * angDot * angDot + float angAtt = lights[i].angAtt[2] * angDot * angDot +
lights[i].angAtt[1] * angDot + lights[i].angAtt[1] * angDot +
lights[i].angAtt[0]; lights[i].angAtt[0];
ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0); ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0);
} }
return clamp(ret.rgb, vec3(0.0), vec3(1.0)); return clamp(ret.rgb, vec3(0.0), vec3(1.0));
@ -142,8 +142,8 @@ vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
#endif #endif
#if defined(URDE_THERMAL_HOT) #if defined(URDE_THERMAL_HOT)
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) { vec3 LightingFunc() {
return vec3(1.0,1.0,1.0); return vec3(1.0);
} }
UBINDING2 uniform ThermalUniform { UBINDING2 uniform ThermalUniform {
vec4 tmulColor; vec4 tmulColor;
@ -152,14 +152,14 @@ UBINDING2 uniform ThermalUniform {
#endif #endif
#if defined(URDE_THERMAL_COLD) #if defined(URDE_THERMAL_COLD)
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) { vec3 LightingFunc() {
return vec3(1.0,1.0,1.0); return vec3(1.0);
} }
#endif #endif
#if defined(URDE_SOLID) #if defined(URDE_SOLID)
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) { vec3 LightingFunc() {
return vec3(1.0,1.0,1.0); return vec3(1.0);
} }
UBINDING2 uniform SolidUniform { UBINDING2 uniform SolidUniform {
vec4 solidColor; vec4 solidColor;
@ -167,8 +167,8 @@ UBINDING2 uniform SolidUniform {
#endif #endif
#if defined(URDE_MB_SHADOW) #if defined(URDE_MB_SHADOW)
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) { vec3 LightingFunc() {
return vec3(1.0,1.0,1.0); return vec3(1.0);
} }
UBINDING2 uniform MBShadowUniform { UBINDING2 uniform MBShadowUniform {
vec4 shadowUp; vec4 shadowUp;
@ -177,13 +177,13 @@ UBINDING2 uniform MBShadowUniform {
#endif #endif
#if defined(URDE_LIGHTING_SHADOW) #if defined(URDE_LIGHTING_SHADOW)
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) { vec3 LightingFunc() {
vec2 shadowUV = vtf.extUvs[0]; vec2 shadowUV = vtf.extUvs[0];
shadowUV.y = 1.0 - shadowUV.y; shadowUV.y = 1.0 - shadowUV.y;
vec4 ret = ambient; vec4 ret = ambient;
vec3 delta = mvPosIn - lights[0].pos.xyz; vec3 delta = vtf.mvPos.xyz - lights[0].pos.xyz;
float dist = length(delta); float dist = length(delta);
vec3 deltaNorm = delta / dist; vec3 deltaNorm = delta / dist;
float angDot = max(dot(deltaNorm, lights[0].dir.xyz), 0.0); float angDot = max(dot(deltaNorm, lights[0].dir.xyz), 0.0);
@ -193,11 +193,11 @@ vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
float angAtt = lights[0].angAtt[2] * angDot * angDot + float angAtt = lights[0].angAtt[2] * angDot * angDot +
lights[0].angAtt[1] * angDot + lights[0].angAtt[1] * angDot +
lights[0].angAtt[0]; lights[0].angAtt[0];
ret += lights[0].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0) * ret += lights[0].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0) *
texture(extTex0, shadowUV).r; texture(extTex0, shadowUV).r;
for (int i = 1; i < URDE_MAX_LIGHTS; ++i) { for (int i = 1; i < URDE_MAX_LIGHTS; ++i) {
vec3 delta = mvPosIn - lights[i].pos.xyz; vec3 delta = vtf.mvPos.xyz - lights[i].pos.xyz;
float dist = length(delta); float dist = length(delta);
vec3 deltaNorm = delta / dist; vec3 deltaNorm = delta / dist;
float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0); float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0);
@ -207,7 +207,7 @@ vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) {
float angAtt = lights[i].angAtt[2] * angDot * angDot + float angAtt = lights[i].angAtt[2] * angDot * angDot +
lights[i].angAtt[1] * angDot + lights[i].angAtt[1] * angDot +
lights[i].angAtt[0]; lights[i].angAtt[0];
ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0); ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0);
} }
return clamp(ret.rgb, vec3(0.0), vec3(1.0)); return clamp(ret.rgb, vec3(0.0), vec3(1.0));
@ -219,8 +219,8 @@ UBINDING2 uniform DisintegrateUniform {
vec4 daddColor; vec4 daddColor;
Fog fog; Fog fog;
}; };
vec3 LightingFunc(vec3 mvPosIn, vec3 mvNormIn) { vec3 LightingFunc() {
return vec3(1.0,1.0,1.0); return vec3(1.0);
} }
#endif #endif
@ -309,12 +309,12 @@ vec3 ReflectionFunc() { return texture(reflectionTex, vtf.dynReflectionUvs[1]).r
vec3 ReflectionFunc() { return texture(reflectionTex, (texture(reflectionIndTex, vtf.dynReflectionUvs[0]).ab - 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; } vec2(0.5, 0.5)) * vec2(0.5, 0.5) + vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; }
#else #else
vec3 ReflectionFunc() { return vec3(0.0, 0.0, 0.0); } vec3 ReflectionFunc() { return vec3(0.0); }
#endif #endif
layout(location=0) out vec4 colorOut; layout(location=0) out vec4 colorOut;
void main() { void main() {
vec3 lighting = LightingFunc(vtf.mvPos.xyz, vtf.mvNorm.xyz); vec3 lighting = LightingFunc();
vec4 tmp; vec4 tmp;
#if defined(URDE_DIFFUSE_ONLY) #if defined(URDE_DIFFUSE_ONLY)
tmp.rgb = SampleTexture_diffuse(); tmp.rgb = SampleTexture_diffuse();

View File

@ -0,0 +1,351 @@
SamplerState samp : register(s0);
SamplerState clampSamp : register(s1);
SamplerState reflectSamp : register(s2);
Texture2D lightmap : register(t0);
Texture2D diffuse : register(t1);
Texture2D emissive : register(t2);
Texture2D specular : register(t3);
Texture2D extendedSpecular : register(t4);
Texture2D reflection : register(t5);
Texture2D alpha : register(t6);
Texture2D reflectionIndTex : register(t7);
Texture2D extTex0 : register(t8);
Texture2D extTex1 : register(t9);
Texture2D extTex2 : register(t10);
Texture2D reflectionTex : register(t11);
static const float3 kRGBToYPrime = float3(0.257, 0.504, 0.098);
/*
#if defined(ALPHA_%s)
float3 SampleTexture_%s(in VertToFrag vtf) { return %s.Sample(samp, vtf.%sUv).aaa; }
float SampleTextureAlpha_%s(in VertToFrag vtf) { return %s.Sample(samp, vtf.%sUv).a; }
#else
float3 SampleTexture_%s(in VertToFrag vtf) { return %s.Sample(samp, vtf.%sUv).rgb; }
float SampleTextureAlpha_%s(in VertToFrag vtf) { return dot(%s.Sample(samp, vtf.%sUv).rgb, kRGBToYPrime); }
#endif
*/
#if defined(ALPHA_lightmap)
float3 SampleTexture_lightmap(in VertToFrag vtf) { return lightmap.Sample(samp, vtf.lightmapUv).aaa; }
float SampleTextureAlpha_lightmap(in VertToFrag vtf) { return lightmap.Sample(samp, vtf.lightmapUv).a; }
#else
float3 SampleTexture_lightmap(in VertToFrag vtf) { return lightmap.Sample(samp, vtf.lightmapUv).rgb; }
float SampleTextureAlpha_lightmap(in VertToFrag vtf) { return dot(lightmap.Sample(samp, vtf.lightmapUv).rgb, kRGBToYPrime); }
#endif
#if defined(ALPHA_diffuse)
float3 SampleTexture_diffuse(in VertToFrag vtf) { return diffuse.Sample(samp, vtf.diffuseUv).aaa; }
float SampleTextureAlpha_diffuse(in VertToFrag vtf) { return diffuse.Sample(samp, vtf.diffuseUv).a; }
#else
float3 SampleTexture_diffuse(in VertToFrag vtf) { return diffuse.Sample(samp, vtf.diffuseUv).rgb; }
float SampleTextureAlpha_diffuse(in VertToFrag vtf) { return dot(diffuse.Sample(samp, vtf.diffuseUv).rgb, kRGBToYPrime); }
#endif
#if defined(ALPHA_emissive)
float3 SampleTexture_emissive(in VertToFrag vtf) { return emissive.Sample(samp, vtf.emissiveUv).aaa; }
float SampleTextureAlpha_emissive(in VertToFrag vtf) { return emissive.Sample(samp, vtf.emissiveUv).a; }
#else
float3 SampleTexture_emissive(in VertToFrag vtf) { return emissive.Sample(samp, vtf.emissiveUv).rgb; }
float SampleTextureAlpha_emissive(in VertToFrag vtf) { return dot(emissive.Sample(samp, vtf.emissiveUv).rgb, kRGBToYPrime); }
#endif
#if defined(ALPHA_specular)
float3 SampleTexture_specular(in VertToFrag vtf) { return specular.Sample(samp, vtf.specularUv).aaa; }
float SampleTextureAlpha_specular(in VertToFrag vtf) { return specular.Sample(samp, vtf.specularUv).a; }
#else
float3 SampleTexture_specular(in VertToFrag vtf) { return specular.Sample(samp, vtf.specularUv).rgb; }
float SampleTextureAlpha_specular(in VertToFrag vtf) { return dot(specular.Sample(samp, vtf.specularUv).rgb, kRGBToYPrime); }
#endif
#if defined(ALPHA_extendedSpecular)
float3 SampleTexture_extendedSpecular(in VertToFrag vtf) { return extendedSpecular.Sample(samp, vtf.extendedSpecularUv).aaa; }
float SampleTextureAlpha_extendedSpecular(in VertToFrag vtf) { return extendedSpecular.Sample(samp, vtf.extendedSpecularUv).a; }
#else
float3 SampleTexture_extendedSpecular(in VertToFrag vtf) { return extendedSpecular.Sample(samp, vtf.extendedSpecularUv).rgb; }
float SampleTextureAlpha_extendedSpecular(in VertToFrag vtf) { return dot(extendedSpecular.Sample(samp, vtf.extendedSpecularUv).rgb, kRGBToYPrime); }
#endif
#if defined(ALPHA_reflection)
float3 SampleTexture_reflection(in VertToFrag vtf) { return reflection.Sample(samp, vtf.reflectionUv).aaa; }
float SampleTextureAlpha_reflection(in VertToFrag vtf) { return reflection.Sample(samp, vtf.reflectionUv).a; }
#else
float3 SampleTexture_reflection(in VertToFrag vtf) { return reflection.Sample(samp, vtf.reflectionUv).rgb; }
float SampleTextureAlpha_reflection(in VertToFrag vtf) { return dot(reflection.Sample(samp, vtf.reflectionUv).rgb, kRGBToYPrime); }
#endif
#if defined(ALPHA_alpha)
float3 SampleTexture_alpha(in VertToFrag vtf) { return alpha.Sample(samp, vtf.alphaUv).aaa; }
float SampleTextureAlpha_alpha(in VertToFrag vtf) { return alpha.Sample(samp, vtf.alphaUv).a; }
#else
float3 SampleTexture_alpha(in VertToFrag vtf) { return alpha.Sample(samp, vtf.alphaUv).rgb; }
float SampleTextureAlpha_alpha(in VertToFrag vtf) { return dot(alpha.Sample(samp, vtf.alphaUv).rgb, kRGBToYPrime); }
#endif
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_DISINTEGRATE)
struct Fog {
float4 color;
float A;
float B;
float C;
int mode;
};
#endif
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW)
struct Light {
float4 pos;
float4 dir;
float4 color;
float4 linAtt;
float4 angAtt;
};
cbuffer LightingUniform : register(b2) {
Light lights[URDE_MAX_LIGHTS];
float4 ambient;
float4 colorReg0;
float4 colorReg1;
float4 colorReg2;
float4 mulColor;
float4 addColor;
Fog fog;
};
#else
static const float4 colorReg0 = float4(1.0, 1.0, 1.0, 1.0);
static const float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0);
static const float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0);
#endif
#if defined(URDE_LIGHTING)
float3 LightingFunc(in VertToFrag vtf) {
float4 ret = ambient;
for (int i = 0; i < URDE_MAX_LIGHTS; ++i) {
float3 delta = vtf.mvPos.xyz - lights[i].pos.xyz;
float dist = length(delta);
float3 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, vtf.mvNorm.xyz), 0.0);
}
return saturate(ret.rgb);
}
#endif
#if defined(URDE_THERMAL_HOT)
float3 LightingFunc(in VertToFrag vtf) {
return float3(1.0, 1.0, 1.0);
}
cbuffer ThermalUniform : register(b2) {
float4 tmulColor;
float4 taddColor;
};
#endif
#if defined(URDE_THERMAL_COLD)
float3 LightingFunc(in VertToFrag vtf) {
return float3(1.0, 1.0, 1.0);
}
#endif
#if defined(URDE_SOLID)
float3 LightingFunc(in VertToFrag vtf) {
return float3(1.0, 1.0, 1.0);
}
cbuffer SolidUniform : register(b2) {
float4 solidColor;
};
#endif
#if defined(URDE_MB_SHADOW)
float3 LightingFunc(in VertToFrag vtf) {
return float3(1.0, 1.0, 1.0);
}
cbuffer MBShadowUniform : register(b2) {
float4 shadowUp;
float shadowId;
};
#endif
#if defined(URDE_LIGHTING_SHADOW)
float3 LightingFunc(in VertToFrag vtf) {
float2 shadowUV = vtf.extUvs[0];
shadowUV.y = 1.0 - shadowUV.y;
float4 ret = ambient;
float3 delta = vtf.mvPos.xyz - lights[0].pos.xyz;
float dist = length(delta);
float3 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, vtf.mvNorm.xyz), 0.0) *
extTex0.Sample(clampSamp, shadowUV).r;
for (int i = 1; i < URDE_MAX_LIGHTS; ++i) {
float3 delta = vtf.mvPos.xyz - lights[i].pos.xyz;
float dist = length(delta);
float3 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, vtf.mvNorm.xyz), 0.0);
}
return saturate(ret.rgb);
}
#endif
#if defined(URDE_DISINTEGRATE)
cbuffer DisintegrateUniform : register(b2) {
float4 daddColor;
Fog fog;
};
float3 LightingFunc(in VertToFrag vtf) {
return float3(1.0, 1.0, 1.0);
}
#endif
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_DISINTEGRATE)
float4 FogFunc(in VertToFrag vtf, float4 colorIn) {
float fogZ;
float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.mvpPos.z))) - fog.C);
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 float4(lerp(colorIn, float4(0.0, 0.0, 0.0, 0.0), saturate(fogZ)).rgb, colorIn.a);
#else
return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);
#endif
}
#endif
#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW)
float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
return FogFunc(vtf, colorIn) * mulColor + addColor;
}
#endif
#if defined(URDE_THERMAL_HOT)
float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
return extTex0.Sample(samp, vtf.extUvs[0]).rrrr * tmulColor + taddColor;
}
#endif
#if defined(URDE_THERMAL_COLD)
float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
return colorIn * float4(0.75, 0.75, 0.75, 0.75);
}
#endif
#if defined(URDE_SOLID)
float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
return solidColor;
}
#endif
#if defined(URDE_MB_SHADOW)
float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
float idTexel = extTex0.Sample(samp, vtf.extUvs[0]).a;
float sphereTexel = extTex1.Sample(samp, vtf.extUvs[1]).a;
float fadeTexel = extTex2.Sample(samp, vtf.extUvs[2]).a;
float val = ((abs(idTexel - shadowId) < 0.001) ?
(dot(vtf.mvNorm.xyz, shadowUp.xyz) * shadowUp.w) : 0.0) *
sphereTexel * fadeTexel;
return float4(0.0, 0.0, 0.0, val);
}
#endif
#if defined(URDE_DISINTEGRATE)
float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
float4 texel0 = extTex0.Sample(samp, vtf.extUvs[0]);
float4 texel1 = extTex0.Sample(samp, vtf.extUvs[1]);
colorIn = lerp(float4(0.0, 0.0, 0.0, 0.0), texel1, texel0);
colorIn.rgb += daddColor.rgb;
return FogFunc(vtf, colorIn);
}
#endif
#if defined(URDE_REFLECTION_SIMPLE)
float3 ReflectionFunc(in VertToFrag vtf)
{ return reflectionTex.Sample(reflectSamp, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; }
#elif defined(URDE_REFLECTION_INDIRECT)
float3 ReflectionFunc(in VertToFrag vtf)
{ return reflectionTex.Sample(reflectSamp, (reflectionIndTex.Sample(samp, vtf.dynReflectionUvs[0]).ab -
float2(0.5, 0.5)) * float2(0.5, 0.5) + vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; }
#else
float3 ReflectionFunc(in VertToFrag vtf) { return float3(0.0, 0.0, 0.0); }
#endif
#if !defined(URDE_ALPHA_TEST)
[earlydepthstencil]
#endif
float4 main(in VertToFrag vtf) : SV_Target0 {
float3 lighting = LightingFunc(vtf);
float4 tmp;
#if defined(URDE_DIFFUSE_ONLY)
tmp.rgb = SampleTexture_diffuse(vtf);
tmp.a = SampleTextureAlpha_alpha(vtf);
#elif defined(RETRO_SHADER)
tmp.rgb = (SampleTexture_lightmap(vtf) * colorReg1.rgb + lighting) * SampleTexture_diffuse(vtf) +
SampleTexture_emissive(vtf) + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) *
SampleTexture_reflection(vtf) + ReflectionFunc(vtf);
tmp.a = SampleTextureAlpha_alpha(vtf);
#elif defined(RETRO_DYNAMIC_SHADER)
tmp.rgb = (SampleTexture_lightmap(vtf) * colorReg1.rgb + lighting) * SampleTexture_diffuse(vtf) * colorReg1.rgb +
SampleTexture_emissive(vtf) * colorReg1.rgb + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) *
SampleTexture_reflection(vtf) + ReflectionFunc(vtf);
tmp.a = SampleTextureAlpha_alpha(vtf);
#elif defined(RETRO_DYNAMIC_ALPHA_SHADER)
tmp.rgb = (SampleTexture_lightmap(vtf) * colorReg1.rgb + lighting) * SampleTexture_diffuse(vtf) * colorReg1.rgb +
SampleTexture_emissive(vtf) * colorReg1.rgb + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) *
SampleTexture_reflection(vtf) + ReflectionFunc(vtf);
tmp.a = SampleTextureAlpha_alpha(vtf) * colorReg1.a;
#elif defined(RETRO_DYNAMIC_CHARACTER_SHADER)
tmp.rgb = (SampleTexture_lightmap(vtf) + lighting) * SampleTexture_diffuse(vtf) +
SampleTexture_emissive(vtf) * colorReg1.rgb + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) *
SampleTexture_reflection(vtf) + ReflectionFunc(vtf);
tmp.a = SampleTextureAlpha_alpha(vtf);
#endif
float4 colorOut = PostFunc(vtf, tmp);
#if defined(URDE_ALPHA_TEST)
if (colorOut.a < 0.25)
discard;
#endif
return colorOut;
}

View File

@ -1,4 +1,4 @@
UBINDING0 uniform HECLVertUniform { UBINDING0 uniform URDEVertUniform {
#if URDE_SKIN_SLOTS #if URDE_SKIN_SLOTS
mat4 objs[URDE_SKIN_SLOTS]; mat4 objs[URDE_SKIN_SLOTS];
mat4 objsInv[URDE_SKIN_SLOTS]; mat4 objsInv[URDE_SKIN_SLOTS];
@ -8,15 +8,15 @@ UBINDING0 uniform HECLVertUniform {
mat4 proj; mat4 proj;
}; };
struct HECLTCGMatrix { struct URDETCGMatrix {
mat4 mtx; mat4 mtx;
mat4 postMtx; mat4 postMtx;
}; };
UBINDING1 uniform HECLTexMtxUniform { UBINDING1 uniform URDETexMtxUniform {
HECLTCGMatrix texMtxs[8]; URDETCGMatrix texMtxs[8];
}; };
UBINDING3 uniform HECLReflectMtx { UBINDING3 uniform URDEReflectMtx {
mat4 indMtx; mat4 indMtx;
mat4 reflectMtx; mat4 reflectMtx;
float reflectAlpha; float reflectAlpha;
@ -37,8 +37,8 @@ layout(location=2 + URDE_COL_SLOTS + URDE_UV_SLOTS) in vec4 weightIn[URDE_WEIGHT
SBINDING(0) out VertToFrag vtf; SBINDING(0) out VertToFrag vtf;
void main() { void main() {
#if URDE_SKIN_SLOTS #if URDE_SKIN_SLOTS
vec4 objPos = vec4(0.0,0.0,0.0,0.0); vec4 objPos = vec4(0.0);
vec4 objNorm = vec4(0.0,0.0,0.0,0.0); vec4 objNorm = vec4(0.0);
for (int i = 0; i < URDE_SKIN_SLOTS; ++i) { for (int i = 0; i < URDE_SKIN_SLOTS; ++i) {
objPos += (objs[i] * vec4(posIn, 1.0)) * weightIn[i / 4][i % 4]; objPos += (objs[i] * vec4(posIn, 1.0)) * weightIn[i / 4][i % 4];
objNorm += (objsInv[i] * vec4(normIn, 1.0)) * weightIn[i / 4][i % 4]; objNorm += (objsInv[i] * vec4(normIn, 1.0)) * weightIn[i / 4][i % 4];
@ -57,5 +57,12 @@ void main() {
#endif #endif
vec4 tmpProj; vec4 tmpProj;
vtf.lightmapUv = vec2(0.0);
vtf.diffuseUv = vec2(0.0);
vtf.emissiveUv = vec2(0.0);
vtf.specularUv = vec2(0.0);
vtf.extendedSpecularUv = vec2(0.0);
vtf.reflectionUv = vec2(0.0);
vtf.alphaUv = vec2(0.0);
URDE_TCG_EXPR URDE_TCG_EXPR
} }

View File

@ -0,0 +1,72 @@
cbuffer URDEVertUniform : register(b0) {
#if URDE_SKIN_SLOTS
float4x4 objs[URDE_SKIN_SLOTS];
float4x4 objsInv[URDE_SKIN_SLOTS];
#endif
float4x4 mv;
float4x4 mvInv;
float4x4 proj;
};
struct URDETCGMatrix {
float4x4 mtx;
float4x4 postMtx;
};
cbuffer URDETexMtxUniform : register(b1) {
URDETCGMatrix texMtxs[8];
};
cbuffer URDEReflectMtx : register(b3) {
float4x4 indMtx;
float4x4 reflectMtx;
float reflectAlpha;
};
struct VertData {
float3 posIn : POSITION;
float3 normIn : NORMAL;
#if URDE_COL_SLOTS
float4 colIn[URDE_COL_SLOTS] : COLOR;
#endif
#if URDE_UV_SLOTS
float2 uvIn[URDE_UV_SLOTS] : UV;
#endif
#if URDE_WEIGHT_SLOTS
float4 weightIn[URDE_WEIGHT_SLOTS] : WEIGHT;
#endif
};
VertToFrag main(in VertData v) {
VertToFrag vtf;
#if URDE_SKIN_SLOTS
float4 objPos = float4(0.0, 0.0, 0.0, 0.0);
float4 objNorm = float4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < URDE_SKIN_SLOTS; ++i) {
objPos += mul(objs[i], float4(v.posIn, 1.0)) * v.weightIn[i / 4][i % 4];
objNorm += mul(objsInv[i], float4(v.normIn, 1.0)) * v.weightIn[i / 4][i % 4];
}
objPos[3] = 1.0;
objNorm = float4(normalize(objNorm.xyz), 0.0);
vtf.mvPos = mul(mv, objPos);
vtf.mvNorm = float4(normalize(mul(mvInv, objNorm).xyz), 0.0);
vtf.mvpPos = mul(proj, vtf.mvPos);
#else
float4 objPos = float4(v.posIn, 1.0);
float4 objNorm = float4(v.normIn, 0.0);
vtf.mvPos = mul(mv, objPos);
vtf.mvNorm = mul(mvInv, objNorm);
vtf.mvpPos = mul(proj, vtf.mvPos);
#endif
vtf.lightmapUv = float2(0.0, 0.0);
vtf.diffuseUv = float2(0.0, 0.0);
vtf.emissiveUv = float2(0.0, 0.0);
vtf.specularUv = float2(0.0, 0.0);
vtf.extendedSpecularUv = float2(0.0, 0.0);
vtf.reflectionUv = float2(0.0, 0.0);
vtf.alphaUv = float2(0.0, 0.0);
float4 tmpProj;
URDE_TCG_EXPR
return vtf;
}

View File

@ -112,9 +112,9 @@ static std::string _BuildVS(const SModelShadersInfo& info) {
"vtf.dynReflectionUvs[1] = (reflectMtx * vec4(objPos.xyz, 1.0)).xy;" "vtf.dynReflectionUvs[1] = (reflectMtx * vec4(objPos.xyz, 1.0)).xy;"
"vtf.dynReflectionAlpha = reflectAlpha;"; "vtf.dynReflectionAlpha = reflectAlpha;";
for (int i = 0; i < info.m_extension.texCount; ++i) { for (size_t i = 0; i < info.m_extension.texCount; ++i) {
const auto& extTex = info.m_extension.texs[i]; const auto& extTex = info.m_extension.texs[i];
if (extTex.mtxIdx < 0) if (extTex.mtxIdx == 0xff)
vertOut << "vtf.extUvs["sv << i << "] = "sv << EmitTexGenSource2(extTex.src) << ";"sv; vertOut << "vtf.extUvs["sv << i << "] = "sv << EmitTexGenSource2(extTex.src) << ";"sv;
else else
vertOut << "tmpProj = texMtxs["sv << unsigned(extTex.mtxIdx) << "].postMtx * vec4("sv << vertOut << "tmpProj = texMtxs["sv << unsigned(extTex.mtxIdx) << "].postMtx * vec4("sv <<

View File

@ -0,0 +1,197 @@
#include <cstdint>
#include <cstdlib>
#include <sstream>
#include "shader_CModelShaders.hpp"
#include "Runtime/Graphics/Shaders/CModelShaders.hpp"
extern "C" const uint8_t CMODELSHADERS_COMMON_HLSL[];
extern "C" size_t CMODELSHADERS_COMMON_HLSL_SZ;
static std::string_view CMODELSHADERS_COMMON_HLSL_SV((char*)CMODELSHADERS_COMMON_HLSL, CMODELSHADERS_COMMON_HLSL_SZ);
extern "C" const uint8_t CMODELSHADERS_VERT_HLSL[];
extern "C" size_t CMODELSHADERS_VERT_HLSL_SZ;
static std::string_view CMODELSHADERS_VERT_HLSL_SV((char*)CMODELSHADERS_VERT_HLSL, CMODELSHADERS_VERT_HLSL_SZ);
extern "C" const uint8_t CMODELSHADERS_FRAG_HLSL[];
extern "C" size_t CMODELSHADERS_FRAG_HLSL_SZ;
static std::string_view CMODELSHADERS_FRAG_HLSL_SV((char*)CMODELSHADERS_FRAG_HLSL, CMODELSHADERS_FRAG_HLSL_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 "v.uvIn[0]"sv;
case TexCoordSource::Tex1:
return "v.uvIn[1]"sv;
case TexCoordSource::Tex2:
return "v.uvIn[2]"sv;
case TexCoordSource::Tex3:
return "v.uvIn[3]"sv;
case TexCoordSource::Tex4:
return "v.uvIn[4]"sv;
case TexCoordSource::Tex5:
return "v.uvIn[5]"sv;
case TexCoordSource::Tex6:
return "v.uvIn[6]"sv;
case TexCoordSource::Tex7:
return "v.uvIn[7]"sv;
default:
assert(false && "Unknown source type");
break;
}
return {};
}
static std::string_view EmitTexGenSource4(TexCoordSource src) {
switch (src) {
case TexCoordSource::Position:
return "float4(objPos.xyz, 1.0)"sv;
case TexCoordSource::Normal:
return "float4(objNorm.xyz, 1.0)"sv;
case TexCoordSource::Tex0:
return "float4(v.uvIn[0], 0.0, 1.0)"sv;
case TexCoordSource::Tex1:
return "float4(v.uvIn[1], 0.0, 1.0)"sv;
case TexCoordSource::Tex2:
return "float4(v.uvIn[2], 0.0, 1.0)"sv;
case TexCoordSource::Tex3:
return "float4(v.uvIn[3], 0.0, 1.0)"sv;
case TexCoordSource::Tex4:
return "float4(v.uvIn[4], 0.0, 1.0)"sv;
case TexCoordSource::Tex5:
return "float4(v.uvIn[5], 0.0, 1.0)"sv;
case TexCoordSource::Tex6:
return "float4(v.uvIn[6], 0.0, 1.0)"sv;
case TexCoordSource::Tex7:
return "float4(v.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_HLSL_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 = mul(texMtxs["sv << mtxIdx << "].postMtx, float4("sv <<
(passChunk->shouldNormalizeUv() ? "normalize"sv : ""sv) << "(mul(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 = float2(0.0,0.0);"sv;
}
}
if (!info.m_extension.noReflection && info.m_tag.getReflectionType() != hecl::Backend::ReflectionType::None)
vertOut << "vtf.dynReflectionUvs[0] = normalize(mul(indMtx, float4(objPos.xyz, 1.0)).xz) * float2(0.5, 0.5) + float2(0.5, 0.5);"
"vtf.dynReflectionUvs[1] = mul(reflectMtx, float4(objPos.xyz, 1.0)).xy;"
"vtf.dynReflectionAlpha = reflectAlpha;";
for (size_t i = 0; i < info.m_extension.texCount; ++i) {
const auto& extTex = info.m_extension.texs[i];
if (extTex.mtxIdx == 0xff)
vertOut << "vtf.extUvs["sv << i << "] = "sv << EmitTexGenSource2(extTex.src) << ";"sv;
else
vertOut << "tmpProj = mul(texMtxs["sv << unsigned(extTex.mtxIdx) << "].postMtx, float4("sv <<
(extTex.normalize ? "normalize"sv : ""sv) << "(mul(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_HLSL_SV;
return vertOut.str();
}
static std::string _BuildFS(const SModelShadersInfo& info) {
std::stringstream fragOut;
fragOut << CMODELSHADERS_COMMON_HLSL_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_HLSL_SV;
return fragOut.str();
}
template <>
std::string StageObject_CModelShaders<hecl::PlatformType::D3D11, hecl::PipelineStage::Vertex>::BuildShader(
const SModelShadersInfo& in) {
return _BuildVS(in);
}
template <>
std::string StageObject_CModelShaders<hecl::PlatformType::D3D11, hecl::PipelineStage::Fragment>::BuildShader(
const SModelShadersInfo& in) {
return _BuildFS(in);
}

2
hecl

@ -1 +1 @@
Subproject commit b2bd959c141af761f981d123316df87a86653e7a Subproject commit 5af0a597ba44ed0dde7f39ebabba95cbedbd987e

2
nod

@ -1 +1 @@
Subproject commit 95ed2ae7dc8619054bff5a6d0d63d51f07334943 Subproject commit ed28576b99f87551bfd01a00e37b6f8513dd6135