Jump to content
  • Advertisement
Sign in to follow this  
Plastinum Star

writing shader code in c++

This topic is 4959 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

when i wrote some shader code in my c++ program, i had to use so many quotation marks(see blow). This is really a tedious work. Any easy way? LPCSTR vscode = "matrix matWVP : register(c0);\n" "matrix matWorld : register(c4);\n" "float4 lightPos : register(c8);\n" "void vs_main(in float4 iPos : POSITION,\n" " in float3 iNormal : NORMAL,\n" " in float3 iTangent : TANGENT,\n" " in float2 iTexc : TEXCOORD0,\n" " out float4 oPos : POSITION,\n" " out float2 oTexc : TEXCOORD0,\n" " out float3 oLight : TEXCOORD1)\n" "{\n" " //output pos\n" " oPos = mul(iPos, matWVP);\n" " float3 worldNormal = normalize(mul(iNormal, (float3x3)matWorld));\n" " float3 worldTangent = normalize(mul(iTangent, (float3x3)matWorld));\n" " float3 worldBinormal = cross(worldNormal, worldTangent);\n" " float3x3 tangentBase = {worldTangent, worldBinormal, worldNormal};\n" " float3 light = normalize(lightPos - iPos.xyz);\n" " oLight = mul(tangentBase, -light);\n" " oTexc = iTexc;\n" "}";

Share this post


Link to post
Share on other sites
Advertisement
Tried writing it in an external file (ex. "shader.txt") or any file. Load that in as a string and then use that string. This way you don't need to recompile the whole program if you change your 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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!