From 71526a415d31c24a08150f9bed28babb2811285a Mon Sep 17 00:00:00 2001 From: Leo Reyes Date: Mon, 1 Feb 2021 21:36:59 -0800 Subject: [PATCH] Animated Textures now support bloom. The intensity field in the anim_seq or anim_rand list is now honored. This was done by modifying the NoGlass pixel shader. --- impl11/ddraw/Direct3DDevice.cpp | 76 ++++----------------- impl11/shaders/PixelShaderAnimLightMap.hlsl | 5 ++ impl11/shaders/PixelShaderNoGlass.hlsl | 19 +++++- 3 files changed, 37 insertions(+), 63 deletions(-) diff --git a/impl11/ddraw/Direct3DDevice.cpp b/impl11/ddraw/Direct3DDevice.cpp index ffd387c1..b5ee5e18 100644 --- a/impl11/ddraw/Direct3DDevice.cpp +++ b/impl11/ddraw/Direct3DDevice.cpp @@ -4601,68 +4601,10 @@ HRESULT Direct3DDevice::Execute( if (lastTextureSelected->material.AlphaIsntGlass && !bIsLightTexture) { bModifiedPixelShader = true; bModifiedShaders = true; + g_PSCBuffer.fBloomStrength = 0.0f; resources->InitPixelShader(resources->_noGlassPS); } - -#ifdef DISABLED - // This block was moved after the DynamicCockpit texture replacement, so that we can - // animate cover textures! - // Animated Light Maps/Textures - if ((bIsLightTexture && lastTextureSelected->material.LightMapATCIndex > -1) || - (!bIsLightTexture && lastTextureSelected->material.TextureATCIndex > -1)) - { - //log_debug("[DBG] %s, LightMapATCIndex: %d, TextureATCIndex: %d", lastTextureSelected->_surface->_name, - // lastTextureSelected->material.LightMapATCIndex, lastTextureSelected->material.TextureATCIndex); - - //int ATCIndex = bIsLightTexture ? - // lastTextureSelected->material.LightMapATCIndex : lastTextureSelected->material.TextureATCIndex; - - // The entry condition into this block makes it impossible for ATCIndex to end up with a -1: - // One of LightMapATCIndex or TextureATCIndex must be > -1 - int ATCIndex = -1; - if (bIsLightTexture) { - bModifiedPixelShader = true; - resources->InitPixelShader(resources->_pixelShaderAnimLightMap); - ATCIndex = lastTextureSelected->material.LightMapATCIndex; - } else - ATCIndex = lastTextureSelected->material.TextureATCIndex; - - AnimatedTexControl *atc = &(g_AnimatedMaterials[ATCIndex]); - int idx = atc->AnimIdx; - //log_debug("[DBG] %s, ATCIndex: %d", lastTextureSelected->_surface->_name, ATCIndex); - - //int rand_idx = rand() % lastTextureSelected->material.LightMapSequence.size(); - int extraTexIdx = atc->Sequence[idx].ExtraTextureIndex; - - /* - // DEBUG - static std::vector DumpedIndices; - bool bInVector = false; - for each (int index in DumpedIndices) - if (index == extraTexIdx) { - bInVector = true; - break; - } - if (!bInVector) { - wchar_t filename[80]; - ID3D11Resource *res = NULL; - resources->_extraTextures[extraTexIdx]->GetResource(&res); - swprintf_s(filename, 80, L"c:\\temp\\_extraTex-%d.png", extraTexIdx); - DirectX::SaveWICTextureToFile(context, res, GUID_ContainerFormatPng, filename); - DumpedIndices.push_back(extraTexIdx); - log_debug("[DBG] Dumped extraTex %d", extraTexIdx); - } - // DEBUG - */ - - if (extraTexIdx > -1) { - // Use the following when using std::vector: - resources->InitPSShaderResourceView(resources->_extraTextures[extraTexIdx]); - } - } -#endif } - // Apply the SSAO mask/Special materials, like lasers and HUD //if (g_bAOEnabled && bLastTextureSelectedNotNULL) @@ -4894,6 +4836,16 @@ HRESULT Direct3DDevice::Execute( g_PSCBuffer.fBloomStrength = g_BloomConfig.fSkydomeLightStrength; g_PSCBuffer.bIsEngineGlow = 1; } + else if (!bIsLightTexture && lastTextureSelected->material.TextureATCIndex > -1) { + bModifiedShaders = true; + int anim_idx = lastTextureSelected->material.TextureATCIndex; + // If this is an animated light map, then use the right intensity setting + // TODO: Make the following code more efficient + if (anim_idx > -1) { + AnimatedTexControl *atc = &(g_AnimatedMaterials[anim_idx]); + g_PSCBuffer.fBloomStrength = atc->Sequence[atc->AnimIdx].intensity; + } + } // Remove Bloom for all textures with materials tagged as "NoBloom" if (bHasMaterial && lastTextureSelected->material.NoBloom) @@ -5024,6 +4976,7 @@ HRESULT Direct3DDevice::Execute( if ((bIsLightTexture && lastTextureSelected->material.LightMapATCIndex > -1) || (!bIsLightTexture && lastTextureSelected->material.TextureATCIndex > -1)) { + bModifiedPixelShader = true; //log_debug("[DBG] %s, LightMapATCIndex: %d, TextureATCIndex: %d", lastTextureSelected->_surface->_name, // lastTextureSelected->material.LightMapATCIndex, lastTextureSelected->material.TextureATCIndex); @@ -5034,12 +4987,13 @@ HRESULT Direct3DDevice::Execute( // One of LightMapATCIndex or TextureATCIndex must be > -1 int ATCIndex = -1; if (bIsLightTexture) { - bModifiedPixelShader = true; resources->InitPixelShader(resources->_pixelShaderAnimLightMap); ATCIndex = lastTextureSelected->material.LightMapATCIndex; } - else + else { + resources->InitPixelShader(resources->_noGlassPS); ATCIndex = lastTextureSelected->material.TextureATCIndex; + } AnimatedTexControl *atc = &(g_AnimatedMaterials[ATCIndex]); int idx = atc->AnimIdx; diff --git a/impl11/shaders/PixelShaderAnimLightMap.hlsl b/impl11/shaders/PixelShaderAnimLightMap.hlsl index 4da9b651..c7027765 100644 --- a/impl11/shaders/PixelShaderAnimLightMap.hlsl +++ b/impl11/shaders/PixelShaderAnimLightMap.hlsl @@ -1,4 +1,9 @@ // Copyright (c) 2021 Leo Reyes +// This shader is used to display animated light maps. +// Transparent areas won't change the previous contents; but this shader +// can be used to render solid areas just like the regular pixel shader. +// The main difference with the regular light map shader is that the alpha +// of the light map is not multiplied by 10. // Licensed under the MIT license. See LICENSE.txt #include "shader_common.h" #include "HSV.h" diff --git a/impl11/shaders/PixelShaderNoGlass.hlsl b/impl11/shaders/PixelShaderNoGlass.hlsl index 8261d5a7..161074a6 100644 --- a/impl11/shaders/PixelShaderNoGlass.hlsl +++ b/impl11/shaders/PixelShaderNoGlass.hlsl @@ -1,7 +1,8 @@ -// Copyright (c) 2020 Leo Reyes +// Copyright (c) 2020, 2021 Leo Reyes // Licensed under the MIT license. See LICENSE.txt // Simplified version of PixelShaderTexture. Alpha-enabled textures won't be interpreted -// as glass materials +// as glass materials. if fBloomStrength is not zero, then bloom will be applied and +// modulated by the alpha of the texture. // Light Textures are not handled in this shader. This shader should not be used with // illumination textures. #include "shader_common.h" @@ -64,6 +65,20 @@ PixelShaderOutput main(PixelShaderInput input) output.ssaoMask = float4(fSSAOMaskVal, fGlossiness, fSpecInt, alpha); // SS Mask: Normal Mapping Intensity, Specular Value, Shadeless output.ssMask = float4(fNMIntensity, fSpecVal, fAmbient, alpha); + + // bloom + float3 HSV = RGBtoHSV(texelColor.rgb); + if (HSV.z >= 0.8) { + float bloom_alpha = saturate(fBloomStrength); + diffuse = 1.0; + output.bloom = float4(fBloomStrength * texelColor.rgb, alpha); + //output.ssaoMask.r = SHADELESS_MAT; + output.ssMask.b = bloom_alpha; + //output.ssaoMask.ga = 1; // Maximum glossiness on light areas + output.ssaoMask.a = bloom_alpha; + //output.ssaoMask.b = 0.15; // Low spec intensity + output.ssaoMask.b = 0.15 * bloom_alpha; // Low spec intensity + } output.color = float4(brightness * diffuse * texelColor.xyz, texelColor.w); return output; }