parallax mapping / bump mapping / phong combined

Return to Code Snippets

parallax mapping / bump mapping / phong combined

Postby miel » Sat Jun 10, 2006 8:59 pm

Played around a bit with CG again. Here's the product of my efforts.

NOTE: the shader takes 3 seperate textures; a regular texture, a normal map texure and a black and white heightfield map.

As always comments are very welcome.

Code: Select all

//Cg
//
//Cg profile arbvp1 arbfp1

void vshader(float4 vtx_position    : POSITION,
             float2 vtx_texcoord0   : TEXCOORD0,
             float3 vtx_tangent0,
             float3 vtx_binormal0,
             float3 vtx_normal      :   NORMAL,
             uniform float4 mspos_view,
             uniform float4 mspos_light,
             uniform float4x4 mat_modelproj,
        out float4 l_position : POSITION,
        out float2 l_texcoord0 : TEXCOORD0,
             out float3 l_eyeVec,
             out float3 l_lightVec)
{
   l_position=mul(mat_modelproj, vtx_position);
   l_texcoord0=vtx_texcoord0;
       
        float3 dirEye = (float3)mspos_view - (float3)vtx_position;
        l_eyeVec.x = dot(vtx_tangent0, dirEye);
        l_eyeVec.y = dot(vtx_binormal0, dirEye);
        l_eyeVec.z = dot(vtx_normal, dirEye);
       
        float3 dirLight = (float3)mspos_light - (float3)vtx_position;
        l_lightVec.x = dot(vtx_tangent0, dirLight);
        l_lightVec.y = dot(vtx_binormal0, dirLight);
        l_lightVec.z = dot(vtx_normal, dirLight);
       
}

void fshader(float2 l_texcoord0 : TEXCOORD0,
             float3 l_eyeVec,
             float3 l_lightVec,
               uniform sampler2D tex_0,
             uniform sampler2D tex_0_n,
        uniform sampler2D tex_0_h,
        out float4 o_color : COLOR)
{
    float3 eyeT = normalize(l_eyeVec);
    float3 lightT = normalize(l_lightVec);
   
    float4 offset = tex2D(tex_0_h, l_texcoord0);
    offset = offset * 0.04 - 0.02;
    float2 texCoords = offset.xy * eyeT.xy + l_texcoord0;
   
   

float4 normalMap = tex2D(tex_0_n, texCoords) * 2.0 - float4(1.0,
1.0, 1.0, 1.0);

float4 tex = tex2D(tex_0, texCoords);

float3 halfAngle = normalize(normalize(l_lightVec) + normalize(l_eyeVec) / 2.0);
float4 l_brite = pow(dot((float3)normalMap, halfAngle), 60.0);
float lightProd = saturate(dot((float3)normalMap, halfAngle)+0.3);

o_color= (float4(0.2, 0.25, 0.2, 1.0) + l_brite) * tex * lightProd;




}


Last edited by miel on Thu Jun 15, 2006 4:04 am, edited 1 time in total.
miel
 
Posts: 45
Joined: Tue Jan 17, 2006 10:20 am

Postby Josh Yelon » Sun Jun 11, 2006 9:42 am

Wow, could this be integrated directly into the "normal mapping" sample program? I'd like to distribute it with panda.
Josh Yelon, Teacher, Carnegie Mellon Entertainment Technology Center
Josh Yelon
 
Posts: 1360
Joined: Wed Mar 30, 2005 8:30 pm

Postby miel » Mon Jun 12, 2006 4:58 am

I just finished the code, it's your own normalMap tutorial combined with my parallax effect. You want it on this forum or should I email it?

greets,

Miel
miel
 
Posts: 45
Joined: Tue Jan 17, 2006 10:20 am

Postby Josh Yelon » Mon Jun 12, 2006 4:03 pm

If you could post a zipfile on a webserver somewhere, that would work. Then, you could put a link here.

Or, you could just email the zipfile to me: jyelon@andrew.cmu.edu.
Josh Yelon, Teacher, Carnegie Mellon Entertainment Technology Center
Josh Yelon
 
Posts: 1360
Joined: Wed Mar 30, 2005 8:30 pm

Postby miel » Thu Jun 15, 2006 4:04 am

Did you get my email?
miel
 
Posts: 45
Joined: Tue Jan 17, 2006 10:20 am

Postby rdb » Tue Jun 02, 2009 1:54 pm

Can you forward said e-mail to me? (My e-mail address is available through the forum software.)
I prefer e-mail over PM
rdb
 
Posts: 8548
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest