Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/vrmedia2/public_html/forums/Sources/Load.php(225) : runtime-created function on line 3
how to implement cube map
forums.vrmedia.it
Welcome, Guest. Please login or register.
March 27, 2017, 07:23:23 PM

Login with username, password and session length
Search:     Advanced search
SMF - Just Installed
1444 Posts in 465 Topics by 370 Members
Latest Member: landiandrea
* Home Help Search Login Register
+  forums.vrmedia.it
|-+  Programming with XVR
| |-+  Shaders Programming (Moderator: capedica)
| | |-+  how to implement cube map
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: how to implement cube map  (Read 17093 times)
Fu
Jr. Member
**
Offline Offline

Posts: 11


« on: December 28, 2008, 07:27:40 AM »

how to implement cube map. i see there is a hdr cube map eample. but i don't know how to get .hdr file
Logged
ilmale
Global Moderator
Hero Member
*****
Offline Offline

Posts: 140


lrosario80
Email
« Reply #1 on: December 30, 2008, 07:36:19 PM »

You can read cubemap like normal texture with CVmTexture but the texture must be in DDS format.

To generate DDS cubemap you can use the CubeMapGen (by ATI/AMD)
http://developer.amd.com/gpu/cubemapgen/pages/default.aspx
The DDS is the only format that support Cubemap.

The other way is to load 6 HDR image as shown in the HDR example.

Another way is to do it with a library..  Lips Sealed
Logged

~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~
Fu
Jr. Member
**
Offline Offline

Posts: 11


« Reply #2 on: December 31, 2008, 07:47:17 PM »

Hi,

Thanks for the reply. But we still pazzled by how to implement cube map in XVR script. can you show some sample code?

Many thanks
Logged
Fu
Jr. Member
**
Offline Offline

Posts: 11


« Reply #3 on: December 31, 2008, 07:55:29 PM »

can you show me some DDS cube map sample code. can you also tell me which function is to inform the engine implementing cube map

many thanks
Logged
ilmale
Global Moderator
Hero Member
*****
Offline Offline

Posts: 140


lrosario80
Email
« Reply #4 on: January 03, 2009, 03:38:40 AM »

Cubemapping is used in a lot of cases, the main one are...
a-skybox
b-specular reflex
c-diffusive illumination

Here the three cases
I have used some simple shader but you can create the same effect with fixed pipeline.
Code:
#include <Script3d.h>

function MoveMouse();
function DrawGrid(col, size);

// skyBox shader definition
var vertexSkyBox = "\
uniform vec3 camPos;\
varying vec3 vTexCoord;\
\
void main(void){\
vTexCoord = gl_Vertex.xyz;\
gl_Vertex.xyz += camPos;\
gl_Position = ftransform();\
}";

var fragmentSkyBox = "\
uniform samplerCube Env;\
varying vec3 vTexCoord;\
\
void main(void){\
gl_FragColor = vec4(textureCube(Env, normalize(vTexCoord)).rgb, 1.0);\
}";

// crome shader definition
var vertexCrome = "\
varying vec3  Normal;\
varying vec3  EyeDir;\
\
void main(void){\
gl_Position    = ftransform();\
Normal         = normalize(gl_NormalMatrix * gl_Normal);\
EyeDir         = (gl_ModelViewMatrix * gl_Vertex).xyz;\
}";

var fragmentCrome = "\
uniform samplerCube Env;\
\
varying vec3  Normal;\
varying vec3  EyeDir;\
\
void main(void){\
vec3 reflectDir = reflect(EyeDir, normalize(Normal));\
gl_FragColor = vec4(textureCube(Env, reflectDir).rgb, 1.0);\
}";

// cubeDiffuse shader definition
var vertexDiffuse = "\
varying vec3  Normal;\
\
void main(void){\
gl_Position    = ftransform();\
Normal         = gl_Normal;\
}";

var fragmentDiffuse = "\
uniform samplerCube Env;\
\
varying vec3  Normal;\
\
void main(void){\
gl_FragColor = vec4(textureCube(Env, normalize(Normal)).rgb, 1.0);\
}";

//meshes
var g_mBunny;
var g_mCube;
//shaders
var g_cromeShader;
var g_cubemapDiffusive;
var g_skyBox;
//textures
var g_tSky;
var g_tDiffuse;

var g_glLib;
#define GL_TEXTURE_CUBE_MAP 0x8513


function OnInit(params){
setlocalDir();

g_tSky = CVmTexture("Sky128.dds");
g_tDiffuse = CVmTexture("diffuseCube.dds");
g_mBunny = CVmNewMesh("bunny.aam");
g_mCube = CVmNewMesh(VRP_BOX, 1, [-10, -10, -10], [10, 10, 10]);
g_mCube.scale(1.0, 1.0, -1.0); // flip the normals

g_skyBox = CVmShaderProgram(vertexSkyBox, fragmentSkyBox, true);
g_skyBox.start();
g_skyBox.setParameter("Env", 0);
g_skyBox.stop();

g_cromeShader = CVmShaderProgram(vertexCrome, fragmentCrome, true);
g_cromeShader.start();
g_cromeShader.setParameter("Env", 0);
g_cromeShader.stop();

g_cubemapDiffusive = CVmShaderProgram(vertexDiffuse, fragmentDiffuse, true);
g_cubemapDiffusive.start();
g_cubemapDiffusive.setParameter("Env", 0);
g_cubemapDiffusive.stop();
}

function onFrame(){
moveMouse();
var cPos = CameraGetPosition();
sceneBegin();
setActiveTexture(g_tSky, VR_NO_FILTER, 0);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
g_skyBox.start();
g_skyBox.setParameter("camPos", cPos);
g_mCube.draw();
g_skyBox.stop();
glPushMatrix();
glTranslate(-0.5, 0.0, 0.0);
g_cromeShader.start();
g_mBunny.draw();
g_cromeShader.stop();
glPopMatrix();
setActiveTexture(g_tDiffuse, VR_BILINEAR_FILTER, 0);
g_cubemapDiffusive.start();
g_mBunny.draw();
g_cromeShader.stop();
glDisable(GL_TEXTURE_CUBE_MAP);
DrawGrid([0.0, 0.0, 0.0], 10);
sceneEnd();
}

function moveMouse(){
static var CamPos = [0.0, 0.2, 1.0];
static var CamDir = [0.0, 0.0, -1.0];

static var InMouseR = false, InMouseL = false;
static var PrecX = 0, PrecY = 0;
static var RotX = 0.0, RotY = 0.0;
static var X = 0.0, Y = 0.0;

if (Mouse.ButtonL)
{
if (InMouseL)
{
X = RotX - (Mouse.X - PrecX) / 4.0;
Y = RotY + (Mouse.Y - PrecY) / 10.0;

if (Y > 70)
Y = 70;
if (Y < -70)
Y = -70;
}
else
{
PrecX = Mouse.X;
PrecY = Mouse.Y;
}
InMouseL = true;
}
else
{
if(InMouseL)
{
RotX = X; RotY = Y;
InMouseL = false;
}
}

CameraSetRotation(Y, 1, 0, 0);
CameraRotate(-X, 0, 1, 0);

var direction = CameraGetDirection();
direction.y = 0;
var perpDirection = norm([-direction.z, 0, direction.x]);
switch(keyboard()){
case "w":
CamPos += direction * 0.05;
CameraSetPosition(camPos);
break;
case "s":
CamPos -= direction * 0.05;
CameraSetPosition(camPos);
break;
case "a":
CamPos -= perpDirection * 0.05;
CameraSetPosition(camPos);
break;
case "d":
CamPos += perpDirection * 0.05;
CameraSetPosition(camPos);
break;
}
}

function DrawGrid(col, size){
/* let's not mess up current OpenGL status */
glPushAttrib(GL_LIGHTING_BIT | GL_LINE_BIT | GL_CURRENT_BIT);

glLineWidth(1);
glDisable(GL_LIGHTING);
glColor(col);
var max = size / 2.0;
var min = -max;
var step = size / 10.0;

glBegin(GL_LINES);
for (var i = min; i <= max; i += step)
{
glVertex(i, 0, max);
glVertex(i, 0, min);

glVertex(max, 0, i);
glVertex(min, 0, i);
}
glEnd();

/* polite restoration of previous OpenGL status */
glPopAttrib();
}

if you need further help just ask, actually I'm a bit in hurry.

Attached you can find the mesh and the cubemaps that I have used.
« Last Edit: January 03, 2009, 04:43:44 AM by ilmale » Logged

~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!