Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 11 Jul 2011
Offline Last Active Feb 16 2015 06:35 PM

Topics I've Started

Blurring in HLSL

23 December 2014 - 05:58 AM

Hi all,


First let me say that I'm only just learning to fiddle with shaders after a lifetime spent in the graphics pipeline.  So at this time I'm a savant at best, so please answer all questions as if you were speaking to a small child.


I have a small gaussian blur that I'm using to render shadows, not optimized for the two-step process since I'm just trying to get it to "work" for the moment.  Here is the code:

sampler2D DiffuseSampler; 
float mBlur : register(c0); 
float mTU : register(c1); 
float mTV : register(c2); 

void Blur1(in float2 vTex : TEXCOORD0, out float4 theResult : COLOR0) 
	for (float aU=-3;aU<=2;aU++) 
		theResult+=tex2D(DiffuseSampler, float2(vTex.x+mTU*aU,vTex.y)); 
		theResult+=tex2D(DiffuseSampler, float2(vTex.x-mTU*aU,vTex.y)); 
		theResult+=tex2D(DiffuseSampler, float2(vTex.x,vTex.y-mTV*aU)); 
		theResult+=tex2D(DiffuseSampler, float2(vTex.x,vTex.y+mTV*aU)); 

void main(in float2 vTex : TEXCOORD0, out float4 theResult : COLOR0) 

So all this does is, when it renders the texture to the screen, it does a small averaging of pixels.  And it works.

However, this is not the effect I want.


I render my shadow texture small (512x512) but then it might get drawn very large (up to 4096x4096).  When it's drawn large, it's doing more work, because it must blur 4096x4096 pixels-- when it really only needed to blur 512x512 pixels.


I'm looking for a way to blur the texture I'm using instead.  Like a simple "BlurTexture()" type function, rather than this "BlurTextureWhenDrawn()" thing that I've implemented above.


Like, I assume I'd turn the shader on, then just draw a quad over my whole texture... but I can't seem to get the shader to use the destination as source and blur it.  It just does nothing.


Can anyone assist?



Following a path, determining when to move on to the next point

19 April 2013 - 04:18 PM

Hi all,


Using A*, I have an object that is following a list of points.


Because the object's speed and actual path is somewhat variable (it only follows the general vicinity of the points), I am looking for a good way to determine if it has passed one point and should move on to the next.


I thought I could do this with the dot product, to check the old vector toward the point with the new one, like so:


if (oldVector.Dot(objectTravelVector)<0) // Move to next point

It seems like that should work, but I am getting instances of my object circling points and refusing to move on to the next one.  It seems that if I pass the point, my dot product with the previous vector should be negative, and I just say, okay, next, point.


Am I doing this wrong?



Handling multitouch in Windows (like for Surface Pro)

08 April 2013 - 05:12 PM

Hi all, I have what I hope is a quick and easy question!


On iOS, multitouch is handled by giving each finger touch an ID... it's real simple, as you receive the touch callback, you just query for the ID too.


How is this done in Windows 8, for touch devices?  When I intercept WM_MOUSEMOVE or WM_LBUTTONDOWN, how can I determine the ID of the touch so I can properly handle them without confusing the two?




Interpolation of four points (grid corners)

18 February 2013 - 01:01 PM

Hi all,


Consider, if you will, this image:



Assuming that the four corners there have n value, I'm looking for a way to determine the best values for the red dots (or, actually, and point within the square).  I'm trying to determine light values at a finer grain than just finding the nearest corner and using it.


Is there a way to do this?  I tried simple linear interpolation combining both directions, but the results aren't satisfactory, so I think the way I thought up is fatally flawed.


Thanks for any help!




Booleans and Polygons

16 February 2013 - 12:09 PM

Hi all,


Can anyone direct me to a good resource about applying boolean operations to polygons?


I have a polygon that is basically a list of points.  There's three operations I want to do them:


1) Cut holes in them-- this would ideally produce two new polygons results for me, with a seam somewhere so I have two polygons that have dents in them that represent the hole.


2) Cut pieces of the edges out-- this would ideally produce just one result polygon, which would be identical to the original except with a bite taken out of it where the first one was.


3) Bisect a polygon.  The example of this would be if I had a polygon and then I had another polygon that crossed the whole polygon.  The result would be two polygons with the big bite taken out of the middle, not touching eachother.


I eventually have to triangulate the results.


I'm looking to write this routine myself, so that I can conform it to the quirks of my own polygon class.  At the same time, I'm not the kind of guy who understands pages and pdfs with equations and theory.  Is there a simple resource anywhere that explains this?


(Note: I've looked at several polygon libraries online that accomplish this.  I am looking for lightweight, since I don't need full boolean functionality, just subtraction)