Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Icebone1000

Member Since 26 Feb 2009
Offline Last Active Today, 04:07 AM

Topics I've Started

How to pin zoom at location

30 July 2015 - 08:28 AM

I have a map that I can scroll (drag with mouse) and zoom.

Im trying to implement this function: 

static void PinScrollZoomAtMapPos(Vector2 mapPos_p, ScrollRect scroll_p)
    {
        // this is to make a point on the map always in the same place on the
        // screen, regardless of current zoom

        Vector2 scrolledMapPos = new Vector2(
               mapPos_p.x + scroll_p.content.localPosition.x,
               mapPos_p.y + scroll_p.content.localPosition.y
               );

        Vector2 scrolledZoomedMapPos = new Vector2(
               mapPos_p.x * scroll_p.content.localScale.x + scroll_p.content.localPosition.x,
               mapPos_p.y * scroll_p.content.localScale.y + scroll_p.content.localPosition.y
               );

        Vector2 diff = scrolledMapPos - scrolledZoomedMapPos;

        Debug.Log("diff: " + diff);

        Vector2 offseted = new Vector2(
            scroll_p.content.localPosition.x + diff.x,
            scroll_p.content.localPosition.y + diff.y
            );

        scroll_p.content.localPosition = offseted;
    }

(The scroll_p.content is the map.)

 

Although I think my logic makes sense at first, I see how it will never work, the 'diff' var should return 0 after subsequent calls to this function, but since I move the map pos, it will never happen. I dont know what I have to do..

 

Now doing this:

static void PinScrollZoomAtMapPos(Vector2 mapPos_p, ScrollRect scroll_p)
    {
        // this is to make a point on the map always in the same place on the
        // screen, regardless of current zoom

        //Vector2 scrolledMapPos = new Vector2(
        //       mapPos_p.x + scroll_p.content.localPosition.x,
        //       mapPos_p.y + scroll_p.content.localPosition.y
        //       );

        Vector2 scrolledZoomedMapPos = new Vector2(
               mapPos_p.x * scroll_p.content.localScale.x + scroll_p.content.localPosition.x,
               mapPos_p.y * scroll_p.content.localScale.y + scroll_p.content.localPosition.y
               );

        Vector2 diff = mapPos_p - scrolledZoomedMapPos;

        Debug.Log("diff: " + diff);

        Vector2 offseted = new Vector2(
            scroll_p.content.localPosition.x + diff.x,
            scroll_p.content.localPosition.y + diff.y
            );

        scroll_p.content.localPosition = offseted;
    }

Works, but the map becomes un-scrollable. I want to account only for zoom, like ignore the displace caused by the zoom (since it enlarges the map from the center).

 

Note this is different from centralizing the map at pos. The pin can be at any place, for example at 80% bottom right of the screen, say theres a city there, I want the city to keep at the exact same place on the screen, while I zoom in/out.

 

I feel is such a simple thing to do,yet Im struggling with this since yesterday.

 

 

 

 

 

 

 


Why no Constant Buffer offsets like for Vertex Buffers?

29 June 2015 - 12:15 PM

This might sound stupid..I was reviewing my instanced sprites code, and something bothered me..

 

[its not about instancing, just the overall architecture/usage of cbuffers]

 

With a draw call I can say which piece of a vertex buffer to use. Meaning I can let it there and use it multiple times by saying offset and number for each drawable..ok

 

So, Instead of having a "drawable" cbuffer for each drawable/'renderable unit', or sharing one between multiple ones and remap it everytime (which is bad due syncing), why cant I just allocate a huge ass cbuffer and use it in slices just like vertex buffers? I could allocate a cbuffer for all my sprites, have each sprite hold an offset, and only map it once per frame..

 

So on the draw call I could have extra params for the cbuffers.

Well, I see you can have lots of different cbuffers on a shader, but its nothing a description structure couldnt solve. (actually, I think an array with offsets for each cbuffer would be enough)

 

Why the difference?

I hope Im making sense. This stuff is again cold in my head.


Ideal chair?

16 January 2015 - 05:09 PM

I never really bothered with this...but my chair sucks, its not comfortable, and I spend too much time on it...

 

Whats the best kind of chair to get long hours programming on?


How to apply Alpha Masks that move around and affect only specific objects (no fullscre...

19 August 2014 - 08:19 PM

Imagine a tiled 2D game where your character goes behind a wall (found a secret spot). Say I want to apply an alpha mask (a circle with faded borders) in the same position the player is, but only for the tiles/sprites hiding the secret spot, not for surrounding environment tiles (where the mask will overlap (due its big size) but not affect, cause theres notting behind then, its a solid wall)

lFgxXkS.png

check how the mask affects only specific tiles

 

Whats the best way to accomplish that?

 

#1# With stencil buffer Id need to render in lots of passes. (I suppose, I dont remember have ever used the stencil buffer before)

Render unaffected tiles + player;

Render the mask in the player position to the stencil buffer;

Render the tiles hiding the secret spot;

 

#2# With specific pixel shader:

Render unaffected tiles + player;

Render the tiles hiding the secret spot w/ a specific pixel shader, that also takes the mask and its screen position.

 

Which method is better?

The pixel shader method sounds better to me, but I dont know how/if it would work.

Id need to check if it overlap with the mask (comparing SV_Position witht the given mask screen position constant), and compute the equivalent uv on the mask..?

 

Computing the equivalent mask uv would be something like

mask uv: (mask_pos - SV_Position) / mask resolution?

What if the current pixel does not overlap (generating negative uvs, or greater than 1)? (if the mask is constrained to have black on the borders than clamping the computed uv to [0,1] would work I guess?)

 

Would #1 or #2 work?

Any better way of doing this?


dx12 - dynamically indexable resources -what exactly it means?

14 August 2014 - 02:07 PM

"In addition to the improved performance offered by descriptor heaps and tables, Direct3D 12 also allows resources to be dynamically indexed in shaders, providing unprecedented flexibility and unlocking new rendering techniques.  As an example, modern deferred rendering engines typically encode a material or object identifier of some kind to the intermediate g-buffer.  In Direct3D 11, these engines must be careful to avoid using too many materials, as including too many in one g-buffer can significantly slow down the final render pass.  With dynamically indexable resources, a scene with a thousand materials can be finalized just as quickly as one with only ten."

link

 

Does this means we will be able to bind lots of textures to a shader and than based on a drawable material (cb variable) pick the correct texture (index to texture) ?

 

Say I have a 2d game and I managed to put all my images on only 3 texture atlas, can I bind the 3 textures and never worry about textures again, as my sprites material will have an index to texture, being able to draw everything w/ a single draw call.

 

Did I get it all wrong?


PARTNERS