Sign in to follow this  
Plastinum Star

writing shader code in c++

Recommended Posts

Plastinum Star    122
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
Slaru    222
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

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