Gamestudio Links
Zorro Links
Newest Posts
Oanda instruments
by Morris. 06/05/20 10:24
Indicator coding
by Grat. 06/05/20 09:29
MT4/5 - wrong M1 time
by Grat. 06/05/20 08:34
fce for close signal
by Grat. 06/05/20 06:09
TMF - Chandelier
by danatrader. 06/05/20 05:03
The Black Book
by danatrader. 06/05/20 04:29
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
12 registered members (alibaba, danatrader, 3run, Grat, ChrstphFr, jbhunter, deepscreener, Mio, 2 invisible), 467 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Frank_Shieh, PBSeven, Hardi01, Giuseppe, AdamWu
18461 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,265
Caucasus
3run Online OP
Senior Expert
3run  Online OP
Senior Expert

Joined: May 2009
Posts: 5,265
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
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,322
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,322
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,265
Caucasus
3run Online OP
Senior Expert
3run  Online OP
Senior Expert

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


Looking for free stuff?? Take a look here: http://badcom.at.ua

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