Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // PC Rain Drop Effect
- //
- #include "global.h"
- shared texture diffusemap : DiffuseMap;
- sampler DIFFUSEMAP_SAMPLER = sampler_state // backbuffer for screen distortion
- {
- Texture = <diffusemap>;
- AddressU = CLAMP;
- AddressV = CLAMP;
- MipFilter = LINEAR;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- };
- shared texture displacemap : DISPLACEMAP;
- sampler DISPLACEMAP_SAMPLER = sampler_state
- {
- Texture = <displacemap>;
- AddressU = WRAP;
- AddressV = WRAP;
- MipFilter = LINEAR;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- };
- sampler DISPLACEMAP_SHADOW_SAMPLER = sampler_state
- {
- Texture = <displacemap>;
- AddressU = BORDER;
- AddressV = BORDER;
- BorderColor = 0x00000000;
- MipFilter = LINEAR;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- };
- shared float4 raindropoffset : RAINDROPOFFSET;
- shared float raindropalpha : 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;
- OUT.tex.y = 1-IN.tex.y; // 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 = float4(distortion.w, lerp(1, tex2D(DISPLACEMAP_SHADOW_SAMPLER, IN.tex + float2(0,2/32.f)).w, 0.5*distortion.w), 1, 1);//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
- SrcBlend = 5; // D3DBLEND_SRCALPHA
- DestBlend = 6; // D3DBLEND_INVSRCALPHA
- VertexShader = compile vs_1_1 vertex_shader_passthru();
- PixelShader = compile ps_2_0 pixel_shader_onscreen_distort();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement