Jump to content

Masterxilo

Members
  • Posts

    379
  • Joined

  • Last visited

Posts posted by Masterxilo

  1. Actually I think that you can load also multiple terrains, and then move the other terrains to make a continuous 3x3x4096x4096 terrain combo.

    You could probably even load then also 16, 25, 36, etc... terrains and have a 1440 km x 1440 km mega terrain.

    CMIIW, but this is (was?) NOT possible. You can only have one terrain.

  2. I just noticed that FPS drop heavily when a window's client area is covered by the vista start orb.

    Did anyone ever notice that?

     

    (the number in the upper left corner of the following pictures is the UPS of the application)

    Window placed normally (viewport not overlapped by vista start icon):

    post-150-12652252043335_thumb.jpg

    Window placed in such a way that the round part of the start orb covers it

    post-150-12652252105469_thumb.jpg

    (If a viewport is being covered by the taskbar only, fps stay normal, so it's really the round, transparent start icon that causes this)

     

    It looks to me as if the application has to wait for the os to render that small round part of the start button over the viewport. What a waste! Why didn't they stay with the simple rectangular taskbar with a start button that fits in it? Why does it have to overlap???

     

    This is nothing le or opengl specific, but obviously happens with any engine and graphics api (tested).

     

    So if you make windowed applications: make sure your realtime viewport NEVER covers the vista start button!

    ---

    Use this code if you want to see for yourself:

    #include "engine.h"
    #include "mathlib.h"
    
    int main(void)
    {
       // Init
       Initialize();
       Graphics(640,480);
       TEntity world = CreateWorld();
    
    
       // Main Loop
       while(!KeyHit(KEY_ESCAPE) && !AppTerminate())
       {
           UpdateWorld();
           UpdateAppTime();
    
           RenderWorld();
    
           DrawText(0,0,"%f",UPS());
    
           Flip(0);
       }
    
       // Terminate
       return Terminate();
    }

     

    I'd appreciate if some people could try that out and report if the experience the same slowdown.

    Maybe there's just something bad going on with my vista/opengl/graphics driver/graphics card/computer...

  3. In ps, there are different color/paint/image blend modes such as "Normal", "Multiply" and "Color".

     

    How does the "Color" blend mode work (programming-wise...).

    How would I recreate that blending in a shader?

  4. The first way doesn't work because you use y as the z position, I think it should be:

    VObject::kiObject->Y = TerrainHeight(cTerrain, kiObject->X*2,kiObject->Z*2); // 2 is the Meter per tile

     

    and for the second way: make sure you use 0 as the pick radius, anything else doesn't work. (set your 5 to 0)

  5. Might actually be useful to define a center for scaling as well. Here some updated versions:

    void ScaleMeshUV(TEntity mesh, TVec2 uvscale, TVec2 center = Vec2(0,0))
    {
       for (int iSurf = 1; iSurf <= CountSurfaces(mesh); iSurf++)
       {
           TSurface surface = GetSurface(mesh, iSurf);
           for (int iVert = 0; iVert < CountVertices(surface); iVert++)
           {
               for (int texcset = 0; texcset < 2; texcset++)
               {
                   TVec2 uv = (GetVertexTexCoords(surface, iVert, texcset) - center) * uvscale + center;
                   SetVertexTexCoords(surface, iVert, uv, texcset);
               }
           }
       }
       UpdateMesh(mesh);
    }
    
    
    void RotateMeshUV(TEntity mesh, float angle, TVec2 center = Vec2(0,0))
    {
       angle = deg2rad(angle);
       for (int iSurf = 1; iSurf <= CountSurfaces(mesh); iSurf++)
       {
           TSurface surface = GetSurface(mesh, iSurf);
           for (int iVert = 0; iVert < CountVertices(surface); iVert++)
           {
               for (int texcset = 0; texcset < 2; texcset++)
               {
                   TVec2 uv = GetVertexTexCoords(surface, iVert, texcset);
                   uv -= center;
                   TVec2 rf = Vec2(cos(angle), sin(angle)); // roationFactor
                   uv = Vec2(uv.X*rf.X - uv.Y*rf.Y, uv.X*rf.Y + uv.Y*rf.X);
                   uv += center;
    
                   SetVertexTexCoords(surface, iVert, uv, texcset);
               }
           }
       }
       UpdateMesh(mesh);
    }

  6. And I just wrote this for rotation (press the up/down keys to rotate the texture on the oil drum):

    #include "engine.h"
    #include "mathlib.h"
    
    #include <string>
    using namespace std;
    
    void RotateMeshUV(TEntity mesh, TVec2 rotationCenter, float angle)
    {
    angle = deg2rad(angle);
    for (int iSurf = 1; iSurf <= CountSurfaces(mesh); iSurf++)
    {
    	TSurface surface = GetSurface(mesh, iSurf);
    	for (int iVert = 0; iVert < CountVertices(surface); iVert++)
    	{
    		for (int texcset = 0; texcset < 2; texcset++)
    		{
    			TVec2 uv = GetVertexTexCoords(surface, iVert, texcset);
    			uv -= rotationCenter;
    			TVec2 rf = Vec2(cos(angle), sin(angle)); // roationFactor
    			uv = Vec2(uv.X*rf.X - uv.Y*rf.Y, uv.X*rf.Y + uv.Y*rf.X);
    			uv += rotationCenter;
    
    			SetVertexTexCoords(surface, iVert, uv, texcset);
    		}
    	}
    }
    UpdateMesh(mesh);
    }
    
    
    int main(void)
    {
    // Init
    Initialize();
    Graphics(640,480);
    TEntity world = CreateWorld();
    TEntity buffer = CreateBuffer(640,480,BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL|BUFFER_COLOR2);
    
    // Cam
    TEntity camera = CreateCamera();
    MoveEntity(camera, Vec3(0,0.5,-1.5) );
    
    // Light
    TEntity light  = CreateSpotLight(15,0);
    MoveEntity   (light,  Vec3(-1,5,-4) );
    RotateEntity (light,  Vec3(45,0,0), 0);
    SetShadowmapSize(light,512);
    AmbientLight(Vec3(.05));
    
    // Ground
    TEntity plane  = CreateCube(0);
    ScaleEntity  (plane,  Vec3(100,1,100) );
    MoveEntity   (plane,  Vec3(0,-2.5,0) );
    
    // Model
    TEntity m1 = LoadMesh("abstract::oildrum.gmf");
    float angle = 0.0f;
    
    // Main Loop
    while(!KeyHit(KEY_ESCAPE) && !AppTerminate())
    {
    	if(KeyDown(KEY_UP) || KeyDown(KEY_DOWN))
    	{
    		float fac = KeyDown(KEY_UP) - KeyDown(KEY_DOWN);
    		RotateMeshUV(m1, Vec2(0,0), fac);
    		angle += fac;
    	}
    
    	UpdateWorld();
    
    	SetBuffer(buffer);
    	RenderWorld();
    	SetBuffer(BackBuffer());
    	RenderLights(buffer);
    
    	DrawText(0,0,"angle: %f", angle);
    
    
    	Flip(1);
    }
    
    // Terminate
    return Terminate();
    }

  7. I do this for uv scaling (move the mouse to set the uv scaling on the oil drum):

    #include "engine.h"
    #include "mathlib.h"
    
    #include <string>
    using namespace std;
    
    void ScaleMeshUV(TEntity mesh, TVec2 uvscale)
    {
    for (int iSurf = 1; iSurf <= CountSurfaces(mesh); iSurf++)
    {
    	TSurface surface = GetSurface(mesh, iSurf);
    	for (int iVert = 0; iVert < CountVertices(surface); iVert++)
    	{
    		for (int texcset = 0; texcset < 2; texcset++)
    		{
    			TVec2 uv = GetVertexTexCoords(surface, iVert, texcset) * uvscale;
    			SetVertexTexCoords(surface, iVert, uv, texcset);
    		}
    	}
    }
    UpdateMesh(mesh);
    }
    
    
    int main(void)
    {
    // Init
    Initialize();
    Graphics(640,480);
    TEntity world = CreateWorld();
    TEntity buffer = CreateBuffer(640,480,BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL|BUFFER_COLOR2);
    
    // Cam
    TEntity camera = CreateCamera();
    MoveEntity(camera, Vec3(0,0.5,-1.5) );
    
    // Light
    TEntity light  = CreateSpotLight(15,0);
    MoveEntity   (light,  Vec3(-1,5,-4) );
    RotateEntity (light,  Vec3(45,0,0), 0);
    SetShadowmapSize(light,512);
    AmbientLight(Vec3(.05));
    
    // Ground
    TEntity plane  = CreateCube(0);
    ScaleEntity  (plane,  Vec3(100,1,100) );
    MoveEntity   (plane,  Vec3(0,-2.5,0) );
    
    // Model
    TEntity m1 = LoadMesh("abstract::oildrum.gmf");
    // ScaleMeshUV(m1, Vec2(3,2)); // some test scaling
    
    // Main Loop
    while(!KeyHit(KEY_ESCAPE) && !AppTerminate())
    {
    	TVec2 scale = Vec2((1.0f*Max(MouseX(),1)/GraphicsWidth())*10,(1.0f*Max(MouseY(),1)/GraphicsHeight())*10);
    	ScaleMeshUV(m1, scale);
    
    	UpdateWorld();
    
    	SetBuffer(buffer);
    	RenderWorld();
    	SetBuffer(BackBuffer());
    	RenderLights(buffer);
    
    	ScaleMeshUV(m1, Vec2(1,1)/scale); // undo above scaling
    
    	Flip(1);
    }
    
    // Terminate
    return Terminate();
    }

  8. Some uniforms are passed per instance (like color, scale, etc), so is there something special about the textures or shaders that would break batching if they were per instance?

    Nothing except the transformation matrix is passed per instance.

    The colored is stored in the 4th row of it (which is actually a "hack").

  9. and even another call to LoadModel would just create another instance of the original

    You just need to copy (maybe also renaming would work) all the files and then load these, this will give you a new model which is no instance of any other entity.

    Loading the same file does indeed always return just an instance.

     

    I wrote these utility functions that do exactly this:

    #include <string>
    using namespace std;
    
    TEntity LoadMeshUninstanced(str name, TEntity parent = 0)
    {
    // Prepare filename
    static int loadedMeshes = 0; loadedMeshes++;
    char buf[10];
    
    string originalFilePath = AbstractPath(name);
    originalFilePath.erase(originalFilePath.length()-4, 4);
    
    string newFilePath = originalFilePath;
    newFilePath += "_meshInstance";
    newFilePath += itoa(loadedMeshes, buf, 10);
    
    // # Copy all files
    CopyFile((originalFilePath+".gmf").c_str(), (newFilePath+".gmf").c_str(), false);
    
    // # Load model
    TEntity mesh = LoadMesh(const_cast<str>((newFilePath+".gmf").c_str()), parent);
    
    // # Delete temp files
    DeleteFile((newFilePath+".gmf").c_str());
    
    return mesh;
    }
    
    TEntity LoadModelUninstanced(str name, TEntity parent = 0)
    {
    // Prepare filename
    static int loadedModels = 0; loadedModels++;
    char buf[10];
    
    string originalFilePath = AbstractPath(name);
    originalFilePath.erase(originalFilePath.length()-4, 4);
    
    string newFilePath = originalFilePath;
    newFilePath += "_instance";
    newFilePath += itoa(loadedModels, buf, 10);
    
    // # Copy all files
    // Models and lods
    long hr = 1;
    for(int lod = 0; hr != 0; lod++)
    {
    	string lodAdd = "";
    	if(lod > 0)
    	{
    		lodAdd += "lod";
    		lodAdd += itoa(lod, buf, 10);
    	}
    
    	hr = CopyFile((originalFilePath+lodAdd+".gmf").c_str(), (newFilePath+lodAdd+".gmf").c_str(), false);
    }
    // Other files
    CopyFile((originalFilePath+".ini").c_str(), (newFilePath+".ini").c_str(), false);
    CopyFile((originalFilePath+".lua").c_str(), (newFilePath+".lua").c_str(), false);
    CopyFile((originalFilePath+".phy").c_str(), (newFilePath+".phy").c_str(), false);
    
    // # Load model
    TEntity model = LoadModel(const_cast<str>((newFilePath+".gmf").c_str()), parent);
    
    // # Delete temp files
    hr = 1;
    for(int lod = 0; hr != 0; lod++)
    {
    	string lodAdd = "";
    	if(lod > 0)
    	{
    		lodAdd += "lod";
    		lodAdd += itoa(lod, buf, 10);
    	}
    
    	hr = DeleteFile((newFilePath+lodAdd+".gmf").c_str());
    }
    DeleteFile((newFilePath+".ini").c_str());
    DeleteFile((newFilePath+".lua").c_str());
    DeleteFile((newFilePath+".phy").c_str());
    
    return model;
    }

     

    Usage example:

    int main(void)
    {
    // Init
    Initialize();
    Graphics(640,480);
    TEntity world = CreateWorld();
    TEntity buffer = CreateBuffer(640,480,BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL|BUFFER_COLOR2);
    
    // Cam
    TEntity camera = CreateCamera();
    MoveEntity(camera, Vec3(0,0,-2.5) );
    
    // Light
    TEntity light  = CreateSpotLight(15,0);
    MoveEntity   (light,  Vec3(-1,5,-4) );
    RotateEntity (light,  Vec3(45,0,0), 0);
    SetShadowmapSize(light,512);
    AmbientLight(Vec3(.05));
    
    // Ground
    TEntity plane  = CreateCube(0);
    ScaleEntity  (plane,  Vec3(100,1,100) );
    MoveEntity   (plane,  Vec3(0,-2.5,0) );
    
    // Model
    TEntity m1 = LoadModelUninstanced("abstract::oildrum.gmf");
    PositionEntity   (m1,  Vec3(-1.5,0,0) );
    
    TEntity m2 = LoadModelUninstanced("abstract::oildrum.gmf");
    PositionEntity(m2,  Vec3(1.5,0,0) );
    PaintEntity(GetChild(m2,1), LoadMaterial("abstract::oakbranch.mat"));
    
    // Main Loop
    while(!KeyHit(KEY_ESCAPE) && !AppTerminate())
    {
    	UpdateWorld();
    
    	SetBuffer(buffer);
    	RenderWorld();
    	SetBuffer(BackBuffer());
    	RenderLights(buffer);
    
    	Flip(1);
    }
    
    // Terminate
    return Terminate();
    }

    Notice both oil drums would have the "oakbranch.mat" applied if you used LoadModel.

  10. Is this your own program where you loaded that mesh?

    Make sure the buffer is created like:

    TEntity buffer = CreateBuffer(640,480,BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL|BUFFER_COLOR2);

    The last "|BUFFER_COLOR2" stores the specular intensity per pixel. Without it, you don't get any specular effects at all. This is new since some version after 2.2x (don't remember which one).

    Before that, specular lighting just worked.

  11. Probably something like this would work, but it seems like a good idea to add this to mathlib:

    void _stdcall EntityCollisionCallback( TEntity entity0, TEntity entity1, byte* position, byte* normal, byte* force, flt speed )
    {
    TVec3 hitforce;
    hitforce.X=force[0];
    hitforce.Y=force[4];
    hitforce.Z=force[8];
    }

    Why so complicated?

    TVec3 *pHitForce = reinterpret_cast<TVec3*>(force);

  12. ^^ yeah, I wouldn't have posted just some stuff simulated using physx if it wouldn't use le for rendering.

     

    When Josh said he didn't see any of these features, he probably meant "Not in LE."

    I know.

    And then I said that this is no argument since everything possible in the physics engine is possible in le.

×
×
  • Create New...