Jump to content

  • Log In with Google      Sign In   
  • Create Account

Tarika

Member Since 06 Mar 2011
Offline Last Active Sep 08 2013 06:38 PM

Topics I've Started

Strange behaviour with texture mapping

16 May 2013 - 10:45 PM

Hey everyone here's an image of a problem I am having:

 

uv_issues.png

 

Hopefully this alone will demonstrate my problem, I am creating sphere like geometry using projected quads. The problem is for some reason even though the quads never overlap, and have UV's of either 0 or 1, the texture seems to get more and more distorted the closer it gets to the poles.

 

At first I thought it was a problem with my coordinate generator, but then I tried to draw a straight forward quad, it draws fine if all edges are at right angles to one another, however if I add a tilt like the image below, I get the distortion again so I am fairly confident there is nothing wrong with the coordinates.

uv_issues1.png

 

Thanks in advance for any help.

 

Aimee


[Solved] Basics, passing color through a vertex shader.

11 May 2013 - 03:06 PM

Hey everyone, I'm having a bit of an issue with shader's in JOGL 2 for Java (JRE 1.7) and I'm hoping you can help. I have an interleaved and un-indexed VBO containing 3 floats per position axis and 3 floats per colour component, I'm able to draw 4 quads absolutely fine if I use the traditional methods for setting up the projection matrix (i.e. glMatrixMode, glLoadIdentity, glOrtho2D). 

When I switch to using my own shader however everything draws fine projection wise, but I am unable to figure out how to pass the vertex colour from vert to frag shaders. So far I have tried various combinations switching between varying and in/out statements to no avail, I am sure I am just missing some syntactical knowledge here and would appreciate if someone could point me in the right direction.

 

Here is the fragment shader I am using:

 

in vec3 diffuse;

void main() {
    gl_FragColor = vec4(diffuse, 1.0);
}

 

 

And here is the vertex shader I am using:

 

uniform mat4 projMatrix;

in vec3 position;
in vec3 color;

out vec3 diffuse;

void main() {
    gl_Position = projMatrix * vec4(position.xyz, 1.0);
    diffuse = vec3(1,1,1);
    // diffuse = color;
}

 

 

Notice the commented out line of code, if I uncomment it and remove the line above the quads I am drawing change from opaque white to transparent (I've made sure by changing the background clear colour). Again I am sure this is just a lack of knowledge on my part but I've been going crazy trying to solve this all day so thanks in advance to anyone who can help me out.

 

 

Aimee


Calculating average mode without creating too much garbage...

06 March 2013 - 06:43 AM

Hey everyone, I'm currently working on some behaviours for non playable characters in a game, and I need to find a reliable and fast method for finding the mode specific average of a set of values. This is not really a mathematics specific question rather a performance once, see the code must be per-formant in various situations where creating things like hash tables or anything else that creates orphan garbage to an extent that has potential to slow the game down to a crawl.

 

So far, I've found 4 different approaches to the issue as follows:

 

static int ModeA(int[] items)
{
    var groups = items.GroupBy(t => t);
    int maxCount = groups.Max(g => g.Count());
    return groups.First(g => g.Count() == maxCount).Key;
}
 
static int ModeB(IEnumerable<int> items)
{
    int maxVal = 0, maxCount = 0, curCount;
    var iter = items.GetEnumerator();
    while (iter.MoveNext())
    {
        curCount = items.Count(t => t == iter.Current);
        if (curCount > maxCount)
        {
            maxVal = iter.Current;
            maxCount = curCount;
        }
    }
    return maxVal;
}
 
static int ModeC(int[] items)
{
    int maxVal, maxCount, curCount;
    for (int i = maxVal = curCount = maxCount = 0; i < items.Length; i++)
    {
        var curVal = items[i];
        if ((curCount = items.Count(t => t == curVal)) > maxCount)
        {
            maxVal = curVal;
            maxCount = curCount;
        }
    }
    return maxVal;
}
 
static int ModeD(int[] items)
{
    int maxVal = 0, maxCount = 0, curCount = 0, curVal = 0, i = 0, j = 0;
    for (i = 0, j = 0; i < items.Length; i++, curCount = 0)
    {
        curVal = items[i]; 
 
        for (j = 0; j < items.Length; j++)
            if (items[j] == curVal) 
                curCount++;
 
        if (curCount > maxCount)
        {
            maxVal = curVal;
            maxCount = curCount;
        }
    }
    return maxVal;
}

 

 

And here is what I get performance wise if I ask each function to return the mode for 10,000 elements (timed with the Stopwatch class):

 

Method A Took: 00:00:00.0112893.
Method B Took: 00:00:02.9916290.
Method C Took: 00:00:02.3635998.
Method D Took: 00:00:00.5677500.
 
Hopefully you'll already be able to see my problem, method A is obviously the fastest but method D is more favourable (at least from what I can see as it doesn't create an enumerable collection like A and B do). In the real-time scenario I'll only be throwing a maximum of 300 elements at this method, which gives me something more reasonable:
 
Method A Took: 00:00:00.0087793.
Method B Took: 00:00:00.0039755.
Method C Took: 00:00:00.0026175.
Method D Took: 00:00:00.0007191.
 
And if I repeat this test within a loop a few times, the results change slightly:

Method A Took: 00:00:00.0000429.
Method B Took: 00:00:00.0027317.
Method C Took: 00:00:00.0021401.
Method D Took: 00:00:00.0005269.
 
Again obviously method A is the fastest, but in this 2rd test only after iteration. So my question is am I being too obsessed over this when I could just go with method A and sod GC, or is method D truly better even though I never see that much improvement after iteration and on larger arrays it struggles.
 
Thanks everyone for any feedback on the subject.
 
Aimee

HLSL Unpack float into 4 bytes

18 February 2013 - 04:30 AM

Hey everyone, if I pack 4 bytes into a float, is there any way for me to pass that float into a HLSL shader and un-pack those bytes again. I'm looking into this to save wastage in an instancing routine, I'd rather not have to use a whole float to represent a single byte value. If it helps, the method I'm using for packing the bytes is BitConverter.ToSingle
 
I also found a good example ( http://theinstructionlimit.com/encoding-boolean-flags-into-a-float-in-hlsl ) on how to pack/un-pack boolean's which is helpful, but really I need the bytes.
 
Thanks for any help.
 
Aimee

Instance index within vertex shader.

17 October 2012 - 02:19 AM

Hi Everyone

I'm currently trying to offload a task where I draw a bunch of sprites onto the graphics card as the GPU is not crunching much in our game, and I've been playing with the idea of instancing a single quad. My question is; is there any easy way to get an index of each instance within the vertex shader?

Thanks all

Aimee

PARTNERS