• 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

Hold Your Hats, Some Cool Lightning Need Container Help.?

1 post in this topic

Hi again.


I've updated some code, I've added a rotate function and the draw gs to out put real cubes based on a direction and size of the lightning segment.


the rotate function in hlsl

//this will rotate the point passed in and return the rotated point
//pass in x y and z rotaion angles in  radians
float3 Rotate(float3 v1, float rotx, float roty, float rotz)
	float4x4 rotateX = { 1.0, 0.0, 0.0, 0.0,                
						0.0, cos(rotx), -sin(rotx), 0.0,                
						0.0, sin(rotx), cos(rotx), 0.0,                
						0.0, 0.0, 0.0, 1.0 };

	float4x4 rotateY = { cos(roty), 0.0, sin(roty), 0.0,               
					0.0, 1.0, 0.0, 0.0,                
					-sin(roty), 0.0, cos(roty), 0.0,               
					 0.0, 0.0, 0.0, 1.0   };

	float4x4 rotateZ = { cos(rotz), -sin(rotz), 0.0, 0.0,                
					sin(rotz), cos(rotz), 0.0, 0.0,                
					0.0, 0.0, 1.0, 0.0,                
					0.0, 0.0, 0.0, 1.0   };

	float4x4 TransformationMatrix =    

float4x4 final = mul(rotateX , rotateY);// * rotateZ * TransformationMatrix;

final = mul(final, rotateZ);

final = mul(final, TransformationMatrix);

float3 rt = float3(final[3].x, final[3].y, final[3].z);
return rt;

}//end Rotate

and the new geometry shader that extrudes the shape based on the direction the lightning segment is.

I'm using the 4 points to create a quad, the code also has triangles. but im using the quads it out put is 24 compared to 36.

there is no change between the frame time doing it iether way.

//going to greate a face that faces the direction and then extrude it by its length
// The draw GS just expandsa quad facing the direction post and target form
void Draw2GS(point VS_OUT gIn[1], 
            inout TriangleStream<GS_OUT> triStream)
	// do not draw emitter particles.
	//if( gIn[0].type != PT_EMITTER )
float4x4 WVP = gViewProj;//mul(W, gViewProj);
		// Compute 4 triangle strip vertices (quad) in local space.
		// The quad faces down the direction start and end form.
//holds triangles for the 6 faces
		//float4 v[36];
		//we make this shape here sortof
		//      ____________
		//  4  /\  1 faces  \
		//    /  \___________\
		//    \  /   2       /
		//   3 \/___________/
		//we only can have 1 size ore we will ned to keep switch whats size is where
		//we have a start and a target position
		//gEmitDirW is a vector3 in 3d world coords and now a direction in this shader its a target
		//if its a SEGMENT_TYPE_SPLITEND the growamount is not added
		float addsize = ggrowamount;
		if(gIn[0].type == SEGMENT_TYPE_SPLITEND)
			addsize = ggrowamount * 0.5;//we don't want to add extra glow
		float wdthp		= gIn[0].sizeW.x + addsize;//gParticleWidth ;//starting points width 
		float3 target	= gIn[0].posT;//gEmitDirW;
		float3 pos		= gIn[0].posW;//gEmitPosW;
//the face vertex points defines our cube
//float3 p1, p2, p3, p4, p5, p6, p7, p8;
float3 vetexdata[8];

//we need to get the direction we are heading
float3 dir = normalize(target - pos);

//create a up vector
float3 up = Perpendicular(dir);//float3(0.0, 1.0, 0.0);//

float halfsize = wdthp * 0.5;

//add a bit to the length to reduce the join not being linked to the next segment
float extrudelength = length(target - pos) + halfsize;

// todo: handle case when (dir == up) done with the perpendicular
float3 o1 = normalize(cross(dir, up)) * halfsize;
float3 o2 = normalize(cross(o1, dir)) * halfsize;

//this is the first face of the cube starting at our position facing the direction we want to extrude in
vetexdata[0] = pos + o1 + o2;
vetexdata[1] = pos + o1 - o2;
vetexdata[2] = pos - o1 - o2;
vetexdata[3] = pos - o1 + o2;

//the second face at the target location
vetexdata[4] = vetexdata[0] + dir* extrudelength;
vetexdata[5] = vetexdata[1] + dir* extrudelength;
vetexdata[6] = vetexdata[2] + dir* extrudelength;
vetexdata[7] = vetexdata[3] + dir* extrudelength;

//the above defines our cubes face vertices now we need to lay them out
//to form eighter the 4 faces with no end caps or the whole cube with end caps

//the easyest way I think is to make a index list with 3 index for a triangle
static int indices[36]={
        // Front face
        // Back face
        // Left face
        // Right face
        // Top face
        // Bottom face

static float4 c[6] =


//cheaper not that its a frame hit any way they run the same
static int faces[24] = {

// Front edges

// Back edges

// Left edges

// Right edges

// Top edges

// Bottom edges
// Front face		
		//make a quad from pos to face target
		v[0] = float4(vetexdata[0], 1.0f);
		v[1] = float4(vetexdata[1], 1.0f);
		v[2] = float4(vetexdata[2], 1.0f);

		v[3] = float4(vetexdata[0], 1.0f);
		v[4] = float4(vetexdata[2], 1.0f);
		v[5] = float4(vetexdata[3], 1.0f);

		v[6] = float4(vetexdata[4], 1.0f);
		v[7] = float4(vetexdata[0], 1.0f);
		v[8] = float4(vetexdata[3], 1.0f);

		v[9] = float4(vetexdata[4], 1.0f);
		v[10] = float4(vetexdata[3], 1.0f);
		v[11] = float4(vetexdata[7], 1.0f);

//left face 
		v[12] = float4(vetexdata[4], 1.0f);
		v[13] = float4(vetexdata[5], 1.0f);
		v[14] = float4(vetexdata[1], 1.0f);

		v[15] = float4(vetexdata[4], 1.0f);
		v[16] = float4(vetexdata[1], 1.0f);
		v[17] = float4(vetexdata[0], 1.0f);

 // Back face
		v[18] = float4(vetexdata[4], 1.0f);
		v[19] = float4(vetexdata[6], 1.0f);
		v[20] = float4(vetexdata[5], 1.0f);

		v[21] = float4(vetexdata[4], 1.0f);
		v[22] = float4(vetexdata[7], 1.0f);
		v[23] = float4(vetexdata[6], 1.0f);

 // Right face
		v[24] = float4(vetexdata[3], 1.0f);
		v[25] = float4(vetexdata[2], 1.0f);
		v[26] = float4(vetexdata[6], 1.0f);

		v[27] = float4(vetexdata[3], 1.0f);
		v[28] = float4(vetexdata[6], 1.0f);
		v[29] = float4(vetexdata[7], 1.0f);
 // Top face
		v[30] = float4(vetexdata[1], 1.0f);
		v[31] = float4(vetexdata[5], 1.0f);
		v[32] = float4(vetexdata[6], 1.0f);

		v[33] = float4(vetexdata[1], 1.0f);
		v[34] = float4(vetexdata[6], 1.0f);
		v[35] = float4(vetexdata[2], 1.0f);

		// Transform quad vertices to world space and output 
		// them as a triangle strip.
		GS_OUT gOut;
//int colourele = 0;//1 colour each face
		int facecount = 0;//we resetstrip at 4 1 face
		for(int i = 0; i < 24; i++)
			gOut.posH  = mul(float4(vetexdata[faces[i]], 1.0f), WVP);//v[i], WVP);
			//gOut.texC  = float2(0.0, 0.0);//gQuadTexC[i];
			//gOut.color = c[colourele];//gIn[0].color;
			//gOut.arrayid = 0;//gIn[0].arrayid;


		if(facecount >=4)
			//if(colourele >=6)
			//	colourele = 5;
			//1 face 
			facecount = 0;
		}//end 1 quad

		}//end all

	}//en not emmitor


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