🔒 Locked
Engine Designed around shaders
Advertisement
Original Post
I want my engine to be based on shaders. I want to(should I?) eliminate fixed function all togeather. Humans have a tendancy to put off advancement as long as possible(x86,32bit cpu,dos progs <-sigh). My targeted systems will be 1.5ghz+, 256mb ram, video card with vs&ps(1.0 or 2.0 <-me no no) minimal. What do you think? Any one know any good tutorials, tech docs about shaders to get me started?
Uh, that's fine. Many engines these days use a programmable-pipeline renderpath exclusively, if for no other reason than because it's simpler. In terms of documentation, the documentation for your chosen API will be the most useful for you (since the engine itself won't tend to care about the particular visual effects being implemented).
Well, seeing how my project is mainly just a hobby thing, I found that throwing out fixed function simplified my code a lot. It might be possible to use vertex shaders for per vertex lighting (which should work on old cards too).
If you want to be serious, and have fast rendering - drop DX effects, they are slow, and they are black-box. And perhabs - too general.
Writing something that can compile HLSL from a file, and produce one PS&VS is very easy - maybe just adding a support for describing render states would be helpful, and that's it.
Shader based - that alone means nothing.
What decisions would you made about materials, about lighting & shadowing?
Can a shader be plugged in the system, and somehow magically all will work...?
(there are ways to do that, but at a cost, of course...).
How these shaders will be managed, how will be bind to instances (shader variables management) and how will scale to meet the requirements of the scene - number and type of lights, fog, shadows, etc.
That's a whole lot to be thinking of.
Dropping FFP is just a very tiny step. Drop it. We dropped it, and I don't sorry even a bit...
But ps11 is still viable option. :)
Writing something that can compile HLSL from a file, and produce one PS&VS is very easy - maybe just adding a support for describing render states would be helpful, and that's it.
Shader based - that alone means nothing.
What decisions would you made about materials, about lighting & shadowing?
Can a shader be plugged in the system, and somehow magically all will work...?
(there are ways to do that, but at a cost, of course...).
How these shaders will be managed, how will be bind to instances (shader variables management) and how will scale to meet the requirements of the scene - number and type of lights, fog, shadows, etc.
That's a whole lot to be thinking of.
Dropping FFP is just a very tiny step. Drop it. We dropped it, and I don't sorry even a bit...
But ps11 is still viable option. :)
I chose to go with just using plain HLSL shaders in txt files to begin with, as I didn't want to have all the overhead of effect files confusing me at first.
The DirectX Docs are pretty good for information about HLSL shaders, but the info you need to simple get a "hello world" shader working, is spread out quite a bit.
I'll try to put here all the base code you might need.
The DirectX Docs are pretty good for information about HLSL shaders, but the info you need to simple get a "hello world" shader working, is spread out quite a bit.
I'll try to put here all the base code you might need.
//vertex shader filefloat4x4 worldViewProj;float4 vLight;struct VS_OUTPUT{ float4 Pos : POSITION; float4 Diff : COLOR0; float2 Tex1 : TEXCOORD0; float2 Tex2 : TEXCOORD1;};VS_OUTPUT vs_main(float4 inPos : POSITION, float3 inNormal : NORMAL, float2 Tex1 : TEXCOORD0, float2 Tex2 : TEXCOORD1 ){ VS_OUTPUT Out; Out.Pos = mul(inPos, worldViewProj); Out.Diff = -dot( inNormal, vLight ); Out.Diff = saturate(Out.Diff); Out.Diff += 0.2; Out.Tex1 = Tex1; Out.Tex2 = Tex2; return Out;}//pixel shader file float4 ps_main( float4 inDiffuse: COLOR0, float2 inTx1: TEXCOORD0, float2 inTx2: TEXCOORD1 ) : COLOR0{ float4 outColor = 0; outColor.r = 1; return outColor;}//in your headerIDirect3DPixelShader9* mlpSplatPixelShader;IDirect3DVertexShader9* mlpVertexShader;ID3DXConstantTable* mpVSConstantTable;//in your cpp, when you initialize D3DCAPS9 caps; mlpD3DDevice->GetDeviceCaps(∩︀); ID3DXBuffer* pShader = NULL; HRESULT hr; //vertex shader if(caps.VertexShaderVersion >= D3DVS_VERSION(1, 1)) { // Compile the vertex shader hr = D3DXCompileShaderFromFile( "GraphicsEngine/shaders/mapHLSL.vsh", NULL, NULL, "vs_main", "vs_1_1", /*D3DXSHADER_DEBUG*/D3DXSHADER_SKIPVALIDATION, &pShader, NULL, // error messages &mpVSConstantTable ); if( FAILED(hr) ) { LOG("Error! Failed compiling vertex shader from file"); SafeRelease(pShader); SafeRelease(mpVSConstantTable); return hr; } // Create the vertex shader hr = mlpD3DDevice->CreateVertexShader( (DWORD*)pShader->GetBufferPointer(), &mlpVertexShader ); SafeRelease(pShader); if( FAILED(hr) ) { SafeRelease(mlpVertexShader); SafeRelease(mpVSConstantTable); return hr; } } else { LOG("Error! Video card does not support Vertex Shader 1.1 "); return E_FAIL; } //pixel shader if(caps.PixelShaderVersion >= D3DPS_VERSION(1, 4)) { hr = D3DXCompileShaderFromFile( "GraphicsEngine/shaders/mapHLSL.psh", NULL, NULL, "ps_main", "ps_1_4", D3DXSHADER_SKIPVALIDATION, &pShader, NULL, NULL ); if(FAILED(hr)) { LOG("Error! Failed compiling pixel shader from file"); SafeRelease(pShader); return hr; } //create the pixel shader hr = mlpD3DDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &mlpSplatPixelShader); SafeRelease(pShader); if( FAILED(hr) ) { SafeRelease(mlpSplatPixelShader); return hr; } } else { LOG("Error! Video card does not support Pixel Shader 1.4 "); return E_FAIL; }//in your cpp, just before rendering mlpD3DDevice->SetVertexShader(mlpVertexShader); mlpD3DDevice->SetPixelShader(mlpSplatPixelShader); matViewProj = matView * matProj; D3DXHANDLE hMatrixConstantHandle = mpVSConstantTable->GetConstantByName( NULL, "worldViewProj" ); mpVSConstantTable->SetMatrix( mlpD3DDevice, hMatrixConstantHandle, &matViewProj ); //set the sunlight D3DXHANDLE hLightConstantHandle = mpVSConstantTable->GetConstantByName( NULL, "vLight" ); mpVSConstantTable->SetVector( mlpD3DDevice, hLightConstantHandle, &sunLight );
Quote:
Original post by Zemedelec
drop DX effects, they are slow
Not true anymore. They got serious speed boost in Summer 2004 SDK update.
Quote:
Original post by Anonymous Poster
Material/shader implementation
Shader system questions
Those are very good threads, and I recommend you to read them both. Although the shader system described in those threads is quite complicated, it can give you some ideas.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement