Skip to main content
gamedev.net
🔒 Locked

Creating a shaderdriven engine

Started by Metus 6 replies 1.8k views
Original Post
Metus
Metus
My old 3d engine had no shaderprogram support at all, so I decided to re-design it with shaders as the primary functionality. I've designed a simple shaderformat with focus on reuseability of shader elements

# Shader Default // name Default

	# Declaration VNT // name VNT (VertexNormalTexture)

		# Stream 0 Vertex
		# Stream 1 Normal
		# Stream 2 Texture

	# End Declaration

	# Material MyMaterial // name MyMaterial

		# Ambient  255 255 255 255
		# Diffuse  255 255 255 255
		# specular 255 255 255 255
		# Emissive 255 255 255 255

		# Pass 0 Streamsource 2 // fetch texcoord from stream 2
	
			# Texture 	"Texture.png" Texture // name Texture
	
			# Operation	ColorOperation
			# Arguments	Arg0 Arg1
	
		# End Pass

		# Pass 1 Streamsource 2 // fetch texcoord from stream 2

			# Texture	"Texture2.png" Texture2 // name Texture2
		
			# operation	ColorOperation
			# Arguments	Arg0 Arg1

			# Operation	ColorOperation
			# Arguments	Arg0 Arg1

		# End Pass

	# End Material

	# Program
		# "../program.fx" 	ShadowVolumeExtraction
		# "../program2.fx"	StencilShadow	
		# "../program3.fx"	PerPixelLighting
	# End Program

# End Shader
As you might notice, each subset except texture passes has an identifier assigned to it and here is where I can see some design flaws, can you? I'd appreciate if you could give me your opinions about my shader format and what I can improve
Ethereal
Promit
Promit
It seems decent. Two things:
1) CgFX and D3D FX might provide a good reference point to look at
2) Why does every line start with a #?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Tarviathun
Tarviathun
I concur with question number 2.
Metus
Metus
Ahh yes, the '#' is nothing more but an identifier-token so they do not play any particular role in the shader.
Second to that, I've decided to split the shader into multiple files, one file with the material properties and one file with declarations so the shader v2 looks like this:
# Shader Default	# Declaration 	VCNT1 	"../vcnt1.dec"   // def'ed externally	# Material	Default	"../default.mat" // def'ed externally	# Pass 0 		# Stream 	3		# Texture 	Default		"../texture.png"		# Operation 	ColorOp 		# Arguments 	Arg0 Arg1		# Pass 1 		# Stream 	3 		# Texture 	Default		"../texture2.png"		# Operation 	ColorOp 		# Arguments	Arg0 Arg1	# Program "ambient"	"../ambient.fx"  // d3d shader .fx file	# Program "specular"	"../specular.fx" // d3d shader .fx file# End Shader


Even this time the '#' is here for readability and as a token
Ethereal
Metus
Metus
Quote:
Original post by Anonymous Poster
Hmmm and what part of this can't HLSL and GLSL not handle?

I _don't_ think GLSL or HLSL can handle the shader reusability that i'm planning, however, I might be wrong
Ethereal
mitchw
mitchw
I agree, since you are going to use FX files for the program portion, then you might as well use it for the whole thing. It is flexible and the interfaces to interact with them via code are already there. You can compile on the file, include other files, etc. I'd take a look at them before developing your own.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.