• 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
RyxiaN

[SlimDX] Multitexturing & a cursor on the terrain

4 posts in this topic

Hey, I've got a slight problem when I'm trying to render a cursor on the terrain. I've got a grid of 100*100 vertices and a shader that does multitexturing with 2 different textures that works great. I looked at [url="http://www.3dgameprogramming.net/2007/06/25/xna-terrain-editor/"]some XNA code[/url] which did exactly what I wanted: displaying a ground cursor on the terrain. It works great at close views, let me show you some pictures.

Here's the cursor I want to display: (Temporarily used from the code I found, for testing & learning)
[img]http://i52.tinypic.com/4ttwli.png[/img]

Here's what it looks like at a close view, with and without wireframe mode on:
[img]http://i56.tinypic.com/t5g42a.png[/img]
[img]http://i55.tinypic.com/112fzx2.png[/img]

And this is what happens when you zoom out:
[img]http://i54.tinypic.com/15x6at4.png[/img]
[img]http://i54.tinypic.com/fufjd.png[/img]

Basically the the cursor is rendered across the entire terrain but I'm clamping the coordinates, so I'm assuming when I zoom out the texture gets so small that the edges are yellow aswell. I've done it exactly how the sample that I looked in did it, and it works perfect in the sample. So I don't get whats wrong.

Here's the HLSL code:
[CODE]// Variables
float4x4 View;
float4x4 Projection;
float4x4 World;
float3 LightDirection;
float Ambient;
bool EnableLighting;

// Cursor
float3 GroundCursorPosition;
texture GroundCursorTexture;
int GroundCursorSize;
bool ShowGroundCursor;

// Textures
texture t0;
float t0scale;
texture t1;
float t1scale;

sampler t0sampler = sampler_state {
Texture = (t0);
MagFilter = Linear;
MinFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler t1sampler = sampler_state {
Texture = (t1);
MagFilter = Linear;
MinFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler CursorSampler = sampler_state {
Texture = (GroundCursorTexture);
MagFilter = Linear;
MipFilter = Linear;
MinFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};

struct VS_INPUT {
float4 Position : POSITION0;
float3 Normal : NORMAL;
float2 TextureCoordinate : TEXCOORD0;
float2 Weights : TEXCOORD1;
};

struct VS_OUTPUT {
float4 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
float3 Position3D : TEXCOORD1;
float2 Weights : TEXCOORD2;
float3 Normal : TEXCOORD3;
float Depth : TEXCOORD4;
};

void Transform(in VS_INPUT Input, out VS_OUTPUT Output) {
Output.Position = mul(Input.Position, mul(World, mul(View, Projection)));
Output.Position3D = mul(Input.Position, World);
Output.TextureCoordinate = Input.TextureCoordinate;
Output.Normal = Input.Normal;
Output.Weights = Input.Weights;
Output.Depth = Output.Position.z / Output.Position.w;
}

struct PS_INPUT {
float3 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
float3 Position3D : TEXCOORD1;
float2 Weights : TEXCOORD2;
float3 Normal : TEXCOORD3;
float Depth : TEXCOORD4;
};

struct PS_OUTPUT {
float4 Color : COLOR0;
};

void Texture(in PS_INPUT Input, out PS_OUTPUT Output) {

float blendDistance = 0.96f;
float blendWidth = 0.040f;
float blendFactor = clamp((Input.Depth - blendDistance) / blendWidth, 0, 1);

float4 farColor;
farColor = tex2D(t0sampler, Input.TextureCoordinate * t0scale) * Input.Weights[0];
farColor += tex2D(t1sampler, Input.TextureCoordinate * t1scale) * Input.Weights[1];

float4 nearColor;
float2 nearTexCoord = Input.TextureCoordinate * 3;
nearColor = tex2D(t0sampler, nearTexCoord * t0scale) * Input.Weights[0];
nearColor += tex2D(t1sampler, nearTexCoord * t1scale) * Input.Weights[1];

float4 a = tex2D(t0sampler, Input.TextureCoordinate * t0scale);
float4 b = tex2D(t1sampler, Input.TextureCoordinate * t1scale);

float4 first = a * Input.Weights[0];
float4 second = b * Input.Weights[1];

float4 color = first + second;

Output.Color = color;

if (ShowGroundCursor) {
float cursorScale = 1.0;
float4 cursorColor = tex2D(CursorSampler, (Input.TextureCoordinate * (cursorScale / GroundCursorSize)) - (GroundCursorPosition.xz * (cursorScale / GroundCursorSize)) + 0.5);
Output.Color.rgb += cursorColor.rgb;
}

Output.Color.a = 1;

//Output.Color = lerp(nearColor, farColor, blendFactor);
}

void Wireframe(in VS_INPUT Input, out VS_OUTPUT Output) {
Output.Position = mul(Input.Position, mul(World, mul(View, Projection)));
Output.Position.y += 0.005;
}

float4 White() : COLOR0 {
return 1;
}

technique TransformTexture {
pass P0 {
VertexShader = compile vs_2_0 Transform();
PixelShader = compile ps_2_0 Texture();
}
}

technique TransformTextureWireframe {
pass P0 {
VertexShader = compile vs_2_0 Transform();
PixelShader = compile ps_2_0 Texture();
}
pass P1 {
VertexShader = compile vs_2_0 Wireframe();
PixelShader = compile ps_2_0 White();
FillMode = Wireframe;
}
}[/CODE]

Any help is appreciated! :D
Thanks in advance!
0

Share this post


Link to post
Share on other sites
The zoom-out behaviour suggests that when your cursor texture has been downsampled to generate lower MIP levels the yellow has bled to the edge of the image. When sampled close-up the high-res mip is sampled and looks OK, but from a distance the lower res mip is sampled and the yellow value at the edge is clamped indefinitely. You could generate the mip levels manually to ensure there's no bleeding to the edge, or use address mode set to 'border' and set the border colour to black.
2

Share this post


Link to post
Share on other sites
Thanks a bunch, border as address mode worked great! Altough, I'm a little interested in manual mipmapping, found nothing but automatic generation of mipmaps on google. How exactly do you manually create mipmaps?
0

Share this post


Link to post
Share on other sites
I believe the DirectX SDK download comes with a texture tool that can compile custom mipmap levels into a texture (I haven't used it for a long time, but check it out, it might do what you need.) Otherwise, Google. I just searched for "DirectX texture tool" and got a bunch of useful looking hits.
1

Share this post


Link to post
Share on other sites
Aha, I thought it had something to do with coding. But thanks a bunch, helped me tons! ;D
0

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