Jump to content

Loading Lightmap via script


Michael Betke
 Share

Recommended Posts

Is is possible with a .lua script to load and display a second UV-channel which contains a lightmap?

I have an object. UV1 is my texture. UV5 are my lightmap UVs.

The Lightmap is a huge texture for a bunch of objects whith baked shaodws.

 

I now want to blend it over my UV1.

 

Is there a way with .lua so I can use it for every level I do?

Pure3d Visualizations Germany - digital essences

AAA 3D Model Shop specialized on nature and environments

Link to comment
Share on other sites

Thanks for your reply.

In the old LE forums a guy posted this:

 

(This is the .vert shader?!)

uniform mat4 MeshMatrix;

varying   vec3 Normal;
varying   vec4 pos;
varying   vec2 texCoord0;
varying   vec2 texCoord1;

#ifdef BUMPMAP
  varying vec3 bump_t;
  varying vec3 bump_b;
#endif

void main(void)
{

  gl_FrontColor = gl_Color;

  mat3 nmat = mat3(MeshMatrix[0].xyz,MeshMatrix[1].xyz,MeshMatrix[2].xyz);   

  Normal=nmat*gl_Normal;

  pos=MeshMatrix*gl_Vertex;   

  texCoord0=gl_MultiTexCoord0.xy;
  texCoord1=gl_MultiTexCoord1.xy;

  #ifdef BUMPMAP
     bump_t = nmat * gl_MultiTexCoord2.xyz;
     bump_b = nmat * gl_MultiTexCoord3.xyz;
  #endif

  gl_Position = gl_ModelViewProjectionMatrix * pos;
}

 

And this as a .frag

uniform vec3 CameraPosition;

varying   vec3   Normal;
varying   vec4   pos;
varying   vec2   texCoord0;
varying   vec2   texCoord1;

#ifdef DIFFUSEMAP
  uniform   sampler2D   DIFFUSEMAP;
#endif

#ifdef BUMPMAP
  uniform   sampler2D   BUMPMAP;
  varying   vec3      bump_t;
  varying   vec3      bump_b;
#endif

#ifdef LIGHTMAP
  uniform   sampler2D   LIGHTMAP;
#endif

void main(void)
{

  #ifdef BUMPMAP
     vec3   nNormal   = texture2D ( BUMPMAP, texCoord0 ).rgb * 2.0 - vec3 ( 1.0 );
  #else
     vec3   nNormal      = normalize( Normal );
  #endif

  vec3   CamVector   = normalize( CameraPosition - pos.xyz );
  vec3   LightVector;
  vec3    HalfVector;

  #ifdef DIFFUSEMAP
     vec3   color      = texture2D(DIFFUSEMAP,texCoord0).rgb;
  #else
     vec3   color      = vec3(1.0,1.0,1.0);
  #endif   

  vec3   diff      = vec3(AMBIENT);   
  float   spec      = 0.0;   
  float   SHINE      = 50.0;   
  float   SHINESTRENGHT   = 0.2;   
  float   dist;   

  #ifdef LIGHTMAP
     diff      = texture2D(LIGHTMAP,texCoord1).rgb;
  #endif

  #ifdef LO1pos

     LightVector   = normalize(LO1pos-pos.xyz);
     HalfVector   = normalize(CamVector+LightVector);
     dist      = length(LO1pos-pos.xyz);

     #ifdef BUMPMAP
        vec3 lt = vec3 ( dot ( LightVector, bump_t ), dot ( LightVector, bump_b ), dot ( LightVector, Normal ) );
        vec3 ht = vec3 ( dot ( HalfVector, bump_t ), dot ( HalfVector, bump_b ), dot ( HalfVector, Normal ) );

        #ifndef LIGHTMAP
           if (dist<LO1range)
           {
              diff   = vec3(max ( (1.0-dist/LO1range)*dot ( nNormal, lt ), AMBIENT ));
           }
        #endif
        spec      = pow ( max ( dot ( nNormal, ht ), 0.0 ), SHINE );

     #else
        #ifndef LIGHTMAP
           if (dist<LO1range)
           {
              diff   = vec3(max ( (1.0-dist/LO1range)*dot ( nNormal, LightVector ), AMBIENT ));
           }
        #endif
        spec      = pow ( max ( dot ( nNormal, HalfVector ), 0.0 ), SHINE );
     #endif

  #endif

  float   shine=min(SHINESTRENGHT * spec,1.0);
  gl_FragColor = vec4 ( color * diff + vec3 ( shine ), 1.0 );
}

 

Taken from this thread: http://www.leadwerks.com/forum/viewtopic.php?f=6&t=4628&p=40933&hilit=lightmap#p40933

 

So what are the steps I have to do?

 

In 3dmax:

rendering my lightmap and exporting it with the model

 

In LE:

-saving above shaders as .vert and .frag

-doing a material using these new shaders for my lightmap textre (?)

- then ??

Pure3d Visualizations Germany - digital essences

AAA 3D Model Shop specialized on nature and environments

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...