PDA

View Full Version : CG 2 GLSL



Golgoth
06-24-2006, 06:58 PM
Hi all!

Trying to convert from cg to glsl... it is pretty straight foward but i have a doubt:

CG

float3x3 mv = float3x3(glstate.matrix.modelview[0]);
float4 pos = float4(IN.pos.x, IN.pos.y, IN.pos.z, 1.0);
OUT.vpos = mul(glstate.matrix.modelview[0], pos).xyz;
float3 tangent = mul(mv, IN.tangent.xyz);
float3 binormal = mul(mv, IN.binormal.xyz);
float3 normal = mul(mv, IN.normal);
float3x3 ts = float3x3(tangent, binormal, normal);
OUT.view = mul(ts, OUT.vpos);
OUT.light = mul(ts, lightpos.xyz - OUT.vpos);glsl

vec3 vpos = vec3(gl_ModelViewMatrix * gl_Vertex);
vec3 tangent = vec3(gl_NormalMatrix * tangent);
vec3 binormal = vec3(gl_NormalMatrix * binormal);
vec3 normal = gl_NormalMatrix * gl_Normal;
mat3 ts = mat3(tangent, binormal, normal);
vec3 view = normalize(ts * vpos);
vec3 light = normalize(ts * gl_LightSource[0].position.xyz - vpos);would light and view return the same in both shaders?

Corrail
06-24-2006, 07:04 PM
No, there's one mistake:


vec3 light = normalize(ts * gl_LightSource[0].position.xyz - vpos);should be

vec3 light = normalize(ts * (gl_LightSource[0].position.xyz - vpos));Then they are (except the normalize funktions) the same.

Golgoth
06-24-2006, 07:14 PM
Awesome!

thx Corrail! :)