Hey!

I was trying to convert some glsl shaders from shadertoy webpage and faced problem with finding viewport resolution (in pixels). I thought that it should be vecViewPort, but I couldn't get it working...

This is the one I was trying to convert:
shockwave2

And this is what I have so far:
Code
const float4 vecTime;
const float4 vecViewPort;

texture TargetMap;

sampler postTex = sampler_state
{
	texture = <TargetMap>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;  
	AddressU = Clamp;
	AddressV = Clamp;
};

float4 FP(float2 TexCoords: TEXCOORD0) : COLOR
{
	// Sawtooth calc of time
	float offset = (vecTime.w - floor(vecTime.w)) / vecTime.w;
	float time = vecTime.w * offset;
	
	// Wave design params
	float3 waveParams = float3(10.0, 0.8, 0.1);
	
	// Find coordinate, flexible to different resolutions
	float maxSize = max(vecViewPort.x, vecViewPort.y);
	float2 uv = TexCoords.xy / maxSize;
	
	// Find center, flexible to different resolutions
	float2 center = vecViewPort.xy / maxSize / 2.0;
	
	// Distance to the center
	float dist = distance(uv, center);
	
	// Original color
	float4 c = tex2D(postTex, uv);
	
	// Limit to waves
	if(time > 0.0 && dist <= time + waveParams.z && dist >= time - waveParams.z)
	{
		// The pixel offset distance based on the input parameters
		float diff = (dist - time);
		float diffPow = (1.0 - pow(abs(diff * waveParams.x), waveParams.y));
		float diffTime = (diff  * diffPow);
		
		// The direction of the distortion
		float2 dir = normalize(uv - center);
		
		// Perform the distortion and reduce the effect over time
		uv += ((dir * diffTime) / (time * dist * 80.0));
		
		// Grab color for the new coord
		c = tex2D(postTex, uv);
		
		// Optionally: Blow out the color for brighter-energy origin
		//c += (c * diffPow) / (time * dist * 40.0);
	}
	
	return c;
}

technique vhs
{
	pass one
	{
		PixelShader = compile ps_3_0 FP();
	}
}
I found out, that when I use 1.0 instead of vecViewPort, it 'kinda works'. I would be glad if you will poke me in the right direction!

Greets.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung