Jump to content

  • Log In with Google      Sign In   
  • Create Account

MahanGM

Member Since 31 Jul 2012
Offline Last Active Apr 18 2015 02:56 PM

Topics I've Started

Problem with texture coordination in shader

04 April 2015 - 05:56 AM

I'm trying to draw 2d planes with textures. Previously, I was doing this with fixed functions which was fine, but now I'm moving into shaders and I'm stuck.

 

I have written below shader:

/**
 * Parameters
 */
const float4x4     WorldViewProjMatrix;
const int         MaxAnisotropy;
const texture     MainTexture;
const float4     MainColor;
const bool        IsMainTextureSet = true;

/**
 * Samplers
 */
sampler2D MainSampler = sampler_state
{
    Texture = <MainTexture>;
    AddressU = Clamp;
    AddressV = Clamp;
    MipFilter = Point;
    MinFilter = Point;
    MagFilter = Point;
    MaxAnisotropy = <MaxAnisotropy>;
    MipMapLodBias = 0;
};

/**
 * Structs
 */
struct VertexShaderInput
{
    float4 Position : POSITION0;
    float2 TextureUV : TEXCOORD0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float2 TextureUV : TEXCOORD0;
};

struct PixelShaderOutput
{
    float4 Color : COLOR0;
};

/**
 * Functions
 */
VertexShaderOutput VertexShaderMain(VertexShaderInput input)
{
    VertexShaderOutput output;

    output.Position = mul(input.Position, WorldViewProjMatrix);
    output.TextureUV = input.TextureUV;

    return output;
}

PixelShaderOutput PixelShaderMain(VertexShaderOutput input)
{
    PixelShaderOutput output;
    float4 textureColor = (IsMainTextureSet) ? tex2D(MainSampler, input.TextureUV) : float4(1.0f, 1.0f, 1.0f, 1.0f);

    output.Color = saturate(textureColor * MainColor);

    return output;
}
 
/**
 * Techniques
 */
technique Diffuse
{
    pass Pass0
    {
        VertexShader = compile vs_2_0 VertexShaderMain();
        PixelShader = compile ps_2_0 PixelShaderMain();
    }
}

The problem is, only first row and column of the texture is drawn. This seems to be a uv coordination problem, but if it was the problem it shouldn't have worked with fixed functions too.

 

I have attached two files. One is the shot from my application and second is my 128x128 test texture. If you look at the first picture you can see there is a red 2d plane with only the first row and column part of the second picture applied to it. In second picture first row and column is a red line.

 

I'm sure there is something I'm missing.


How to alter an object handle value from host application?

19 January 2015 - 06:07 AM

I faced a problem when I wanted to change the content of a member variable in my script class.

 

This is my class:

class Foo
{
  int baz1;
  Bar@ baz2;
}

I can easily change value types in C++ by:

int* value = (int*)addressOfbaz1;
(*value) = 456;

But this doesn't work with object handles and I know why, but I don't know how I can alter the address that object handles are pointing to.


How to get public member variables from script class in AngelScript

16 January 2015 - 02:08 AM

I'm trying to get member variables declared in an anglescript script class from my host application. There is a function for getting the global properties, but none for getting script class properties.


asBEHAVE_ASSIGNMENT is missing

12 August 2014 - 04:46 PM

I was using angelscript version 2.23.1 and I had this problem when I wanted to register assignment behavior for one of my value types. I downloaded the 2.29.1 version and I still have the same problem. I've checked angelscript header file and this label is just not there.


How to use z axis as depth for 2d quads

25 June 2014 - 05:39 PM

I've been drawing primitives recently and I have problem with rendering order. I was expecting by setting different z values for my quads, I'd get a kind of depth system. I'm not sure what I'm doing wrong or even my theory is true.

 

I simply create my vertices:

Vertex2D vertices[] = {
    {0, 0, 0, color, 0, 0},
    {rect.Width(), 0, 0, color, 1, 0},
    {0, rect.Height(), 0, color, 0, 1},
    {rect.Width(), rect.Height(), 0, color, 1, 1},
    {rect.Width(), 0, 0, color, 1, 0},
};

Then I set translation for them:

D3DXMATRIX translationMatrix;
D3DXMatrixTranslation(&translationMatrix, rect.X() - 0.5f, rect.Y() - 0.5f, depth);

device->SetTransform(D3DTS_WORLD, &translationMatrix);

And finally draw.

 

Before this, I was using D3DXSprite to draw sprites and I was drawing shapes with the Direct3D device itself. There was a depth problem between primitives drawn by Direct3D device and sprites drawn by D3DXSprite so I decided to switch to textured quads for sprite drawing and eliminate D3DXSprite. D3DXSprite had a front to back depth sort flag that could manage different z values, I don't know if there is a magical way to achieve what D3DXSprite is offering or it's just a simple vector sort, I just need to know what's the solution.

 

Thanks.


PARTNERS