Jump to content

Where has gone cube map shader code?


isidisi
 Share

Recommended Posts

I'm using Leadwerks Engine 2.28

 

It seems as if some versions ago there was a shader for cube maps. Now there's some code in mesh.vert shader, and no code in mesh.frag shader (only a uniform samplerCube LW_CUBEMAP declaration, but later this is not using in shader).

 

But if I download some versions older, I see there was some code related to cube maps in mesh.frag shader.

 

Was deleted by error?, is not needed to implement a cube map? What's the right way to do a cube map with current version of Leadwerks?

 

Thanks

Link to comment
Share on other sites

In the vertex shader, add:

varying vec3 modelnormal;

in the declarations before the code.

Then in the code, after "modelvertex = ":

modelnormal = nmat * gl_Normal;

 

Now go to the frag shader and extend the declaration of the cube map to this:

#ifdef LW_CUBEMAP
uniform samplerCube LW_CUBEMAP;
   uniform float cubemapIntensity = 1.0;
   varying vec3 modelnormal;
#endif

and extend:

//Diffuse
gl_FragData[0] = diffuse;

to

	//Diffuse
   #ifdef LW_CUBEMAP
       // Add cubemap
       diffuse = mix(diffuse,
                     textureCube(LW_CUBEMAP, 
                         reflect(normalize(cameraposition - vertexposition.xyz), normalize(modelnormal)) * vec3(1.0,-1.0,1.0)),
                     cubemapIntensity);
   #endif

gl_FragData[0] = diffuse;	

 

Now the only thing left to do is the declaration of an "intermediate" (= include) shader.

Mine looks like:

// Requires meshModelnormal.vert

#define LW_DIFFUSE texture0
#define LW_CUBEMAP texture3

Include "abstract::meshCubemap.frag"

And is called mesh_diffuse_cubemap.frag

 

This should do the trick (it does for 2.32, shouldn't be much different in 2.28).

Link to comment
Share on other sites

  • 2 weeks later...

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...