Jump to content
  • Advertisement
Sign in to follow this  

multiple passes in opengl

This topic is 4255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am not sure if I do post on the correct board, but i think it's a basic question. I have a model which is rendered with an uv-mapped texture. an I am using a Cg fragment program to do this mapping (via sample2D). Now I want to add reflection to it, using a cubemap (sampleCube) but as soon as I access more than one of these 2 samples.. I get as result only one of the two textures mapped. (I am using cgGLGetLatestProfile(CG_GL_FRAGMENT); and get fp40 or sth. like that...) I am pretty sure that I've read sth. like, not to access more than one sample in a pass. So do I need multipass rendering? And if yes, how do I do it? Is there a good article about it (using OpenGL and Cg) on the web?

Share this post

Link to post
Share on other sites
You shouldn't need multiple passes. Using either fixed function multitexturing, or a shader, should allow you to blend the base texture and the reflection texture.

Posting your shader code and the relevant program code would be helpful.

PS - there is an opengl forum.

Share this post

Link to post
Share on other sites

void main_erectron_vp(
float4 position : POSITION,
float2 texCoord0 : TEXCOORD0,
float3 normal : NORMAL,

out float4 oPosition : POSITION,
out float2 uv0 : TEXCOORD0,
out float3 objectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2,
out float oDist : TEXCOORD3,
out float3 R : TEXCOORD4,
uniform float3 eyePositionW,
uniform float4x4 modelToWorld,
uniform float4x4 modelViewProj)

oPosition = mul(modelViewProj, position);
uv0 = texCoord0;
objectPos = position.xyz;
oDist = length(position.xz);
oNormal = normal;

float3 positionW = mul(modelToWorld, position).xyz;
float3 N = mul((float3x3)modelToWorld,normal);
N = normalize(N);

float3 I = positionW-eyePositionW;

R = reflect(I,N);

void main_erectron_fp(
float3 uv0 : TEXCOORD0,
float4 position: TEXCOORD1,
float4 rPosition: POSITION,
float3 normal: TEXCOORD2,
float dist: TEXCOORD3,
float3 R: TEXCOORD4,
out float4 oColor: COLOR,

uniform sampler2D texture: TEXUNIT0,
uniform samplerCUBE envMap: TEXUNIT1,
uniform float3 globalAmbient,
uniform float3 lightColor,
uniform float3 lightPosition,
uniform float3 eyePosition,
uniform float3 Ke,
uniform float3 Ka,
uniform float3 Kd,
uniform float3 Ks,
uniform float shininess,
uniform float heatFactor
// Just sample texture using supplied UV
float4 texColor1 = tex2D(texture, uv0);
float4 texColor2 = texCUBE(envMap,R);
float4 texColor = lerp(textColor1,texColor2,0.5);

float3 P = position.xyz;
float3 N = normalize(normal);

float3 emissive = Ke;

float3 ambient = Ka * globalAmbient;

// Compute the diffuse term
float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(L, N), 0);
float3 diffuse = Kd * lightColor * diffuseLight;

// Compute the specular term
float3 V = normalize(eyePosition - P);
float3 H = normalize(L + V);
float specularLight = pow(max(dot(H, N), 0), shininess);
if (diffuseLight <= 0) specularLight = 0;
float3 specular = Ks * lightColor * specularLight;
float4 color;
color.xyz = (emissive + ambient + diffuse + specular)*1.5;
color.w = 1;

oColor = lerp(color,texColor,0.5);
oColor = lerp(float4(1.0,0.0,0.0,1.0)*heatFactor,oColor,abs(dist/11));
oColor += lerp(float4(1.0,0.0,0.0,1.0)*heatFactor,float4(0.0,0.0,0.0,1.0),abs(dist/11));

Share this post

Link to post
Share on other sites
oh sorry forgot to add text ;)
yes well these are the vertex and fragment shader i use... (single they work.. means if i am using just texColor1 or just texColor2...)

(the code is mainly copy pasted from the Cg Tutorial actually....

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!