diff --git a/Shaders/CModelShaders.frag.hlsl b/Shaders/CModelShaders.frag.hlsl index ab7e77e77..52f0c5421 100644 --- a/Shaders/CModelShaders.frag.hlsl +++ b/Shaders/CModelShaders.frag.hlsl @@ -330,7 +330,7 @@ float4 main(in VertToFrag vtf) : SV_Target0 { #if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) 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, clamp(0.5 - SampleTextureAlpha_specular(vtf), 0.0, 1.0)) * 2.0); + (SampleTexture_reflection(vtf) * ReflectionFunc(vtf, saturate(0.5 - SampleTextureAlpha_specular(vtf))) * 2.0); tmp.a = SampleTextureAlpha_alpha(vtf); #elif defined(URDE_DIFFUSE_ONLY) tmp.rgb = SampleTexture_diffuse(vtf); diff --git a/Shaders/CModelShaders.frag.metal b/Shaders/CModelShaders.frag.metal index 034379829..d1a8ff7e9 100644 --- a/Shaders/CModelShaders.frag.metal +++ b/Shaders/CModelShaders.frag.metal @@ -66,7 +66,7 @@ constant float3 kRGBToYPrime = float3(0.257, 0.504, 0.098); #define SampleTextureAlpha_alpha() dot(alpha.sample(samp, vtf.alphaUv).rgb, kRGBToYPrime) #endif -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_DISINTEGRATE) +#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) struct Fog { float4 color; float A; @@ -76,7 +76,7 @@ struct Fog { }; #endif -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) +#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) struct Light { float4 pos; float4 dir; @@ -104,7 +104,7 @@ constant float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0); constant float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0); #endif -#if defined(URDE_LIGHTING) +#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_CUBE_REFLECTION) float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { float4 ret = lu.ambient; @@ -162,7 +162,7 @@ float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, textur } #endif -#if defined(URDE_LIGHTING_SHADOW) +#if defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { float2 shadowUV = vtf.extUvs0; shadowUV.y = 1.0 - shadowUV.y; @@ -210,7 +210,7 @@ float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, textur } #endif -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_DISINTEGRATE) +#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) float4 FogFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn) { float fogZ; float fogF = saturate((lu.fog.A / (lu.fog.B - (1.0 - vtf.mvpPos.z))) - lu.fog.C); @@ -243,7 +243,7 @@ float4 FogFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colo } #endif -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) +#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, texture2d extTex1, texture2d extTex2, sampler samp, float4 colorIn) { @@ -301,7 +301,10 @@ float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, } #endif -#if defined(URDE_REFLECTION_SIMPLE) +#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) +#define ReflectionFunc(roughness) \ + (reflectionTex.sample(reflectSamp, reflect(vtf.mvPos.xyz, vtf.mvNorm.xyz), bias(roughness)).rgb) +#elif defined(URDE_REFLECTION_SIMPLE) #define ReflectionFunc() \ (reflectionTex.sample(reflectSamp, vtf.dynReflectionUvs1).rgb * vtf.dynReflectionAlpha) #elif defined(URDE_REFLECTION_INDIRECT) @@ -330,11 +333,20 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], texture2d extTex0 [[ texture(8) ]], texture2d extTex1 [[ texture(9) ]], texture2d extTex2 [[ texture(10) ]], +#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) + texturecube reflectionTex [[ texture(11) ]], +#else texture2d reflectionTex [[ texture(11) ]], +#endif constant LightingUniform& lu [[ buffer(4) ]]) { float3 lighting = LightingFunc(vtf, lu, extTex0, clampSamp); float4 tmp; -#if defined(URDE_DIFFUSE_ONLY) +#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) + tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() + + SampleTexture_emissive() + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * + (SampleTexture_reflection() * ReflectionFunc(saturate(0.5 - SampleTextureAlpha_specular())) * 2.0); + tmp.a = SampleTextureAlpha_alpha(); +#elif defined(URDE_DIFFUSE_ONLY) tmp.rgb = SampleTexture_diffuse(); tmp.a = SampleTextureAlpha_alpha(); #elif defined(RETRO_SHADER) diff --git a/hecl b/hecl index 17adf4fb6..b435752eb 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 17adf4fb61b2563d457219755e7279aeb2d1f04d +Subproject commit b435752ebb2238cd103257d1d05cd827416036df diff --git a/visigen/MainMac.mm b/visigen/MainMac.mm index c41f66839..3f18ac114 100644 --- a/visigen/MainMac.mm +++ b/visigen/MainMac.mm @@ -46,6 +46,7 @@ static void UpdatePercent(float percent) } - (void)prepareOpenGL { + [super prepareOpenGL]; s_task = std::thread([self](){ [[self openGLContext] makeCurrentContext]; m_renderer->Run(UpdatePercent);