Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, Nymphodora), 1,012 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
vecViewPort and viewport resolution (in pixels) #479414
03/27/20 19:01
03/27/20 19:01
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
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
Re: vecViewPort and viewport resolution (in pixels) [Re: 3run] #479419
03/27/20 21:30
03/27/20 21:30
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
As far as I see, you only need to replace TEXCOORD0 by VPOS. The former is normalized while the second is in pixels.

Salud!

Re: vecViewPort and viewport resolution (in pixels) [Re: 3run] #479421
03/27/20 21:48
03/27/20 21:48
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Thank you txesmi! It seems to work fine now! :>


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

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1