Showing results for 
Search instead for 
Did you mean: 

OVR SDK: How to use a custom shader for Model::Fill?

Level 7
Hi guys, I writing a C++ program that reads World of Warcraft data and draws it in VR. I'm not using any engines like Unity or Unreal but I'm modifying OculusWorldDemo provided with the SDK to achieve my purpose. (Actually I did it in Unity but I find the result waaay too slow and now I'm trying with the SDK).

I'm at the part with terrain geometry and I need to mix up to 4 textures with a 5th one that contains alpha values for the 4 textures. So I wrote a .shader in Unity earlier but now I need to translate it in the SDK.

So far all I can see is I only have access to pRender->LoadBuiltinShader()?

Ptr<ShaderFill> shader = *new ShaderFill(*pRender->CreateShaderSet());
shader->GetShaders()->SetShader(pRender->LoadBuiltinShader(Shader_Vertex, VShader_MVP));

//now I need to set my own fragment shader
Ptr<Shader> fragshader = *new Shader(Shader_Fragment);
My fragment shader is going to look like that:

Texture2D Texture[5] : register(t0);
SamplerState Linear[5]: register(s0);

struct Varyings
float4 Position : SV_Position;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
float2 TexCoord1 : TEXCOORD1;

float4 main(in Varyings ov) : SV_Target
float4 c0 = Texture[0].Sample(Linear[0], ov.TexCoord);
float4 c1 = Texture[1].Sample(Linear[1], ov.TexCoord);
float4 c2 = Texture[2].Sample(Linear[2], ov.TexCoord);
float4 c3 = Texture[3].Sample(Linear[3], ov.TexCoord);
float4 a = Texture[4].Sample(Linear[4], ov.TexCoord1);
float4 col = c0*(1.0f-a.r-a.g-a.b) + c1*a.r + c2*a.g + c3*a.b;
return col;

So my question is how do I compile that fragment shader and put it into fragshader?