Is this OSL?

I was looking through the shader files of the Dolphin Wii emulator, and came across these two shaders:


// Omega's 3D Stereoscopic filtering (Amber/Blue)
// TODO: Need depth info!


uniform samplerRECT samp0 : register(s0);


void main(out float4 ocol0 : COLOR0, in float2 uv0 : TEXCOORD0)
{
  float4 c0 = texRECT(samp0, uv0).rgba; // Source Color
  float sep = 5;
  float red   = c0.r;
  float green = c0.g;
  float blue  = c0.b;


  // Left Eye (Amber)
  float4 c2 = texRECT(samp0, uv0 + float2(sep,0)).rgba;
  float amber = (c2.r + c2.g) / 2;
  red = max(c0.r, amber);
  green = max(c0.g, amber);


  // Right Eye (Blue)
  float4 c1 = texRECT(samp0, uv0 + float2(-sep,0)).rgba;
  blue = max(c0.b, c1.b);


  
  ocol0 = float4(red, green, blue, c0.a);
}


And this one:


uniform samplerRECT samp0 : register(s0);


void main(out float4 ocol0 : COLOR0, in float2 uv0 : TEXCOORD0)
{
  float4 c0 = texRECT(samp0, uv0).rgba;
  float red   = 0.0;
  float blue  = 0.0;


  if (c0.r < 0.35 || c0.b > 0.5)
  {
	red = c0.g + c0.b;
  }
  else
  {
    red = c0.g + c0.b;
	blue = c0.r + c0.b;
  }
  
  ocol0 = float4(red, 0.0, blue, 1.0);
}


Are these Open Shading Language? If yes, how can I use them in Blender? If not, how can they be translated?

OSL is for Blender Cycles Renderer, not for the Game Engine. You want to find GLSL shaders.

Okay. Is it GLSL?

No, it isn’t. I guess it is indeed OSL, because I can see that it isn’t GLSL. There are some things (like the float4 datatype in the first shader) that aren’t available in GLSL, and you don’t have function arguments for the main function for GLSL shaders in the BGE (if I recall). You would do well to look at some working GLSL shaders for Blender and some GLSL shader tutorials to see how to adapt it, as the core of the shaders are just a few mathematic function calls.

My guess is this is either HLSL or Cg (the two are very similar). This shouldn’t be hard to convert to GLSL if you are familiar with GLSL. The float4 and float2 data types are vec4 and vec2 in GLSL. Instead of a samplerRECT you could probably get away with just a sampler2D in GLSL, and use texture2D as the look up function. From there it is just a matter of dealing with the input and outputs to the fragment shader. If you don’t know how input and output for a shader works, it would be best to learn some basic GLSL before translating these shaders. That basic knowledge can also help you when dealing with BGE specific APIs.