XaskeL

water caustics

Oct 1st, 2019
188
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local SHADER_CODE = [[
  2.     #include "mta-helper.fx"
  3.    
  4.     #define TAU 6.28318530718
  5.     #define MAX_ITER 6
  6.    
  7.     sampler Sampler0 : register( s0 );
  8.      
  9.     struct VSInput
  10.     {
  11.         float4 Position     : POSITION0;  
  12.         float4 Diffuse      : COLOR0;
  13.         float2 TexCoord     : TEXCOORD0;
  14.     };
  15.      
  16.     struct PSInput
  17.     {
  18.         float4 Position     : POSITION0;
  19.         float2 TexCoord     : TEXCOORD0;
  20.         float4 Diffuse      : COLOR0;
  21.     };
  22.  
  23.     float3 vec3(float x,float y,float z) { return float3(x,y,z); }
  24.     float3 vec3(float x) { return float3(x,x,x); }
  25.     float3 vec3(float2 x,float y) { return float3(float2(x.x,x.y),y); }
  26.  
  27.     float2 vec2(float x,float y) { return float2(x,y); }
  28.     float2 vec2(float x) { return float2(x,x); }
  29.      
  30.     PSInput VertexShaderFunction(VSInput VS)
  31.     {
  32.         PSInput PS = (PSInput)0;
  33.          
  34.         float4 worldPosition    = mul(VS.Position, gWorld);
  35.         float4 viewPosition     = mul(worldPosition, gView);
  36.         float4 position         = mul(viewPosition, gProjection);
  37.          
  38.         PS.Position             = position;
  39.         PS.TexCoord             = VS.TexCoord;
  40.        
  41.         PS.Diffuse              = MTACalcGTABuildingDiffuse(VS.Diffuse);
  42.        
  43.         return PS;
  44.     }
  45.    
  46.     float4 PixelShaderFunction( PSInput PS ) : COLOR0
  47.     {
  48.         float time = gTime*0.5+23.0;
  49.         float2 uv = PS.TexCoord.xy / 1;
  50.        
  51.         float2 p = fmod(uv*TAU*2.0, TAU)-250.0;
  52.        
  53.         float2 i = vec2(p);
  54.         float c = 1.0;
  55.         float inten = 0.005;
  56.        
  57.         for (int n = 0; n < MAX_ITER; n++)
  58.         {
  59.             float t = time * (1.0 - (3.5 / float(n+1)));
  60.             i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
  61.             c += 1.0/length(vec2(p.x / (sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten)));
  62.         }
  63.        
  64.         c /= float(MAX_ITER);
  65.         c = 1.17-pow(c, 1.4);
  66.        
  67.         float3 colour = vec3(pow(abs(c), 8.0));
  68.         colour = clamp(colour + vec3(0.0, 0.35, 0.5), 0.0, 1.0);
  69.        
  70.         float4 maincolor = tex2D(Sampler0, PS.TexCoord) * PS.Diffuse;
  71.         return float4(colour, 1.0) * maincolor;
  72.     }
  73.      
  74.     technique
  75.     {
  76.         pass P0
  77.         {
  78.             AlphaBlendEnable = TRUE;
  79.             VertexShader     = compile vs_3_0 VertexShaderFunction();
  80.             PixelShader      = compile ps_3_0 PixelShaderFunction();
  81.         }
  82.     }
  83. ]]
  84.  
  85. local shader = DxShader(SHADER_CODE, 0, 3, true, "world,object")
  86. shader:applyToWorldTexture("*")
  87.  
  88. addEventHandler('onClientRender', root, function()
  89.     dxDrawImage(300, 300, 300, 300, shader)
  90. end )
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×