How to fix: Could not create vertex shader in irrlicht?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Noiecity
Posts: 422
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

How to fix: Could not create vertex shader in irrlicht?

Post by Noiecity »

I was trying to compile Irrlicht with D3D9 in CodeBlocks (I installed the version of CodeBlocks that came with the 32-bit compiler, as I couldn’t compile for 32-bit using the 64-bit version).
First, I enabled the flags to compile with C++98, and changed two `nullptr`s that were somewhere in the OpenGL code – I can’t remember where – to `NULL`.

I then successfully compiled the code (I hadn’t checked the console yet).
I tried moving the executable file to another location, and it appeared not to run because some of the C++ wasn’t statically linked… so I compiled Irrlicht source statically(Win32 - Release - fast math - static); now I could move the executable file and it worked…
Image
Image
(I think you only need d3d9 and d3dx9 to compile correctly; I’ve managed to compile it using d3d9, d3dx9 and dxguid – I haven’t tried it without dxguid)
Image
Image


but to my surprise, I got this:


Irrlicht Engine version 1.9.0
Microsoft Windows 8 or later (Build 9200)
Using renderer: Direct3D 9.0
NVIDIA GeForce RTX 3050 6GB Laptop GPU nvldumd.dll 32.0.15.9180
At least available dedicated+shared system texture memory (kB): 4177920
Could not load shader function D3DXAssembleShader from dll, shaders disabled: d3dx9_43.dll
Could not create vertex shader.
Could not create vertex shader.

Resizing window (1920 1061)
Resetting D3D9 device.

I managed to sort out the .dll issue by downloading the file in question, but I couldn’t fix the vertex shader compilation errors. I want to compile using GCC as its auto-vectorisation is among the best available in C++; Visual Studio with MSBUILD doesn’t have such robust auto-vectorisation.
(I also vectorised it, optimising it for CPUs from 2013 to maximise compatibility(-march=corei7))
And don’t even get me started on trying to vectorise SIMD instructions manually yourself – GCC always does it better (I’ve tried to do it better, and I couldn’t, and others have tried too https://markaicode.com/gcc-14-auto-vect ... -assembly/:

Code: Select all


#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


// -----------------------------------------------------------------------------
// Single controller that maintains the base position + orientation and derives
// both cameras of the horizontal stereo pair.
//
// Mouse behaviour:
//   * The OS cursor is hidden.
//   * Deltas are computed against the last known cursor position, so the
//     camera rotates smoothly without forcing the cursor to the center.
//   * The cursor is only teleported back to the center when it gets close to
//     a screen edge. This keeps 360-degree rotation possible while avoiding
//     the "cursor fights to return to center" feeling.
// -----------------------------------------------------------------------------
class TwoViewportController : public IEventReceiver
{
public:

    TwoViewportController(ICameraSceneNode* left,
                          ICameraSceneNode* right,
                          const vector3df& startPos,
                          const vector3df& startTarget,
                          ICursorControl* cursorControl,
                          s32 centerX,
                          s32 centerY,
                          s32 screenW,
                          s32 screenH,
                          f32 moveSpeed        = 30.0f,
                          f32 mouseSensitivity = 0.15f,
                          s32 edgeMargin       = 100)
        : CamLeft(left),
          CamRight(right),
          Position(startPos),
          MoveSpeed(moveSpeed),
          MouseSensitivity(mouseSensitivity),
          CursorControl(cursorControl),
          CenterX(centerX),
          CenterY(centerY),
          ScreenW(screenW),
          ScreenH(screenH),
          EdgeMargin(edgeMargin),
          LastMouseX(-1),
          LastMouseY(-1)
    {
        vector3df dir = (startTarget - startPos).normalize();

        Yaw   = atan2f(dir.X, dir.Z);
        Pitch = asinf(core::clamp(dir.Y, -1.0f, 1.0f));

        for (u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i)
            KeyIsDown[i] = false;

        updateCameras();
    }


    bool OnEvent(const SEvent& event) override
    {
        if (event.EventType == EET_KEY_INPUT_EVENT)
        {
            KeyIsDown[event.KeyInput.Key] =
                event.KeyInput.PressedDown;

            return false;
        }


        if (event.EventType == EET_MOUSE_INPUT_EVENT &&
            event.MouseInput.Event == EMIE_MOUSE_MOVED)
        {
            const s32 x = event.MouseInput.X;
            const s32 y = event.MouseInput.Y;

            // First mouse event after the cursor was (re)placed: just record
            // the position, don't treat it as a movement.
            if (LastMouseX < 0)
            {
                LastMouseX = x;
                LastMouseY = y;
                return true;
            }

            const s32 dx = x - LastMouseX;
            const s32 dy = y - LastMouseY;

            LastMouseX = x;
            LastMouseY = y;

            if (dx != 0 || dy != 0)
            {
                Yaw   += (f32)dx * MouseSensitivity * core::DEGTORAD;
                Pitch -= (f32)dy * MouseSensitivity * core::DEGTORAD;

                const f32 limit = 89.0f * core::DEGTORAD;
                if (Pitch >  limit) Pitch =  limit;
                if (Pitch < -limit) Pitch = -limit;
            }

            // Only teleport the cursor back to the center when it is close to
            // an edge. This lets the cursor move freely in the middle of the
            // screen while still allowing unlimited rotation.
            if (CursorControl &&
                (x <  EdgeMargin          ||
                 x >  ScreenW - EdgeMargin ||
                 y <  EdgeMargin          ||
                 y >  ScreenH - EdgeMargin))
            {
                // Set LastMouse *before* setPosition so that the synthetic
                // event generated by the recenter produces a zero delta.
                LastMouseX = CenterX;
                LastMouseY = CenterY;

                CursorControl->setPosition(CenterX, CenterY);
            }

            return true;
        }

        return false;
    }


    void update(f32 dt)
    {
        vector3df fwd = getBaseDirection();

        fwd.Y = 0;

        if (fwd.getLength() < 1e-4f)
            fwd = vector3df(0, 0, 1);
        else
            fwd.normalize();


        const vector3df right =
            fwd.crossProduct(vector3df(0, 1, 0)).normalize();


        vector3df move(0, 0, 0);

        if (KeyIsDown[KEY_KEY_W]) move += fwd;
        if (KeyIsDown[KEY_KEY_S]) move -= fwd;
        if (KeyIsDown[KEY_KEY_D]) move -= right;
        if (KeyIsDown[KEY_KEY_A]) move += right;

        if (move.getLength() > 1e-4f)
        {
            move.normalize();

            Position += move * MoveSpeed * dt;
        }

        updateCameras();
    }


private:

    vector3df getBaseDirection() const
    {
        vector3df d;

        d.X = cosf(Pitch) * sinf(Yaw);
        d.Y = sinf(Pitch);
        d.Z = cosf(Pitch) * cosf(Yaw);

        return d;
    }


    static matrix4 makePerspectiveOffCenterLH(
        f32 l, f32 r,
        f32 b, f32 t,
        f32 n, f32 f)
    {
        matrix4 m;
        m.makeIdentity();

        m(0,0) =  2.0f * n / (r - l);
        m(0,1) =  0.0f;
        m(0,2) =  0.0f;
        m(0,3) =  0.0f;

        m(1,0) =  0.0f;
        m(1,1) =  2.0f * n / (t - b);
        m(1,2) =  0.0f;
        m(1,3) =  0.0f;

        m(2,0) = (l + r) / (l - r);
        m(2,1) = (t + b) / (b - t);
        m(2,2) =  f / (f - n);
        m(2,3) =  1.0f;

        m(3,0) =  0.0f;
        m(3,1) =  0.0f;
        m(3,2) = -n * f / (f - n);
        m(3,3) =  0.0f;

        return m;
    }


    void updateCameras()
    {
        const vector3df baseDir = getBaseDirection();

        vector3df up(0, 1, 0);
        up -= baseDir * up.dotProduct(baseDir);
        up.normalize();

        CamLeft->setPosition(Position);
        CamLeft->setTarget(Position + baseDir);
        CamLeft->setUpVector(up);

        CamRight->setPosition(Position);
        CamRight->setTarget(Position + baseDir);
        CamRight->setUpVector(up);

        const f32 n = CamLeft->getNearValue();
        const f32 f = CamLeft->getFarValue();

        const f32 halfVAngleRad = 26.565f * core::DEGTORAD;
        const f32 halfH         = n * tanf(halfVAngleRad);
        const f32 halfW         = 2.0f * halfH;

        const matrix4 projLeft =
            makePerspectiveOffCenterLH(
                -halfW,  0.0f,
                -halfH,  halfH,
                 n,      f);

        const matrix4 projRight =
            makePerspectiveOffCenterLH(
                 0.0f,   halfW,
                -halfH,  halfH,
                 n,      f);

        CamLeft ->setProjectionMatrix(projLeft,  false);
        CamRight->setProjectionMatrix(projRight, false);
    }


    ICameraSceneNode* CamLeft;
    ICameraSceneNode* CamRight;

    vector3df Position;

    f32 Yaw;
    f32 Pitch;

    f32 MoveSpeed;
    f32 MouseSensitivity;

    ICursorControl* CursorControl;
    s32 CenterX;
    s32 CenterY;
    s32 ScreenW;
    s32 ScreenH;
    s32 EdgeMargin;

    s32 LastMouseX;
    s32 LastMouseY;

    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};


// -----------------------------------------------------------------------------
// Draw one screen-aligned textured quad.
// -----------------------------------------------------------------------------
static void drawScreenQuad(
    IVideoDriver* driver,
    ITexture* tex,
    f32 x0, f32 y0, f32 x1, f32 y1)
{
    const SColor white(255, 255, 255, 255);

    S3DVertex v[4];

    v[0] = S3DVertex(x0, y0, 0.f, 0.f, 0.f, 1.f, white, 0.f, 0.f);
    v[1] = S3DVertex(x1, y0, 0.f, 0.f, 0.f, 1.f, white, 1.f, 0.f);
    v[2] = S3DVertex(x1, y1, 0.f, 0.f, 0.f, 1.f, white, 1.f, 1.f);
    v[3] = S3DVertex(x0, y1, 0.f, 0.f, 0.f, 1.f, white, 0.f, 1.f);

    const u16 idx[6] = { 0, 1, 2,  0, 2, 3 };

    SMaterial drawMat;
    drawMat.Lighting         = false;
    drawMat.ZBuffer          = ECFN_DISABLED;
    drawMat.ZWriteEnable     = EZW_OFF;
    drawMat.MaterialType     = EMT_SOLID;
    drawMat.TextureLayer[0].Texture            = tex;
    drawMat.TextureLayer[0].BilinearFilter     = false;
    drawMat.TextureLayer[0].TrilinearFilter    = false;
    drawMat.TextureLayer[0].AnisotropicFilter  = 0;
    drawMat.TextureLayer[0].TextureWrapU       = ETC_CLAMP_TO_EDGE;
    drawMat.TextureLayer[0].TextureWrapV       = ETC_CLAMP_TO_EDGE;
    drawMat.TextureLayer[0].LODBias            = 0;

    driver->setMaterial(drawMat);

    driver->drawVertexPrimitiveList(
        v, 4,
        idx, 2,
        EVT_STANDARD,
        EPT_TRIANGLES);
}


// -----------------------------------------------------------------------------
// MAIN
// -----------------------------------------------------------------------------
int main()
{
    IrrlichtDevice* device =
        createDevice(
            video::EDT_DIRECT3D9,
            dimension2d<u32>(1920, 1080),
            32,
            false,
            false,
            false,
            0);

    if (!device)
        return 1;

    IVideoDriver*    driver = device->getVideoDriver();
    ISceneManager*   smgr   = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

    driver->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);

    IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");

    if (!mesh)
    {
        device->drop();
        return 1;
    }

    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);

    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialFlag(EMF_BILINEAR_FILTER, false);
        node->setMaterialTexture(
            0,
            driver->getTexture("../../media/sydney.bmp"));
    }

    ICameraSceneNode* camLeft = smgr->addCameraSceneNode();
    camLeft->setNearValue(1.0f);
    camLeft->setFarValue(400.0f);

    ICameraSceneNode* camRight = smgr->addCameraSceneNode();
    camRight->setNearValue(1.0f);
    camRight->setFarValue(400.0f);

    const u32 RT_SIZE = 128 - 32;

    ITexture* rtLeft =
        driver->addRenderTargetTexture(
            dimension2d<u32>(RT_SIZE, RT_SIZE), "rtLeft");

    ITexture* rtRight =
        driver->addRenderTargetTexture(
            dimension2d<u32>(RT_SIZE, RT_SIZE), "rtRight");

    if (!rtLeft || !rtRight)
    {
        device->drop();
        return 1;
    }

    ICursorControl* cursorControl = device->getCursorControl();

    const s32 screenW = (s32)driver->getScreenSize().Width;
    const s32 screenH = (s32)driver->getScreenSize().Height;
    const s32 centerX = screenW / 2;
    const s32 centerY = screenH / 2;

    TwoViewportController controller(
        camLeft,
        camRight,
        vector3df(0, 20, -40),
        vector3df(0, 5, 0),
        cursorControl,
        centerX,
        centerY,
        screenW,
        screenH,
        30.0f,     // move speed
        0.15f,     // mouse sensitivity
        100);      // edge margin for recentering

    device->setEventReceiver(&controller);

    if (cursorControl)
    {
        cursorControl->setVisible(false);
        cursorControl->setPosition(centerX, centerY);
    }

    IGUIStaticText* fpsText =
        guienv->addStaticText(
            L"FPS: 0",
            rect<s32>(10, 10, 160, 30),
            false, false, 0, -1, true);

    fpsText->setOverrideColor(SColor(255, 255, 255, 0));
    fpsText->setBackgroundColor(SColor(160, 0, 0, 0));

    u32 lastTime = device->getTimer()->getTime();

    while (device->run())
    {
        const u32 now = device->getTimer()->getTime();
        const f32 dt  = (f32)(now - lastTime) / 1000.0f;
        lastTime = now;

        controller.update(dt);

        driver->beginScene(true, true, SColor(255, 0, 0, 0));

        driver->setRenderTarget(rtLeft, true, true, SColor(255, 0, 0, 0));
        smgr->setActiveCamera(camLeft);
        smgr->drawAll();

        driver->setRenderTarget(rtRight, true, true, SColor(255, 0, 0, 0));
        smgr->setActiveCamera(camRight);
        smgr->drawAll();

        driver->setRenderTarget(0, false, false);

        const dimension2d<u32> screenSize = driver->getScreenSize();
        const s32 W = (s32)screenSize.Width;
        const s32 H = (s32)screenSize.Height;

        driver->setViewPort(rect<s32>(0, 0, W, H));

        s32 totalW, totalH;

        if (W / 2 <= H) { totalW = W; totalH = W / 2; }
        else            { totalH = H; totalW = H * 2; }

        const s32 offsetX = (W - totalW) / 2;
        const s32 offsetY = (H - totalH) / 2;
        const s32 halfW   = totalW / 2;

        matrix4 ortho;
        ortho.makeIdentity();
        ortho[0]  =  2.0f / (f32)W;
        ortho[5]  = -2.0f / (f32)H;
        ortho[12] = -1.0f;
        ortho[13] =  1.0f;

        matrix4 identity;
        identity.makeIdentity();

        driver->setTransform(ETS_PROJECTION, ortho);
        driver->setTransform(ETS_VIEW,       identity);
        driver->setTransform(ETS_WORLD,      identity);

        drawScreenQuad(driver, rtLeft,
            (f32)offsetX, (f32)offsetY,
            (f32)(offsetX + halfW), (f32)(offsetY + totalH));

        drawScreenQuad(driver, rtRight,
            (f32)(offsetX + halfW), (f32)offsetY,
            (f32)(offsetX + totalW), (f32)(offsetY + totalH));

        core::stringw fpsStr = L"FPS: ";
        fpsStr += driver->getFPS();
        fpsText->setText(fpsStr.c_str());

        guienv->drawAll();

        driver->endScene();
    }

    device->drop();
    return 0;
}

My programme actually works fine as I don’t use any shaders – just what d3d9 offers by default – but I’ve come across this issue. I’d still like to sort it out as I want to add the bloom effect soon. Has anyone managed to fix this?
thanks :mrgreen: :mrgreen:
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Noiecity
Posts: 422
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by Noiecity »

I modify the CD3D9ShaderMaterialRenderer.cpp from source with:

Code: Select all

bool CD3D9ShaderMaterialRenderer::createVertexShader(const char* vtxsh)
{
	if (!vtxsh)
		return true;

	// Mostrar el código fuente del vertex shader
	os::Printer::log("Vertex shader source:", ELL_INFORMATION);
	os::Printer::log(vtxsh, ELL_INFORMATION);

	// compile shader

	LPD3DXBUFFER code = 0;
	LPD3DXBUFFER errors = 0;

	#ifdef _IRR_D3D_NO_SHADER_DEBUGGING

		// compile shader without debug info
		stubD3DXAssembleShader(
			vtxsh,
			(UINT)strlen(vtxsh),
			0,
			0,
			0,
			&code,
			&errors
		);

	#else

		// compile shader and emit some debug information to
		// make it possible to debug the shader in visual studio

		static int irr_dbg_file_nr = 0;
		++irr_dbg_file_nr;

		char tmp[32];
		snprintf_irr(
			tmp,
			sizeof(tmp),
			"irr_d3d9_dbg_shader_%d.vsh",
			irr_dbg_file_nr
		);

		FILE* f = fopen(tmp, "wb");

		if (f)
		{
			fwrite(vtxsh, strlen(vtxsh), 1, f);
			fflush(f);
			fclose(f);
		}

		stubD3DXAssembleShaderFromFile(
			tmp,
			0,
			0,
			D3DXSHADER_DEBUG,
			&code,
			&errors
		);

	#endif


	if (errors)
	{
		os::Printer::log(
			"Vertex shader compilation failed:",
			ELL_ERROR
		);

		os::Printer::log(
			(c8*)errors->GetBufferPointer(),
			ELL_ERROR
		);

		if (code)
			code->Release();

		errors->Release();

		return false;
	}


	if (!code)
	{
		os::Printer::log(
			"Could not compile vertex shader: no bytecode generated.",
			ELL_ERROR
		);

		return false;
	}

	HRESULT hr = pID3DDevice->CreateVertexShader(
		(DWORD*)code->GetBufferPointer(),
		&VertexShader
	);

	if (FAILED(hr))
	{
		char msg[128];

		snprintf_irr(
			msg,
			sizeof(msg),
			"Could not create vertex shader. HRESULT = 0x%08X",
			(unsigned int)hr
		);

		os::Printer::log(msg, ELL_ERROR);

		code->Release();

		return false;
	}

	code->Release();

	return true;
}
The result now:

Irrlicht Engine version 1.9.0
Microsoft Windows 8 or later (Build 9200)
Using renderer: Direct3D 9.0
NVIDIA GeForce RTX 3050 6GB Laptop GPU nvldumd.dll 32.0.15.9180
At least available dedicated+shared system texture memory (kB): 4177920
Vertex shader source:
;Irrlicht Engine 0.8 D3D9 render path normal map vertex shader
; c0-3: Transposed world matrix
; c8-11: Transposed worldViewProj matrix (Projection * View * World)
; c12: Light01 position
; c13: x,y,z: Light01 color; .w: 1/(LightRadius*LightRadius)
; c14: Light02 position
; c15: x,y,z: Light02 color; .w: 1/(LightRadius*LightRadius)
vs.1.1
dcl_position v0 ; position
dcl_normal v1 ; normal
dcl_color v2 ; color
dcl_texcoord0 v3 ; texture coord
dcl_texcoord1 v4 ; tangent
dcl_texcoord2 v5 ; binormal

def c95, 0.5, 0.5, 0.5, 0.5 ; used for moving light vector to ps

m4x4 oPos, v0, c8 ; transform position to clip space with worldViewProj matrix

m3x3 r5, v4, c0 ; transform tangent U
m3x3 r7, v1, c0 ; transform normal W
m3x3 r6, v5, c0 ; transform binormal V

m4x4 r4, v0, c0 ; vertex into world position
add r2, c12, -r4 ; vtxpos - lightpos1
add r3, c14, -r4 ; vtxpos - lightpos2

dp3 r8.x, r5, r2 ; transform the light vector 1 with U, V, W
dp3 r8.y, r6, r2
dp3 r8.z, r7, r2
dp3 r9.x, r5, r3 ; transform the light vector 2 with U, V, W
dp3 r9.y, r6, r3
dp3 r9.z, r7, r3

dp3 r8.w, r8, r8 ; normalize light vector 1 (r8)
rsq r8.w, r8.w
mul r8, r8, r8.w
dp3 r9.w, r9, r9 ; normalize light vector 2 (r9)
rsq r9.w, r9.w
mul r9, r9, r9.w

mad oT2.xyz, r8.xyz, c95, c95 ; move light vector 1 from -1..1 into 0..1
mad oT3.xyz, r9.xyz, c95, c95 ; move light vector 2 from -1..1 into 0..1

; calculate attenuation of light 1
dp3 r2.x, r2.xyz, r2.xyz ; r2.x = r2.x*r2.x + r2.y*r2.y + r2.z*r2.z
mul r2.x, r2.x, c13.w ; r2.x * attenuation
rsq r2, r2.x ; r2.xyzw = 1/sqrt(r2.x * attenuation)
mul oD0, r2, c13 ; resulting light color = lightcolor * attenuation

; calculate attenuation of light 2
dp3 r3.x, r3.xyz, r3.xyz ; r3.x = r3.x*r3.x + r3.y*r3.y + r3.z*r3.z
mul r3.x, r3.x, c15.w ; r2.x * attenuation
rsq r3, r3.x ; r2.xyzw = 1/sqrt(r2.x * attenuation)
mul oD1, r3, c15 ; resulting light color = lightcolor * attenuation

mov oT0.xy, v3.xy ; move out texture coordinates 1
mov oT1.xy, v3.xy ; move out texture coordinates 2
mov oD0.a, v2.a ; move out original alpha value


Could not compile vertex shader: no bytecode generated.
Vertex shader source:
;Irrlicht Engine 0.10 D3D9 render path parallax mapping vertex shader
; c0-3: Transposed world matrix
; c4: Eye position
; c8-11: Transposed worldViewProj matrix (Projection * View * World)
; c12: Light01 position
; c13: x,y,z: Light01 color; .w: 1/(LightRadius*LightRadius)
; c14: Light02 position
; c15: x,y,z: Light02 color; .w: 1/(LightRadius*LightRadius)
vs.1.1
dcl_position v0 ; position
dcl_normal v1 ; normal
dcl_color v2 ; color
dcl_texcoord0 v3 ; texture coord
dcl_texcoord1 v4 ; tangent
dcl_texcoord2 v5 ; binormal

def c95, 0.5, 0.5, 0.5, 0.5 ; used for moving light vector to ps
def c96, -1, 1, 1, 1 ; somewhere I've got a bug. flipping the vectors with this fixes it.

m4x4 oPos, v0, c8 ; transform position to clip space with worldViewProj matrix

m3x3 r5, v4, c0 ; transform tangent U
m3x3 r7, v1, c0 ; transform normal W
m3x3 r6, v5, c0 ; transform binormal V

m4x4 r4, v0, c0 ; vertex into world position
add r2, c12, -r4 ; vtxpos - light1 pos
add r3, c14, -r4 ; vtxpos - light2 pos
add r1, -c4, r4 ; eye - vtxpos

dp3 r8.x, r5, r2 ; transform the light1 vector with U, V, W
dp3 r8.y, r6, r2
dp3 r8.z, r7, r2
dp3 r9.x, r5, r3 ; transform the light2 vector with U, V, W
dp3 r9.y, r6, r3
dp3 r9.z, r7, r3
dp3 r10.x, r5, r1 ; transform the eye vector with U, V, W
dp3 r10.y, r6, r1
dp3 r10.z, r7, r1

dp3 r8.w, r8, r8 ; normalize light vector 1 (r8)
rsq r8.w, r8.w
mul r8, r8, r8.w
;mul r8, r8, c96
dp3 r9.w, r9, r9 ; normalize light vector 2 (r9)
rsq r9.w, r9.w
mul r9, r9, r9.w
;mul r9, r9, c96
dp3 r10.w, r10, r10 ; normalize eye vector (r10)
rsq r10.w, r10.w
mul r10, r10, r10.w
mul r10, r10, c96


mad oT2.xyz, r8.xyz, c95, c95 ; move light vector 1 from -1..1 into 0..1
mad oT3.xyz, r9.xyz, c95, c95 ; move light vector 2 from -1..1 into 0..1
mad oT4.xyz, r10.xyz, c95, c95 ; move eye vector from -1..1 into 0..1

; calculate attenuation of light 1
dp3 r2.x, r2.xyz, r2.xyz ; r2.x = r2.x*r2.x + r2.y*r2.y + r2.z*r2.z
mul r2.x, r2.x, c13.w ; r2.x * attenuation
rsq r2, r2.x ; r2.xyzw = 1/sqrt(r2.x * attenuation)
mul oD0, r2, c13 ; resulting light color = lightcolor * attenuation

; calculate attenuation of light 2
dp3 r3.x, r3.xyz, r3.xyz ; r3.x = r3.x*r3.x + r3.y*r3.y + r3.z*r3.z
mul r3.x, r3.x, c15.w ; r2.x * attenuation
rsq r3, r3.x ; r2.xyzw = 1/sqrt(r2.x * attenuation)
mul oD1, r3, c15 ; resulting light color = lightcolor * attenuation

mov oT0.xy, v3.xy ; move out texture coordinates 1
mov oT1.xy, v3.xy ; move out texture coordinates 2
mov oD0.a, v2.a ; move out original alpha value


Could not compile vertex shader: no bytecode generated.
Resizing window (1920 1061)
Resetting D3D9 device.
Irrlicht is love, Irrlicht is life, long live to Irrlicht
CuteAlien
Admin
Posts: 10054
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by CuteAlien »

Sorry, don't know about shader code right now, not sure I still have a system with 32-bit Code::Blocks.
There was once a tutorial for compiling D3D9 with MinGW, maybe there's some useful info in there: https://web.archive.org/web/20140703204 ... 9WithMinGW

Also if you get shaders working - easier to work with hi-level shaders (hlsl). I don't think there's too many people around still remembering the low level assembly stuff (I never learned that myself at least).

I fixed the nullptr stuff, sorry - slipped in some day, I'm so used to using those that I sometimes forget to not use them when I'm on Irrlicht.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Noiecity
Posts: 422
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by Noiecity »

CuteAlien wrote: Tue Sep 22, 2026 11:11 am Sorry, don't know about shader code right now, not sure I still have a system with 32-bit Code::Blocks.
There was once a tutorial for compiling D3D9 with MinGW, maybe there's some useful info in there: https://web.archive.org/web/20140703204 ... 9WithMinGW

Also if you get shaders working - easier to work with hi-level shaders (hlsl). I don't think there's too many people around still remembering the low level assembly stuff (I never learned that myself at least).

I fixed the nullptr stuff, sorry - slipped in some day, I'm so used to using those that I sometimes forget to not use them when I'm on Irrlicht.
Thank you for the link; I’m always very grateful to you
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Noiecity
Posts: 422
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by Noiecity »

Right, I can see it’s happening with Visual Studio too; on Windows 11, it doesn’t load any of Irrlicht’s default shaders in DirectX 9 (I haven’t tried my own shaders yet). Well, never mind, as long as the basic DirectX 9 works, that’s fine by me. I tried Irrlicht 1.8.5, and exactly the same thing happens. On Windows 10 and Windows 7 I didn’t have this bloody problem. So, I’ll switch to OpenGL, or carry on using DirectX 9. DirectX 9 gives me about 200 fps more in the same examples (in fact, at low resolutions, up to 1,400 fps more) – it’s always like that, so I’ll stick with it. (Although it doesn’t actually run DirectX 9; it runs modern DirectX and simply translates the DirectX 9 calls. I suppose the default DirectX 9 pipeline is fairly lightweight to translate.)
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Noiecity
Posts: 422
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by Noiecity »

Interestingly, this doesn’t happen in Irrlicht 1.6.1 (everything works fine in D3D9); this leads me to believe that, from a certain version onwards, Irrlicht attempts to compile with modern versions of DirectX9(as it asks for d3dx9_43, regardless of whether I use other libraries or different versions), and these versions are more demanding in terms of the shader model used

Image

Image

The same thing happened in Windows XP; Windows XP came with D3D9 by default, which was the same version used by Irrlicht 1.6.1, so the examples ran without having to install anything (you had to install the modern version of D3D9 to run Irrlicht 1.8.5 examples). Perhaps my problem will be solved by installing D3D9 (perhaps Windows 11 comes with the same version as XP by default).

I remember that on Windows XP I sorted this out simply by downloading and using an old DirectX SDK (2004); I’ll try the same with GCC – perhaps that will solve the problem.

The other option is simply to install the directx_Jun2010_redist.exe and ensure that others install it too as a minimum requirement for running my application (which isn’t a bad option, given that DirectX 9 may have undergone optimisation changes)
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Noiecity
Posts: 422
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by Noiecity »

Image

All issues can be resolved by installing directx_Jun2010_redist.exe(95mb) on the computer on which the application will run.

Image

You do not need to install any DirectX SDK to compile in modern CodeBlocks; just make sure you install the 32-bit version of CodeBlocks if you are compiling for 32-bit systems.

Make sure you link d3dx9, dxguid and dinput8 (these are already included in the version of CodeBlocks that comes with the compiler and MinGW).

Make sure that when you compile the source code, IRR_COMPILE_WITH_DX9_DEV_PACK is defined. It should look something like this:

Code: Select all

WIN32
NDEBUG
_WINDOWS
_USRDLL
IRRLICHT_EXPORTS
_CRT_SECURE_NO_DEPRECATE
__GNUWIN32__
IRR_COMPILE_WITH_DX9_DEV_PACK
(Win32 - Release - fast math - dll).

Make sure the following compiler options are enabled:
-static-libgcc
-static-libstdc++
-static

This is because, if you do not do so, you will encounter errors regarding missing C++-related .dll files; this ensures you have a portable application.
Irrlicht is love, Irrlicht is life, long live to Irrlicht
CuteAlien
Admin
Posts: 10054
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by CuteAlien »

Thanks for the info. I have to admit I'm a bit lost myself when it comes to get D3D9 working. Basically I have to figure it out only once when installing a new PC (which I rarely do). I thought I didn't have to install DXSDK_Jun10 anymore on my current Windows 11 PC and it just worked somehow. But just looked in my Download folder and that DXSDK_Jun10 installer is there... so I probably did that as well and just forgot about it again over the years.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Noiecity
Posts: 422
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: How to fix: Could not create vertex shader in irrlicht?

Post by Noiecity »

By the way, the changes I suggested to CD3D9ShaderMaterialRenderer.cpp were just so I could see what I was trying to compile that was failing; I don’t recommend applying them (it was just to show how I obtained that information).

Thanks anyway
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Post Reply