HLSL cubemaps

This commit is contained in:
Jack Andersen 2019-05-31 23:28:12 -10:00
parent 410d7896f7
commit 4a4cf58b6f
4 changed files with 25 additions and 12 deletions

View File

@ -150,7 +150,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, false, false, true}, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true},
/* Normal lit shading with cube reflection and world shadow */ /* Normal lit shading with cube reflection and world shadow */
{0, nullptr, 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}};
static const char* ShaderMacros[] = { static const char* ShaderMacros[] = {

View File

@ -309,8 +309,7 @@ vec4 PostFunc(vec4 colorIn) {
#endif #endif
#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) #if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW)
vec3 ReflectionFunc(float roughness) { return texture(reflectionTex, reflect(vtf.mvPos.xyz, vtf.mvNorm.xyz), vec3 ReflectionFunc(float roughness) { return texture(reflectionTex, reflect(vtf.mvPos.xyz, vtf.mvNorm.xyz), roughness).rgb; }
roughness * 5.0).rgb; }
#elif defined(URDE_REFLECTION_SIMPLE) #elif defined(URDE_REFLECTION_SIMPLE)
vec3 ReflectionFunc() { return texture(reflectionTex, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; } vec3 ReflectionFunc() { return texture(reflectionTex, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; }
#elif defined(URDE_REFLECTION_INDIRECT) #elif defined(URDE_REFLECTION_INDIRECT)

View File

@ -12,7 +12,12 @@ Texture2D reflectionIndTex : register(t7);
Texture2D extTex0 : register(t8); Texture2D extTex0 : register(t8);
Texture2D extTex1 : register(t9); Texture2D extTex1 : register(t9);
Texture2D extTex2 : register(t10); Texture2D extTex2 : register(t10);
#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW)
TextureCube reflectionTex : register(t11);
#else
Texture2D reflectionTex : register(t11); Texture2D reflectionTex : register(t11);
#endif
static const float3 kRGBToYPrime = float3(0.257, 0.504, 0.098); static const float3 kRGBToYPrime = float3(0.257, 0.504, 0.098);
@ -82,7 +87,7 @@ float3 SampleTexture_alpha(in VertToFrag vtf) { return alpha.Sample(samp, vtf.al
float SampleTextureAlpha_alpha(in VertToFrag vtf) { return dot(alpha.Sample(samp, vtf.alphaUv).rgb, kRGBToYPrime); } float SampleTextureAlpha_alpha(in VertToFrag vtf) { return dot(alpha.Sample(samp, vtf.alphaUv).rgb, kRGBToYPrime); }
#endif #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 { struct Fog {
float4 color; float4 color;
float A; float A;
@ -92,7 +97,7 @@ struct Fog {
}; };
#endif #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 { struct Light {
float4 pos; float4 pos;
float4 dir; float4 dir;
@ -117,7 +122,7 @@ 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); static const float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0);
#endif #endif
#if defined(URDE_LIGHTING) #if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_CUBE_REFLECTION)
float3 LightingFunc(in VertToFrag vtf) { float3 LightingFunc(in VertToFrag vtf) {
float4 ret = ambient; float4 ret = ambient;
@ -174,7 +179,7 @@ cbuffer MBShadowUniform : register(b2) {
}; };
#endif #endif
#if defined(URDE_LIGHTING_SHADOW) #if defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW)
float3 LightingFunc(in VertToFrag vtf) { float3 LightingFunc(in VertToFrag vtf) {
float2 shadowUV = vtf.extUvs[0]; float2 shadowUV = vtf.extUvs[0];
shadowUV.y = 1.0 - shadowUV.y; shadowUV.y = 1.0 - shadowUV.y;
@ -222,7 +227,7 @@ float3 LightingFunc(in VertToFrag vtf) {
} }
#endif #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(in VertToFrag vtf, float4 colorIn) { float4 FogFunc(in VertToFrag vtf, float4 colorIn) {
float fogZ; float fogZ;
float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.mvpPos.z))) - fog.C); float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.mvpPos.z))) - fog.C);
@ -255,7 +260,7 @@ float4 FogFunc(in VertToFrag vtf, float4 colorIn) {
} }
#endif #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(in VertToFrag vtf, float4 colorIn) { float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
return FogFunc(vtf, colorIn) * mulColor + addColor; return FogFunc(vtf, colorIn) * mulColor + addColor;
} }
@ -301,7 +306,11 @@ float4 PostFunc(in VertToFrag vtf, float4 colorIn) {
} }
#endif #endif
#if defined(URDE_REFLECTION_SIMPLE) #if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW)
float3 ReflectionFunc(in VertToFrag vtf, float roughness) {
return reflectionTex.SampleBias(reflectSamp, reflect(vtf.mvPos.xyz, vtf.mvNorm.xyz), roughness).rgb;
}
#elif defined(URDE_REFLECTION_SIMPLE)
float3 ReflectionFunc(in VertToFrag vtf) float3 ReflectionFunc(in VertToFrag vtf)
{ return reflectionTex.Sample(reflectSamp, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; } { return reflectionTex.Sample(reflectSamp, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; }
#elif defined(URDE_REFLECTION_INDIRECT) #elif defined(URDE_REFLECTION_INDIRECT)
@ -318,7 +327,12 @@ float3 ReflectionFunc(in VertToFrag vtf) { return float3(0.0, 0.0, 0.0); }
float4 main(in VertToFrag vtf) : SV_Target0 { float4 main(in VertToFrag vtf) : SV_Target0 {
float3 lighting = LightingFunc(vtf); float3 lighting = LightingFunc(vtf);
float4 tmp; float4 tmp;
#if defined(URDE_DIFFUSE_ONLY) #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);
tmp.a = SampleTextureAlpha_alpha(vtf);
#elif defined(URDE_DIFFUSE_ONLY)
tmp.rgb = SampleTexture_diffuse(vtf); tmp.rgb = SampleTexture_diffuse(vtf);
tmp.a = SampleTextureAlpha_alpha(vtf); tmp.a = SampleTextureAlpha_alpha(vtf);
#elif defined(RETRO_SHADER) #elif defined(RETRO_SHADER)

2
hecl

@ -1 +1 @@
Subproject commit 9bb5181bbd9657c6b48d9a214352a72b26d411a0 Subproject commit 17adf4fb61b2563d457219755e7279aeb2d1f04d