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

Generic Shader for DirectX 11?

3 posts in this topic

I'm working on loading different models with the Assimp library and was wondering if anyone could offer any help on a generic shader, if that is possible. I have very little shader experience and was wondering if there was a way to create a generic shader that my engine could load and use it to display different models. I was thinking it could take the vertices of the model I load, as well as the optional normals and texture coordinates and display the model with just ambient light. I know that for more advanced things I would need custom shaders, but I was hoping it would be possible to take 3D file that Assimp loads and just display the object in my scene with no extra effects. Is it possible for a generic shader like this, or would I need to create a shader for every file format I want to load and use that shader for each model I load. If any of my questions don't make much sense or aren't possible just let me know, I'm pretty new to the whole shader thing at the moment and haven't really found a resource like I'm describing. Any help would be greatly appreciated.

0

Share this post


Link to post
Share on other sites

I have no idea about HLSL specifics but as far as I know, anything teaching you a shading language will start with what you asked, what you need to display a model, any model. That includes the various spaces you're going to work on, shading language specifics and how to set up and upload the data to your GPU (which is often the most cumbersome work, at this level your shader is going to be a few lines long, ie, vertexPos = MVP * inputPos; and color = inputColor. thats it).

0

Share this post


Link to post
Share on other sites

This is the ImmediateGeometrySolid.hlsl file from the Hieroglyph 3 code repository:

 

//--------------------------------------------------------------------------------
// ImmediateGeometrySolid.hlsl
//
//
// Copyright (C) 2012 Jason Zink.  All rights reserved.
//--------------------------------------------------------------------------------

cbuffer WorldTransforms
{
	matrix WorldMatrix;
	matrix WorldViewProjMatrix;	
};

cbuffer ObjectMaterialInfo
{
	//float4 Ka;
	//float4 Kd;
	float4 Ks;
};

cbuffer PointLightInfo
{
	float4 LightPosition;
	float4 Ia;
	float4 Id;
	float4 Is;
};

cbuffer SceneInfo
{
	float4 ViewPosition;
};




struct VS_INPUT
{
	float3 position : POSITION;
	float3 normal   : NORMAL;
	float4 color    : COLOR;
};

struct VS_OUTPUT
{
	float4 position : SV_Position;
	float4 worldPos : POSITION;
	float3 normal   : NORMAL;
	float4 color    : COLOR;
};


VS_OUTPUT VSMAIN( in VS_INPUT input )
{
	VS_OUTPUT output;
	
	// Lighting calculations done in world space
	float4 P = mul( float4( input.position, 1.0f ), WorldMatrix );
	float3 N = mul( input.normal, (float3x3)WorldMatrix );

	output.position = mul( float4( input.position, 1.0f ), WorldViewProjMatrix );
	output.worldPos = P;	
	output.normal = N;
	output.color = input.color;
	
	return output;
}


float4 PSMAIN( in VS_OUTPUT input ) : SV_Target
{
	float3 P = input.worldPos.xyz;// / input.worldPos.w;
	float3 N = normalize( input.normal );
	float3 L = normalize( LightPosition.xyz - P.xyz );
	float3 V = normalize( ViewPosition.xyz - P.xyz );
	float3 H = normalize( L + V );

	float NdotL = dot( L, N );
	float4 ambientIntensity = input.color * Ia;
	float4 diffuseIntensity = input.color * Id * clamp( NdotL, 0.0f, 1.0f );
	float4 specularIntensity = Ks * Is * clamp( pow( abs( dot( H, N ) ), 64.0f ), 0.0f, 1.0f );

	float4 output = ambientIntensity;

	if ( NdotL > 0.0f ) {
		output += diffuseIntensity;
		output += specularIntensity;
	}

	output.a = 1.0f;


	return( output );
}


It has a specular and diffuse portion, but even if those end up contributing zero then you can still output something with the ambient term.  I hope that helps, and if you need guidance on how it works, feel free to ask!

0

Share this post


Link to post
Share on other sites

You can't really have a single generic vertex shader, since your vertex buffer(s) need to provide every element expected by the vertex shader. So if the vertex shader expects positions, normals, and texture coordinates, you need to provide all of those otherwise your call to create the input layout will fail. So you either need to use different shaders, or you would need to provide "dummy" vertex data if the element is present.

Anyway I would highly recommend that you check out BasicEffect from DirectXTK. It should do exactly what you want, and the library also provides a few other effects if you want to go a little more advanced. All of the source code is available as well, so you can see how they do it.

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