xan1242/nfsc_fixstreakflares

Just a thought regarding onscreen raindrops

Opened this issue · 4 comments

since this fixes light streaks while porting the 360 particle shader over to PC, would a port of the 360 version's (much better) onscreen raindrops be viable?

as to what it changes from the PC version, it changes some naming and variable structure around first of all:

(PC name, Xbox 360 name)
Textures:
DISPMACEMAP (RAINDROPPC) => DIFFUSEMAP_TEXTURE (ONSCREENRAINDROP)
DIFFUSEMAP_TEXTURE (backbuffer) => MISCMAP1_SAMPLER (still backbuffer)
Variables:
RAINDROPALPHA => cvBaseAlphaRef.x
RAINDROPOFFSET => cvLocalCenter

and there's some new stuff too:
cvBaseAlphaRef.y => mask texture horizontal offset
OPACITYMAP_TEXTURE => ONSCREENRAINDROPALPHA, this not only contains a mask but also a small shadow for the raindrops, making them a tad bit more defined

another thing to note is that ONSCREENRAINDROP is 2x the resolution of RAINDROPPC but is otherwise the same texture

I made a real hacky implementation of it by replacing rain_drop.fx and RAINDROPPC with these
image

//
// PC Rain Drop Effect
//
#include "global.h"

DECLARE_TEXTURE(DIFFUSEMAP_TEXTURE)
sampler DIFFUSEMAP_SAMPLER = sampler_state	// backbuffer for screen distortion
{
    ASSIGN_TEXTURE(DIFFUSEMAP_TEXTURE)
	AddressU = CLAMP;
	AddressV = CLAMP;
	DECLARE_MIPFILTER(LINEAR)
	DECLARE_MINFILTER(LINEAR)
	DECLARE_MAGFILTER(LINEAR)
};

DECLARE_TEXTURE(DISPLACEMAP) // PC edit - these NEED to be here for the shader to work!
sampler DISPLACEMAP_SAMPLER = sampler_state
{
	ASSIGN_TEXTURE(DISPLACEMAP)
	AddressU = WRAP;
	AddressV = WRAP;
	DECLARE_MIPFILTER(LINEAR)
	DECLARE_MINFILTER(LINEAR)
	DECLARE_MAGFILTER(LINEAR)
};

float4 RAINDROPOFFSET;
float RAINDROPALPHA;

struct VS_INPUT
{
	float4 position : POSITION;
	float4 color    : COLOR;
	float4 tex		: TEXCOORD;
	float4 size		: TEXCOORD1;
	//int4   light_index	: BLENDINDICES;
    int4   light_index	: TEXCOORD2;
};

///////////////////////////////////////////////////////////////////////////////////////
//
// Onscreen rain particle effect
//
struct VtoP_RAIN
{
	float4 position  : POSITION;
	float4 tex       : TEXCOORD0;
};

VtoP_RAIN vertex_shader_passthru(const VS_INPUT IN)
{
	VtoP_RAIN OUT;
	OUT.position = screen_position(IN.position);
	OUT.position.w = 1.0f;
	OUT.tex = IN.tex * float4(1, -1, 1, 1); // invert it because it's inverted for some reason

	return OUT;
}

float2 scaleUV(float2 uv, float scale) {
	return ((uv-0.5) / scale) + 0.5;
}

float4 pixel_shader_onscreen_distort(const VtoP_RAIN IN) : COLOR0
{	
	// this is an abomination of a formula, but it works
	float rdoffset = floor((((pow(abs(max(max(RAINDROPOFFSET.r, RAINDROPOFFSET.b), max(RAINDROPOFFSET.g, RAINDROPOFFSET.a))-0.5), 2.2))*5000) % 1.0f) * 4)/4;
	float2 cvBaseAlphaRef = float2(RAINDROPALPHA, rdoffset);
	
	float4 distortion = tex2D(DISPLACEMAP_SAMPLER, IN.tex * float2(0.2f, 1.0f));
	float2 offset = distortion.gb * RAINDROPOFFSET.ba + RAINDROPOFFSET.rg;
	float4 background = tex2D(DIFFUSEMAP_SAMPLER, offset);
	
	// The opacity map has four different raindrop texture tiled horizontally.  The
	// offset into this texure is stored in cvBaseAlphaRef.y
	//
	offset = IN.tex;
	offset.x = 0.2 + ((cvBaseAlphaRef.y + IN.tex.x*0.25) * 0.8);
	float4 opacity = tex2D(DISPLACEMAP_SAMPLER, offset);
	
	float4 result;
	result = background * opacity.y;
	result.w = opacity.r * cvBaseAlphaRef.x;

	//result = opacity;
	
	return result;
}



technique sampdisplace <int shader = 1;>
{
    pass p0
    {
	AlphaBlendEnable = TRUE; // has to be manually set here, thanks Black Box
        VertexShader = compile vs_1_1 vertex_shader_passthru();
        PixelShader  = compile ps_3_0 pixel_shader_onscreen_distort();
    }
}

see https://www.youtube.com/watch?v=mWGDlPKwm4k

No. This is primarily a shader fix, not a render rework. You'd need to rework the render code to do so. It's not just the shader for it, there also is the texture that renders on screen. These rain drops in particular are the same ones from Underground 2. I could, instead, do something that ThirteenAG did (or take his and make it work slightly better with the game if needed). -- Lovro Pleše

this would make more sense as a discussion as I never really intended it to be a part of this in particular, but as you haven't enabled discussions on this repo (yet), I had to open it as an issue (fyi issues can be turned into discussions)