Thread: Applying Light to Textures (DirectX 9)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039

    Applying Light to Textures (DirectX 9)

    Hey guys. You're probably going to laugh at me and tell me to read a book on DirectX(which I probably *should*...well I read one on DX6 when I was youngster whilst actively posting on this site, but forgot essentially everything), because I'm developing a game engine and all is going well -- except for one crucial aspect -- lighting. Now in DirectX we all know lighting is one of the easiest aspects -- I've implemented physics, my own mesh loader, etc, now, I've always been an OpenGL programmer, but it seems I've committed myself to DirectX 9 for my engine for a multitude of reasons -- I love being able to pass D3D device pointers into other functions, I love the entire built-in .X mesh concept, but I absolutely hate vertex/index buffers(which I don't have a complete grasp on as yet), and I'm not using DX11 because I want older PC's to be able to run my crappy games. Anyway, part of my engine borrows code from xbdev.net's BSP header file to read BSP tree maps(The guy is a genius in my eyes).
    I've uploaded bsp.h here: bsp.h - Google Drive

    Screenshot of my engine thus far: game01.jpg - Google Drive

    Screenshot of the same thing but with a mesh rotation, and in an futile attempt to influence lighting, I've changed the FVF format for the texture: game02.jpg - Google Drive

    Within this header file is DrawFace(), where the textures are applied and polygons rendered according to a certain point. Now, I've been able to do just about everything within my engine, except *lighting*( in the traditional sense, at least, I could be cheap with this and just draw a large texture over the screen, apply alpha and use that texture to darken/lighten the screen, as you can see with my debug console), but I want to be able to influence lighting on the BSP map that is rendered.

    Point is, there is *nowhere* in my source code where I have implemented an actual lightsource. I've disabled using materials, my light function is commented out, I've been trying *everything* to somehow influence lighting on the textures being rendered on the map, even screwing with the FVF as you can see in the second screenshot. I've put code for directional, spotlight, any kind of lighting you can think of *right before* the primitive is drawn for each polygon, within the DrawFace() function, that's how desperate I've become.

    I concede to the fact that I am in over my head here, that if I want a real game engine I should understand the API a lot better than I do, but I'm one of those sink-or-swim people and it's beyond help at this point, I drive myself mad. So when it comes to DirectX, I am retard-dumb. Caveman grunt, jaw dropping on the ground knuckle-dragging idiot knocking an engine together. So I need answers from you fine gentlemen in ways I can understand.

    I know that in the vertex format for textured primitives there are normals, perpendicular to the face itself to reflect light, and I should somehow use this to influence lighting -- I've tried everything here folks. I wouldn't be coming here admitting defeat if I wasn't at my wits end.

    Code such as the following I've tinkered with a thousand times, in my render() function, and even in the BSP's :rawFace() and ::RenderAllFace() functions:

    Hey guys. You're probably going to laugh at me and tell me to read a book on DirectX(which I probably *should*), because I'm developing a game engine and all is going well -- except for one crucial aspect -- lighting. Now in DirectX we all know lighting is one of the easiest aspects -- I've implemented physics, my own mesh loader, etc, now, I've always been an OpenGL programmer, but it seems I've committed myself to DirectX 9 for my engine for a multitude of reasons -- I love being able to pass D3D device pointers into other functions, I love the entire built-in .X mesh concept, but I absolutely hate vertex/index buffers(which I don't have a complete grasp on as yet), and I'm not using DX11 because I want older PC's to be able to run my crappy games. Anyway, part of my engine borrows code from xbdev.net's BSP header file to read BSP tree maps(The guy is a genius in my eyes).
    I've uploaded bsp.h here: bsp.h - Google Drive

    Screenshot of my engine thus far: game01.jpg - Google Drive

    Screenshot of the same thing but with a mesh rotation, and in an futile attempt to influence lighting, I've changed the FVF format for the texture: game02.jpg - Google Drive

    Within this header file is DrawFace(), where the textures are applied and polygons rendered according to a certain point. Now, I've been able to do just about everything within my engine, except *lighting*( in the traditional sense, at least, I could be cheap with this and just draw a large texture over the screen, apply alpha and use that texture to darken/lighten the screen, as you can see with my debug console), but I want to be able to influence lighting on the BSP map that is rendered.

    Point is, there is *nowhere* in my source code where I have implemented an actual lightsource. I've disabled using materials, my light function is commented out, I've been trying *everything* to somehow influence lighting on the textures being rendered on the map, even screwing with the FVF as you can see in the second screenshot. I've put code for directional, spotlight, any kind of lighting you can think of *right before* the primitive is drawn for each polygon, within the DrawFace() function, that's how desperate I've become.

    I concede to the fact that I am in over my head here, that if I want a real game engine I should understand the API a lot better than I do, but I'm one of those sink-or-swim people and it's beyond help at this point, I drive myself mad. So when it comes to DirectX, I am retard-dumb. Caveman grunt, jaw dropping on the ground knuckle-dragging idiot knocking an engine together. So I need answers from you fine gentlemen in ways I can understand.

    I know that in the vertex format for textured primitives there are normals, perpendicular to the face itself to reflect light, and I should somehow use this to influence lighting -- I've tried everything here folks. I wouldn't be coming here admitting defeat if I wasn't at my wits end.

    Code such as the following I've tinkered with a thousand times, in my render() function, and even in the BSP's :rawFace() and ::PVSRender() functions:

    Code:
    D3DLIGHT9 light;
    	D3DMATERIAL9 material;
    
    	ZeroMemory(&light, sizeof(light));
    	ZeroMemory(&light, sizeof(light));
    	light.Type = D3DLIGHT_SPOT;    // make the light type 'spot light'
    	light.Diffuse = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);
    	light.Position = g_vCamPosition;
    	light.Direction = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
    	light.Range = 1000.0f;    // a range of 100
    	light.Attenuation0 = 0.0f;    // no constant inverse attenuation
    	light.Attenuation1 = 0.125f;    // only .125 inverse attenuation
    	light.Attenuation2 = 0.0f;    // no square inverse attenuation
    	light.Phi = D3DXToRadian(40.0f);    // set the outer cone to 30 degrees
    	light.Theta = D3DXToRadian(20.0f);    // set the inner cone to 10 degrees
    	light.Falloff = 1.0f;    // use the typical falloff
    
    	g_pd3dDevice->SetLight(0, &light);
    	g_pd3dDevice->LightEnable(0, TRUE);
    
    	ZeroMemory(&material, sizeof(D3DMATERIAL9));
    	material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
    	material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
    
    	g_pd3dDevice->SetMaterial(&material);
    I'm not saying that the above is even the appropriate code, it's just a quick example of a copy-paste of one of my failed attempts. It does *not* matter what variables, flags, or functions I use for my material/light, it does not influence my game whatsoever, because my game is 100% being lit by textures being read, and that is the light itself. My 3D meshes have jpeg/png's for textures, so they're not influenced, and nor is the map -- the light I get is the light that is emitted from the textures themselves. The only time my light/material's are influencing my game is when I'm at the end of my map looking out into space, and they change colors. That's it.

    Look within DrawFace(), or bsp.h as a whole -- what can I do to influence lighting of these textures? Could someone provide me with example code? I'd really, really, appreciate it. I've been up 48 hours trying everything.

    Please. Help. I have no idea what to do at this point and I am at a loss, and I'm not going to resort to blanketing my game with alpha'd primitives to try and give the illusion of lighting. I really need your guys help with this one, you people are brilliant.

    Thanks so much!

    And yes, Salem, I have cross-posted on cplusplus.com, they don't have the proper forum for such a question and I'm looking for expediency =) (And *this* is where I truly belong anyway!) <3
    Last edited by Xterria; 12-20-2019 at 09:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX : Problem related to applying transformations
    By N Jagdish in forum Game Programming
    Replies: 4
    Last Post: 12-06-2011, 06:36 PM
  2. applying formula help please
    By farah0718 in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2008, 05:07 AM
  3. Applying windows to walls?
    By dxfoo in forum Game Programming
    Replies: 4
    Last Post: 09-29-2006, 11:59 PM
  4. DirectX 8 Transparent Textures
    By poopy_pants2 in forum Game Programming
    Replies: 14
    Last Post: 04-17-2003, 07:59 PM

Tags for this Thread