Jump to content

SpiderPig

Developers
  • Posts

    2,272
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. Used some old code today and loading a non-existent shader family with the .json extension printed this output...

    Loading shader family "Shaders/Unlit.json"
    Deleting shader family "Shaders/Unlit.json"

    Should it be more like this so we know it actually failed?

    Error : Failed to load shader family "Shaders/Unlit.json"

     

  2. Not positive if this is a bug to be honest and if it is it may well be fixed in the next update, but just in case - In my game rotating the directional light to mimic the sun causes the vertex, polygon and instance count to slowly ramp up to about 20x then it will slowly decrease and then ramp up again.  (I have 1.2 million verts in my game and it can get up to 30million before repeating the cycle)  The code below shows the stats fluctuating in the window title albeit at a lesser extent than in my game.

    Should the vertex, polygon and instance counts fluctuate with a moving / rotating light source?  And by that much?

    #include "Engine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
        world->RecordStats();
    
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(10, 10, -8);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
    
        
        auto floor = CreateBox(world, 128);
        floor->Move(0, -64, 0);
    
        vector<shared_ptr<Entity>> boxes;
        for (int z = 0; z < 25; z++) {
            for (int x = 0; x < 25; x++) {
                auto e = CreateSphere(world);
                e->SetPosition(x, 0.0f, z, true);
                boxes.push_back(e);
            }
        }
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            Vec3 day_speed = Vec3(0.5, 0, 0);
            light->Turn(day_speed.x, day_speed.y, day_speed.z);
    
            auto stats = world->renderstats;
            WString text = "FPS : [" + WString(stats.framerate) + "] - ";
            text += "Verts : [" + WString(stats.vertices) + "] - ";
            text += "Polys : [" + WString(stats.polygons) + "] - ";
            text += "Insts : [" + WString(stats.instances) + "] - ";
            text += "Shadow Polys : [" + WString(stats.shadowpolygons) + "]";
    
            window->SetText(text);
    
            world->Update();
            world->Render(framebuffer, false);
        }
    
        return 0;
    }

     

  3. Finally got normal mapping working correctly.  :wub:

    NormalsDoneRight.thumb.png.e637fd6ab71bbe4e13d619bcff0df4ba.png

    I'm using debugging heightmaps to identify each world and the square in the top left of each map tells me what the coordinate system should be for that world.  I love it how the edges of each map blend nicely together with no extra work other than just normals.

    Next steps;

    • Fix tangent & bitangent maps
    • Re-apply heightmaps and generate rocky heights for the borders between worlds
    • Apply gravity maps & get physics working again
    • Generate biomes according to heightmap stamps used

    After all that I can finally start working on gameplay again. :D

    • Like 1
    • Upvote 1
  4. Once again simply posting has helped solve the problem... This is not the correct order to multiply matrices in.

    localVertPos *= inverse(projectionMatrix);
    localVertPos *= inverse(entityMatrix);

    This is.

    localVertPos = inverse(projectionMatrix) * localVertPos;
    localVertPos = inverse(entityMatrix) * localVertPos;

    And the other issue of points all appearing in the centre of the mesh.  Both vertex and geometry shaders need to be in the mask section of a shader family. 

    Fozzie Bear Reaction GIF

  5. I have officially been driven mad by this issue over the last few days.  Something I've had working in the past and thought I understood now doesn't want to behave.

    Here's a simplified example.  I'll be creating vertices in the geometry shader and those new positions will need multiplying by the model and projection matrices.  But I'm getting mixed result of vertices flying off screen and sometimes only one vertex in the centre of the model.  I know I'm doing something wrong.

    Here I'm applying the shader to a grid made with CreatePlane and 8 x & y segments.  It should be a flat grid of points but the code below makes them fly around with the camera, this is just one shot were they were in view.

    Even when I pass the entity matrix, projection matrix and raw vertex position as an output to the geometry shader I can't get it to work.  I'm sure a quick discussion with guys will help resolve this.

    GeometryShaderIssue.thumb.jpg.53035a0e919668ae652ab0ad5ad01ae5.jpg

    Geometry Shader Code.

    #version 450
    #extension GL_GOOGLE_include_directive : enable
    #extension GL_ARB_separate_shader_objects : enable
    #extension GL_EXT_multiview : enable
    
    layout ( triangles ) in;
    layout ( points , max_vertices = 1 ) out;
    
    layout(location = 9 ) in flat uint inFlags[];
    layout(location = 25 ) in flat uint inEntityindex[];
    layout(location = 2 ) in vec4 inTexCoords[];
    layout(location = 3 ) in vec3 inTangent[];
    layout(location = 4 ) in vec3 inBitangent[];
    layout(location = 5 ) in flat uint inMaterialIndex[];
    layout(location = 0 ) in vec4 inColor[];
    layout(location = 6 ) in vec4 inVertexCameraPosition[];
    layout(location = 23 ) in vec3 inScreenvelocity[];
    layout(location = 1 ) in vec3 inNormal[];
    layout(location = 7 ) in vec4 inVertexWorldPosition[];
    layout(location = 17 ) in vec4 inVertexPosition[];
    
    
    layout(location = 9 ) out flat uint outFlags;
    layout(location = 25 ) out flat uint outEntityindex;
    layout(location = 2 ) out vec4 outTexCoords;
    layout(location = 3 ) out vec3 outTangent;
    layout(location = 4 ) out vec3 outBitangent;
    layout(location = 5 ) out flat uint outMaterialIndex;
    layout(location = 0 ) out vec4 outColor;
    layout(location = 6 ) out vec4 outVertexCameraPosition;
    layout(location = 23 ) out vec3 outScreenvelocity;
    layout(location = 1 ) out vec3 outNormal;
    layout(location = 7 ) out vec4 outVertexWorldPosition;
    layout(location = 17 ) out vec4 outVertexPosition;
    
    #include "../../../../../../../../UltraEngine/Templates/Common/Source/Shaders/Base/EntityInfo.glsl"
    #include "../../../../../../../../UltraEngine/Templates/Common/Source/Shaders/Base/CameraInfo.glsl"
    
    void main() {
    	//This works, only the first vertex of every triangle should make a point and it does just that
    	/*for (int vertex_id = 0; vertex_id < 1; vertex_id++) {
    		gl_Position = gl_in[vertex_id].gl_Position;
    		gl_PointSize = 4.0f;
    		
    		outFlags = inFlags[vertex_id];
    		outEntityindex = inEntityindex[vertex_id];
    		outTexCoords = inTexCoords[vertex_id];
    		outTangent = inTangent[vertex_id];
    		outBitangent = inBitangent[vertex_id];
    		outMaterialIndex = inMaterialIndex[vertex_id];
    		outColor = inColor[vertex_id];
    		outVertexCameraPosition = inVertexCameraPosition[vertex_id];
    		outScreenvelocity = inScreenvelocity[vertex_id];
    		outNormal = inNormal[vertex_id];
    		outVertexWorldPosition = inVertexWorldPosition[vertex_id];
    		outVertexPosition = inVertexPosition[vertex_id];
    		EmitVertex();
    	}
    	EndPrimitive();*/
    
      	//Here I'm trying to prove that I can take a local vertex position and re-multiply it by the correct matrices
      	//As f ar as I know to get the local vertex postion back I need to undo a few things first...
      	//I actually don't know what the vertex 'w' component should be.  I'm pretty sure it should be 1.0f...
     
    	mat4 entityMatrix = ExtractEntityMatrix(inEntityindex[0]);
    	mat4 projectionMatrix = ExtractCameraProjectionMatrix(CameraID, gl_ViewIndex);
    	
    	vec4 localVertPos = gl_in[0].gl_Position;
    	localVertPos.z *= 2.0f;
    	localVertPos.z -= localVertPos.w;
    	
    	localVertPos *= inverse(projectionMatrix);
    	localVertPos *= inverse(entityMatrix);
    	
    	//This is what the vertex shader does as far as I can tell
    	gl_Position = projectionMatrix * (entityMatrix * localVertPos);
    	gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5f;
    	gl_PointSize = 4.0f;
    		
    	EmitVertex();
    	EndPrimitive();
    }

     

    DisplayNormals.zip

  6. Thanks for your input guys.  I actually have the app id already - but I don't know how to make the page live with no download attached... is that as simple as publishing the page but not making a repo? (or what ever it's called, I forget) or do I make it coming soon page?

  7. Does anyone have any thoughts on releasing an alpha version of my game on steam as a free download?  I thought about uploading it to something like itch.io but I want to use and test some steam features too.

    I'm thinking I could develop the game while it's on steam, get some feedback etc.  and then later turn that free download into the demo for the final game.

    I'm just wondering though if this is a good idea or if steam should be avoided until ready for early access phase.  Mainly for things like reviews.  But I'm curious to hear your thoughts.

  8. So the max instance count is about 65k but does that include things like sub-passes and meshes?

    I mean can we have 65,000 instanced cubes or with 2 sub-passes are we limited to only 32,000 cubes?

    Also, with your Instanced geometry benchmark code, I've added in swept culling and a few more cubes.  Even with swept culling enabled it doesn't make much difference.  In my game I only have a few thousand instances and it doesn't hep much there either.

    Can I turn off culling for particular objects or all of them?  I'd like to test the performance of both options.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
    	const int count = 32;
    	RegisterComponents();
    
    	//Get the displays
    	auto displays = GetDisplays();
    
    	//Create a window
    	auto window = CreateWindow("Instanced Geometry", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    
    	//Create framebuffer
    	auto framebuffer = CreateFramebuffer(window);
    
    	//Create world
    	auto world = CreateWorld();
    
    	//Create camera
    	auto camera = CreateCamera(world);
    	camera->SetPosition(0, 0, -count * 2);
    	camera->SetClearColor(0.125);
    	camera->SetDepthPrepass(false);
    	camera->AddComponent<CameraControls>();
    	camera->SetSweptCulling(true);
    	camera->SetOcclusionCullingMode(false);
    	
    
    	//Create box 
    	auto box = CreateBox(world);
    	box->SetCollider(NULL);
    
    	auto mtl = CreateMaterial();
    	mtl->SetColor(0.5f);
    	mtl->SetShaderFamily(LoadShaderFamily("Shaders/Unlit.fam"));
    	box->SetMaterial(mtl);
    
    	//Create instances
    	std::vector<shared_ptr<Entity> > boxes;
    	boxes.reserve(count * count * count);
    	int x, y, z;
    	for (x = 0; x < 32; ++x)
    	{
    		for (y = 0; y < 32; ++y)
    		{
    			for (z = 0; z < 64; ++z)
    			{
    				auto inst = box->Instantiate(world);
    				inst->SetPosition(3.0f + float(x - 1 - (count / 2)) * 2, 3.0f + float(y - 1 - (count / 2)) * 2, 3.0f + float(z - 1 - (count / 2)) * 2);
    				boxes.push_back(inst);
    			}
    		}
    	}
    
    	box = NULL;
    
    	//Fps display
    	auto font = LoadFont("Fonts/arial.ttf");
    	auto sprite = CreateSprite(world, font, "", 14);
    	world->RecordStats(true);
    	sprite->SetRenderLayers(2);
    	sprite->SetPosition(2, framebuffer->size.y - font->GetHeight(14) - 2, 0);
    	auto orthocam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    	orthocam->SetRenderLayers(2);
    	orthocam->SetClearMode(ClearMode(0));
    	orthocam->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0);
    
    	//Main loop
    	while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    	{
    		//Check for failed renderer initialization
    		while (PeekEvent())
    		{
    			const auto e = WaitEvent();
    			if (e.id == EVENT_STARTRENDERER and e.data == 0)
    			{
    				Notify(L"Renderer failed to intialize.\n\n" + e.text, "Ultra Engine", true);
    				return 0;
    			}
    		}
    
    		sprite->SetText("FPS: " + String(world->renderstats.framerate));
    
    		world->Update();
    		world->Render(framebuffer, false);
    	}
    	return 0;
    }

     

  9. I just noticed your texture creation method;

    _dataTexture = CreateTexture(TEXTURE_2D, 64, 32, TEXTURE_RGBA32, {}, 1, TEXTURE_DEFAULT, TEXTUREFILTER_NEAREST);

    I leave my type as TEXTURE_RGBA and convert to floats like this -

    float BytesToFloat( in vec4 pixel ) {
    	return intBitsToFloat( ( int( ( pixel.w * 255.0f ) ) << 24 ) | ( int( ( pixel.z * 255.0f ) ) << 16 ) | ( int( ( pixel.y * 255.0f ) ) << 8 ) | int( ( pixel.x * 255.0f ) ) );
    }

    Would that function still work with the type TEXTURE_RGBA32 you think? I also use TexelFetch instead of sample.

  10. 16 minutes ago, klepto2 said:

    In your case, the sun direction is already available in the shader, you don't need to pass it down like that, In ultraEngine you can always access nearly anything at anytime in the shader. This itroduces a lot of possbilities: eg calculating combined atmospheric effects for multiple suns.

    Sweet!  That should work better.  As far as using the buffer, I had it working fine on some smaller applications which leads me to believe there's a bug with my shader.  Pity we can't debug shaders....

  11. I can't seem to reproduce this on a smaller scale.  It's more than likely an issue with the shader itself but I can't for the life of me narrow it down.  :blink:

    Anyway I've attached code and shaders if someone would like to take a look as well.  It's like the shader doesn't like some of the vectors of the sun position and it causes it to flicker black sometimes.  Any help is appreciated, I'll be tackling this in the shadows. :ph34r:

     

     

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    using namespace UltraEngine;
    
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto framebuffer = CreateFramebuffer(window);
    
        auto world = CreateWorld();
        world->RecordStats(true);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->Move(0, 2, 0);
        camera->AddComponent<CameraControls>();
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(45, 35, 0);
        light->SetColor(2);
    
        auto plane = CreatePlane(world, 100, 100);
    
        auto sphere = CreateSphere(world, 512, 32);
        auto mat = LoadMaterial("Materials\\DynamicSky\\DynamicSky.mat");
        sphere->SetMaterial(mat);
    
        auto size = 8;
        auto buffer = CreateBuffer(size * size * 4);
        auto texture = CreateTexture(TEXTURE_2D, size, size);
        mat->SetTexture(texture, 15);
    
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            Vec3 speed = Vec3(0.02, 0, 0);
            light->Turn(speed.x, speed.y, speed.z);
    
            auto yoffset = 300;
            auto dir = Vec3(light->matrix.k.x, light->matrix.k.y, light->matrix.k.z).Normalize();
            auto sun_raw_pos = Vec3(-dir.x, -dir.y, -dir.z);
            auto camera_range = camera->GetRange().y;
            auto sun_pos = Vec3(-dir.x, -dir.y + (yoffset / camera_range), -dir.z).Normalize();
    
            auto index = 0;
            buffer->PokeFloat(index, sun_pos.x);
            buffer->PokeFloat(index + 4, sun_pos.y);
            buffer->PokeFloat(index + 8, sun_pos.z);
    
            texture->SetPixels(buffer);
    
            auto stats = world->renderstats;
            window->SetText("FPS : " + WString(stats.framerate) + " --- verts : " + WString(stats.vertices) +
            " --- polys : " + WString(stats.polygons) + " --- instances : " + WString(stats.instances));
    
            world->Update();
            world->Render(framebuffer, false);
        }
        return 0;
    }

     

  12. I've been using a texture to store variables for a lot of my shaders.   I've just decided today to see if I can update those variables in real-time.  While it does work, I am seeing a bit of flicking - which in this case I'm assuming is due the to fact that when I'm setting a textures pixels there may be a few shader updates were that information is either gone or invalid?  I've tried both render hooks as well.  HOOKID_TRANSFER reduces it a bit but not completely.

    Just wondering if this is a good idea before I continue with it.  :)

    buffer->PokeInt(index, value);
    texture->SetPixels(buffer);

     

×
×
  • Create New...