• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Flicklizic

Painting texture layers - pixel shader

4 posts in this topic

I'm creating a little editor for my terrain so I can "paint" the terrain, but I'm getting something around 20 FPS using 8 textures and 2 alphamaps from now.

My HLSL code for pixel shader:

 

////////////////////////////////////////////////////////////////////////////////
// Filename: terrain.ps
////////////////////////////////////////////////////////////////////////////////


/////////////
// GLOBALS //
/////////////

Texture2D textures[8];
Texture2D alphaTextures[2];


//////////////
// SAMPLERS //
//////////////
SamplerState SampleType;


//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float2 alpha : TEXCOORD1;
float3 normal : NORMAL;
};


////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 TerrainPixelShader(PixelInputType input) : SV_TARGET
{
int i;
float4 color;
float4 baseColor;
float4 textureColor[8];
float4 alphaMap[2];

// Sample all textures
for(i=0; i<8; i++)
{
textureColor[i] = textures[i].Sample(SampleType, input.tex, 0);
}

// Sample the alphamaps
for(i=0; i<2; i++)
{
alphaMap[i] = alphaTextures[i].Sample(SampleType, input.alpha, 0);
}

// Set the base color
color.r = 0;
color.g = 0;
color.b = 0;
color.a = 255;

// Add the second layer using the red channel of the alpha map.
color = lerp(color, textureColor[0], alphaMap[0].r);

// Add the third layer using the green channel of the alpha map.
color = lerp(color, textureColor[1], alphaMap[0].g);

// Add the forth layer using the blue channel of the alpha map.
color = lerp(color, textureColor[2], alphaMap[0].b);

// Add the fifth layer using the alpha channel of the alpha map.
color = lerp(color, textureColor[3], alphaMap[0].a);

// Add the sixth layer using the red channel of the alpha map.
color = lerp(color, textureColor[4], alphaMap[1].r);

// Add the seventh layer using the green channel of the alpha map.
color = lerp(color, textureColor[5], alphaMap[1].g);

// Add the eigth layer using the blue channel of the alpha map.
color = lerp(color, textureColor[6], alphaMap[1].b);

// Add the eigth layer using the alpha channel of the alpha map.
color = lerp(color, textureColor[7], alphaMap[1].a);

// Return the final color
return color;
}
 

 

 


Yes I know that I could check if I really need to use the 8 textures (and skip some part of the code) but I want to imagine a situation where I NEED to use all textures.

The FPS start to drop when I paint more layers, everything start black, when I paint the first layer (Just need to be a little pixel) my FPS go from 55 to 45, the second layer makes my fps go from 45 to 37 and so on...

There is a better way to achieve this or this Is the only way? I'm a little new on directX so I belive there is something wrong with my code (or my theory) Thanks!

Note that my first texture coordinates repeat the terrain about 4X and the alpha fills only one time, this is slowing things too because if I use the alpha coordinates for the textures too my FPS grows up +-20. (the coordinates go from 0.0 to 1.0 on both).

0

Share this post


Link to post
Share on other sites

you perform a 10 lookups and a couple of lerps so that is not the most performance heavy shader...

Without more info about the context you use this shader (texture sizes, sampler types, geometry count, how/how often do you update the textures,...) I don't think we can improve a lot here...

0

Share this post


Link to post
Share on other sites

Here is the info:

 

- All textures are 1024x1024

- The alpha textures are 256x256

 

- The sampler state is configured like this:

 

 

   samplerDesc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
    samplerDesc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
    samplerDesc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
    samplerDesc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
    samplerDesc.MipLODBias = 0.0f;
    samplerDesc.MaxAnisotropy = 1;
    samplerDesc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
    samplerDesc.BorderColor[0] = 0;
    samplerDesc.BorderColor[1] = 0;
    samplerDesc.BorderColor[2] = 0;
    samplerDesc.BorderColor[3] = 0;
    samplerDesc.MinLOD = 0;
    samplerDesc.MaxLOD = D3D10_FLOAT32_MAX;
 

 

- My terrain has 128x128 vertices

 

I only update the alpha textures (only when I want to paint)

 

And one more thing... I only use 1 MipLevel for all textures, maybe this is what is causing this?

 

0

Share this post


Link to post
Share on other sites

I only use 1 MipLevel for all textures, maybe this is what is causing this?

Most likely, although it depends on how "zoomed in" you are in to your terrain. If one pixel of your rendered terrain ends up corresponding to more than a couple of texels of your texture, then using mip maps will help performance (they will significantly reduce texture bandwidth, which may be your perf bottleneck). In general, you should be using mip maps.

What format are your textures? Using DXT compression will also significantly reduce texture sampling bandwidth.
0

Share this post


Link to post
Share on other sites

From my experience disabling mipmapping lowers framerate in many situations, especially if the texture is being drawn to many pixels like a terrain would. Not so much a problem for closer objects than it is for farther ones. Part of the extra GPU work of not using mipmaps also results from determining which texel takes priority for a given pixel.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0