Hi!

I need to convert Thermal Vision from GLSL to CG Shader who will help me?

void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
uniform sampler2D sceneTex; // 0
uniform float vx_offset;
void main()
{
vec2 uv = gl_TexCoord[0].xy;

vec3 tc = vec3(1.0, 0.0, 0.0);
if (uv.x < (vx_offset-0.005))
{
vec3 pixcol = texture2D(sceneTex, uv).rgb;
vec3 colors[3];
colors[0] = vec3(0.,0.,1.);
colors[1] = vec3(1.,1.,0.);
colors[2] = vec3(1.,0.,0.);
float lum = (pixcol.r+pixcol.g+pixcol.b)/3.;
int ix = (lum < 0.5)? 0:1;
tc = mix(colors[ix],colors[ix+1],(lum-float(ix)*0.5)/0.5);
}
else if (uv.x>=(vx_offset+0.005))
{
tc = texture2D(sceneTex, uv).rgb;
}
gl_FragColor = vec4(tc, 1.0);
}

Nobody Help me???

I’m still very much learning about shaders, but decided to post an answer as I’ve been looking to make my own thermal shader and was struggling to find any resources/references. Hopefully it helps someone in the future. Also was a good exercise to help me learn more about writing Cg.

For anyone interested this wikibook is an invaluable resource: Cg Programming/Unity - Wikibooks, open books for an open world

And for the orginal poster, if you do ever read this, you’re a lot more likely to get help when you at least make some effort on your own part. A lot easier to help someone who is almost there rather than someone who wants you to do all the work.

Anyway, here is my attempt:

``````Shader "Custom/ThermalVision" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_vxOffset ("Offset", Range(0,1)) = 1
}
Tags { "RenderType"="Opaque" }

Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"

struct v2f {
float4 pos:SV_POSITION;
float4 uv:TEXCOORD0;
};

sampler2D _MainTex;
float3 texCol;
float _vxOffset;

v2f vert(appdata_base input)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, input.vertex);
o.uv = input.texcoord;
return o;
}

float4 frag(v2f input):COLOR
{

if(input.uv.x < (_vxOffset - 0.005))
{
texCol = tex2D(_MainTex, float2(input.uv)).rgb;

float3 colors[3];
colors[0] = float3(0.0,0.0,1.0);
colors[1] = float3(1.0,1.0,0.0);
colors[2] = float3(1.0,0.0,0.0);

texCol = tex2D(_MainTex, float2(input.uv)).rgb;
float lum = Luminance(texCol.rgb);
float ix = (lum < 0.5) ? 0.0 : 1.0;
float3 range1 = lerp(colors[0], colors[1], (lum-ix*0.5)/0.5);
float3 range2 = lerp(colors[1], colors[2], (lum-ix*0.5)/0.5);

texCol = lerp (range1, range2, ix);
}
else if( input.uv.x >= (_vxOffset + 0.0005))
{
texCol = tex2D(_MainTex, float2(input.uv)).rgb;
}

return float4(texCol, 1.0);
}

ENDCG
}

}
FallBack "VertexLit"
}
``````