Skip to content

Commit

Permalink
Animated Textures now support bloom.
Browse files Browse the repository at this point in the history
The intensity field in the anim_seq or anim_rand list is now honored. This was
done by modifying the NoGlass pixel shader.
  • Loading branch information
Prof-Butts committed Feb 2, 2021
1 parent bbb5799 commit 71526a4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 63 deletions.
76 changes: 15 additions & 61 deletions impl11/ddraw/Direct3DDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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<ID3D11ShaderResourceView*>:
resources->InitPSShaderResourceView(resources->_extraTextures[extraTexIdx]);
}
}
#endif
}


// Apply the SSAO mask/Special materials, like lasers and HUD
//if (g_bAOEnabled && bLastTextureSelectedNotNULL)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions impl11/shaders/PixelShaderAnimLightMap.hlsl
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
19 changes: 17 additions & 2 deletions impl11/shaders/PixelShaderNoGlass.hlsl
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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;
}

0 comments on commit 71526a4

Please sign in to comment.