Jump to content
  • Advertisement
Sign in to follow this  
Enerjak

runtime shader code not compiling good. (need some help)

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, i've tried and tried but i can't seem to find anything wrong with this shader code:



static char* shaderCode[] =
{
{"float4x4 viewProjMatrix;"},
{"struct VS_OUT"},
{"{"},
{"float4 pos : POSITION0;"},
{"};"},
{"VS_OUT vs_main(float4 pos : POSITION)"},
{"{"},
{"VS_OUT pOut = (VS_OUT)0;"},
{"pOut.pos = mul(viewProjMatrix,pos);"},
{"return pOut;"},
{"};"},
{"float4 ps_main() : COLOR"},
{"{"},
{"return float4(1,0,0,1);"},
{"}"},
{"technique One"},
{"{"},
{"pass one"},
{"{"},
{"VertexShader = compile vs_2_0 vs_main();"},
{"PixelShader = compile ps_2_0 ps_main();"},
{"}"},
{"}"}
};


and when run i get this:

shaderError.png


not really sure what to do since from my side it looks fine, i don't know what the GPU sees

Share this post


Link to post
Share on other sites
Advertisement
Why is your shader code in an array of arrays of characters? How do you take that code and compile it?

Try this:static char* shaderCode =
"float4x4 viewProjMatrix;"
"struct VS_OUT"
"{"
" float4 pos : POSITION0;"
"};"
"VS_OUT vs_main(float4 pos : POSITION)"
"{"
" VS_OUT pOut = (VS_OUT)0;"
" pOut.pos = mul(viewProjMatrix,pos);"
" return pOut;"
"};"
"float4 ps_main() : COLOR"
"{"
" return float4(1,0,0,1);"
"}"
"technique One"
"{"
" pass one"
" {"
" VertexShader = compile vs_2_0 vs_main();"
" PixelShader = compile ps_2_0 ps_main();"
" }"
"}"
;

Share this post


Link to post
Share on other sites

Why is your shader code in an array of arrays of characters? How do you take that code and compile it?

Try this:static char* shaderCode =
"float4x4 viewProjMatrix;"
"struct VS_OUT"
"{"
" float4 pos : POSITION0;"
"};"
"VS_OUT vs_main(float4 pos : POSITION)"
"{"
" VS_OUT pOut = (VS_OUT)0;"
" pOut.pos = mul(viewProjMatrix,pos);"
" return pOut;"
"};"
"float4 ps_main() : COLOR"
"{"
" return float4(1,0,0,1);"
"}"
"technique One"
"{"
" pass one"
" {"
" VertexShader = compile vs_2_0 vs_main();"
" PixelShader = compile ps_2_0 ps_main();"
" }"
"}"
;





ID3DXBuffer* errors;
HRESULT hr = D3DXCreateEffect(Direct3DApp::getDevice9(),(void**)shaderCode,(UINT)(sizeof(shaderCode)),0,0,0,
0,&m_pEffect,&errors);



probably should of added that also........:P. i thought that would be a good way to do it.

Share this post


Link to post
Share on other sites
Hmm, i tried that but when ran it said there's a syntax error: it can't find identifier "floa" and i don't see any misspelled words in the code.

Share this post


Link to post
Share on other sites
That [font="Courier New"](void**)[/font] cast is very out of place. It is expecting a pointer to an array of characters, which you cast to a pointer-to-a-pointer? I'm guessing you added this in order to force your original array-of-arrays-of-characters version to compile?

The [font="Courier New"]sizeof[/font] is simply incorrect -- it's returning the size of the type that you're passing in, but what you really need to know is the number of characters in the array.

Your "[font="Lucida Console"]floa[/font]" error is because [font="Courier New"]sizeof(char*)[/font] is equal to 4 -- So you're telling D3DX that it should only read the first 4 characters of your shader code.


Try:
[font="Lucida Console"]HRESULT hr = D3DXCreateEffect(Direct3DApp::getDevice9(), shaderCode, strlen(shaderCode)+1,0,0,0,0,&m_pEffect,&errors);[/font]

Share this post


Link to post
Share on other sites

That [font="Courier New"](void**)[/font] cast is very out of place. It is expecting a pointer to an array of characters, which you cast to a pointer-to-a-pointer? I'm guessing you added this in order to force your original array-of-arrays-of-characters version to compile?

The [font="Courier New"]sizeof[/font] is simply incorrect -- it's returning the size of the type that you're passing in, but what you really need to know is the number of characters in the array.

Your "[font="Lucida Console"]floa[/font]" error is because [font="Courier New"]sizeof(char*)[/font] is equal to 4 -- So you're telling D3DX that it should only read the first 4 characters of your shader code.


Try:
[font="Lucida Console"]HRESULT hr = D3DXCreateEffect(Direct3DApp::getDevice9(), shaderCode, strlen(shaderCode)+1,0,0,0,0,&m_pEffect,&errors);[/font]



ok thank you, now i gotta figure out how to make it so i can progmatically add constanst and stuff, like you know create a function to allow people to creat their own shader variables in code and add them to the shader?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!