• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
hamsham

OpenGL
Hypothesizing a new lighting method.

18 posts in this topic

Hi Everybody. This is my first post so please be nice. I'm new to graphics programming with OpenGL and have only done basic tutorials thus far.

 

After going through the deferred rendering tutorial at http://ogldev.atspace.co.uk/, I was kind of left with the impression that the process of deferred lighting is a bit backwards. Forward rendering looks great with all lights but the only problem is that rendering everything causes an absurd amount of iteration (render time = light count * mesh count). Deferred rendering shows promise (light count + mesh count) but it also means that, in some implementations, you may have to drastically increase the amount of vertices rendered. Additionally, shadows are a bit more difficult to implement. I was thinking of another approach to rendering lights with the speed of deferred rendering but the visual quality of forward rendering.

Basically, there could be two cube maps stored on the GPU which could hold the color, intensity, and position of every light in a scene. The renderer would place every light of the scene into these cube maps in a first pass, then render each mesh in a second pass. The first cube map could add individual RGB and Intensity values of every light, clamped to four individual byte values while the second cube map could hold each light's position (clamped to 3 individual bytes). Next, after each light has been rendered to the cube maps, every mesh of the scene can sample them when they're processed in another pass by the pixel/fragment shader. This means that you get the speed of a deferred renderer (render time = light count + mesh count) with a drastically reduced memory footprint.

 

Would anyone be able to shed some light as to the plausibility of rendering a scene this way? Right now, I have calculated that both buffers would be a total size of about 2.6 Mb, which seems like a hell of a lot less than what is typically required by a deferred renderer. Like I said above, I'm a graphics novice; this is all just theory and I have no idea how it would be implemented in practice, I'm just looking for feedback.

 

My memory calculation is as follows:

4 bytes for the first cube map + 3 bytes for the second cube map = 7 total bytes per pixel, across both cubemaps (math whiz here).

Each cube map is made of 6 2D textures.

Each 2D texture is 256 pixels wide by 256 pixels high.

Therefore, the total memory used by the entire process is 7 bytes * 256 wide * 256 high * 6 textures = 2752512 bytes = 2.6 Mb total.

 

 

0

Share this post


Link to post
Share on other sites

That could only work for non positional lights.

I was initially going to test this with point lights but I guess I'll have to figure out how to add directional and spot lighting. Throwing more textures at the GPU in order to hold each light's properties will end up using as much memory as regular deferred rendering.
At least with point lights, the light vector could be calculated pretty easily (in the fragment shader) by getting the vector from the camera to a mesh and reflecting that against the mesh's surface so that you can find what light[s] to pluck out from the first cube map. Once you do that, then you could also extract the lights position from the second cube map.
0

Share this post


Link to post
Share on other sites

"This means that you get the speed of a deferred renderer (render time = light count + mesh count) with a drastically reduced memory footprint."

 

The speed of a deferred renderer has nothing to do with your algorithm at all. The speed in deferred comes in the fact that you run the pixel shader once for every pixel on the screen. You make pixel shader overdraw = 0. In your algorithm you would still draw an object with a pixel shader and then another object can come along and redraw over that pixel and have to run a pixel shader again (2x for the same pixel).

The algorithm itself doesnt make much sense to me. Why is it a cube map again? What does a mesh use to find the correct light in the cubemap? Why wouldnt it just be a 2D texture of the lights? How exactly does the light get mapped into the cubemap?(its not a 3d Array, its simply 6 faces that designate up down left righ bottom top.

Yes, you don't have the experience enough to finalize your algorithm. I'm planning to do something similar to this, however you have some holes to get to the end and you are in no way related to deferred rendering by this approach.

2

Share this post


Link to post
Share on other sites

The speed of a deferred renderer has nothing to do with your algorithm at all. The speed in deferred comes in the fact that you run the pixel shader once for every pixel on the screen. You make pixel shader overdraw = 0. In your algorithm you would still draw an object with a pixel shader and then another object can come along and redraw over that pixel and have to run a pixel shader again (2x for the same pixel).

 

In this, the pixel shader would be run once for every light to store it in the cube maps, then once more for every mesh when rendering to a final output buffer; just like a deferred renderer. Overdraw can occur regardless of what rendering method is used but it can be reduced if each object is sorted in the scene based on its position from the camera (but I'm not really worried about it at the moment).

 

 

The algorithm itself doesnt make much sense to me. Why is it a cube map again? What does a mesh use to find the correct light in the cubemap? Why wouldnt it just be a 2D texture of the lights? How exactly does the light get mapped into the cubemap?(its not a 3d Array, its simply 6 faces that designate up down left righ bottom top.

 

The lights would be stored in a cubemap for nothing more than indexing really. I imagine it to be a 3D lookup table to get an angle of incidence between the camera, a mesh, and a light in the scene.

 

So for the first pass on the scene, each light's position is stored in one cube map, then its RGB and intensity values in the other. Think of having a skybox but with a bunch of lights' colors and positions only. In order to actually get the data into the cubemaps, I was imagining having the 6 sides of the cube maps set up as render targets that would be bound to the output of a fragment shader.

 

After each light has been rendered to, then in a second fragment shader, a scene's meshes could be rendered to from the view of a camera. Then, as I noted earlier, you could find out how to color each fragment by getting a vector from the camera's position towards the mesh, reflect that vector off the mesh, and finally find which light that reflection vector is pointing at in the cube maps. Since each light's position is stored, you can determine how to color a fragment based on its position and intensity with regards to the final scene.

0

Share this post


Link to post
Share on other sites

Ideas are just that. Consider throwing together a prototype/proof of concept that actually shows the lighting method and relevant shaders, and perhaps allows for some preliminary verification and performance testing. Also consider looking into tiled forward rendering, as I think that's where things are headed in the future.

Edited by Promit
0

Share this post


Link to post
Share on other sites


In this, the pixel shader would be run once for every light to store it in the cube maps

 

Generally, a cubemap represents the scene from a certain view point. For instance, they can be used to render the scene around a point and used to draw rough environment reflections on objects. "rough" because it will only be accurate from one specific position in the scene. Of course it works well for things like a skybox (which is "infinitely" far away and looks the same from every point in the scene).

 

So... what exactly are you putting in your cubemap? Is the end result that there will be a single texel somewhere in the cubemap for each light?

 

 


you could find out how to color each fragment by getting a vector from the camera's position towards the mesh, reflect that vector off the mesh, and finally find which light that reflection vector is pointing at in the cube maps.

 

What are the chances that that reflection vector will line up exactly with the texel that contains the light information? Pretty small. Or does your cubemap contain large areas that cover a light's influence? If so, how would you handle overlapping lights?

 

(also, reflecting the eye vector off the mesh will help you calculate the specular component, what about diffuse?)

 

Maybe I'm just not understanding your description, but I still don't see how your algorithm makes any sense. As Promit suggested, try coming up with a proof of concept. I think it will quickly become obvious where things fall apart.

1

Share this post


Link to post
Share on other sites

I'm not going to go into much depth here, but almost everything you have said really shows your inexperience. Based on that, I would just say don't plan on doing this. You can make games look good with forward rendering, deferred whatever. Don't try to implement the greatest lighting model when you aren't fully grasping things. Really quickly:

"then once more for every mesh when rendering to a final output buffer; just like a deferred renderer."Overdraw can occur regardless of what rendering method is used"
Uh....deferred rendering has 0 pixel shader overdraw. The initial filling of the buffers of course will have some overdraw, but its not like its wasting time running crazy pixel shaders. All lighting shaders are run once for ever pixel. 0 pixel shader (lighting) overdraw.

"but it can be reduced if each object is sorted in the scene based on its position from the camera (but I'm not really worried about it at the moment)."
Yes. In a deferred renderer you would be doing this as well to reduce the G-Buffer initial pass overdraw, but not the lighting pass overdraw.

"Think of having a skybox but with a bunch of lights' colors and positions only."
So I have a 3d light: A and B.  A = vec3(-100,10,0) B = vec3(-110,10,0). Where would these be rendered into the cube map?  If you use simply their position as a vector to render to the cube map....they render to the same spot. A cube map is 6 2D textures, it is not a 3d array. A 3D array would be a cube map with slices cut through it. and even then an actual 3d Texture wouldnt work for your algorithm. Not going to explain to you why because I don't think you will get it.


"Then, as I noted earlier, you could find out how to color each fragment by getting a vector from the camera's position towards the mesh, reflect that vector off the mesh, and"
This wont work. If you are actually rendering the cube map lights as actual spherical geometry... then what you have essentially is cube mapping/environment mapping. But you would have to render all the lights each frame for each mesh. So much wrong with this algorithm.
And if you are talking about rendering geometry, what happens when 2 lights geometry overlap in the cube map?
 

0

Share this post


Link to post
Share on other sites

"What are the chances that that reflection vector will line up exactly with the texel that contains the light information? Pretty small. Or does your cubemap contain large areas that cover a light's influence? If so, how would you handle overlapping lights?"

 

Same thing I said pretty much. If you are only rendering to 1 pixel your light information, then it is still wrong. Noither approaches will work.

0

Share this post


Link to post
Share on other sites
Ok so I guess the idea needs a bit (or rather a lot) more work. Thanks you guys for the feedback, I'll try to rework my lighting method based on all your suggestions.
0

Share this post


Link to post
Share on other sites

I'd like to also put it on record that shadow mapping with deferred shading is no harder than it is with forward shading, and in fact many games use a very simple deferred approach for shadows (Crysis 1 for example) rather than applying shadows in the forward pass.

1

Share this post


Link to post
Share on other sites

This may only work at all if you sample "cones" rather than reflection vectors, and only for lights at infinity. Surfaces are not perfect mirrors, so one point on the screen that you look at does not correspond to exactly one point in the "sky" (i.e. the cubemap). It corresponds to an area. Unless you come up with something very clever (something like a distance map with a direction vector to the closest "cardinal light" might actually be an idea...) you will need to do a lot of samples so it looks kind of good -- and then it's cheaper to just do normal forward rendering and evaluating all lights as usual.

 

Also, if a light is not "at infinity", let's say 5 meters above you, then an object which is at your position and an object which is  5 meters away will get light from the same angle and with the same intensity. Which is... just wrong, and just looks very bad.

 

Also I'm afraid that you are trying to solve the wrong problem. First of all, forward shading doesn't look better than deferred shading. It will usually look somewhat different, but not necessarily "better" as such. The one big advantage of forward shading is that transparency is a no-brainer (and also antialiasing is easier to get working), but other than that there is no reason why correctly implemented deferred shading should look any worse. On the contrary, you can get a much more consistent lighting and put a lot more shader work into every pixel.

 

On the other hand, deferred shading is not faster.  It is more scaleable in respect of geometry and lights (in particular shadow-casting lights) at the expense of higher memory and bandwidth demands. Deferred shading has a complexity of numbers of lights multiplied with [at most] the resolution plus a more-or-less constant setup, instead of numbers of lights multiplied with number of vertices. Also, deferred shading (if no such thing as clustered DS is done) needs one shadow map at a time, for the one light that is currently being shaded whereas forward shading needs shadow maps for all lights that may affect any of the drawn geometry at once.

0

Share this post


Link to post
Share on other sites

First of all, forward shading doesn't look better than deferred shading. It will usually look somewhat different, but not necessarily "better" as such. The one big advantage of forward shading is that transparency is a no-brainer (and also antialiasing is easier to get working), but other than that there is no reason why correctly implemented deferred shading should look any worse. On the contrary, you can get a much more consistent lighting and put a lot more shader work into every pixel.

 

Most deferred renderers will sacrifice some precision with normals, position(depth reconstruction is not 100% accurate) and with other paramaters that can cause some quality loss on final image. Luckily this is mostly last gen games where this is visible.

0

Share this post


Link to post
Share on other sites

This technique would work for the one point in the scene that you render as the center of the cube maps.  When you render the lights into the cube map, you're doing it relative to this one point.  So that one point would be lit correctly.  Everything else would be skewed.

0

Share this post


Link to post
Share on other sites

I used a technique on the Wii that's very similar to the one mentioned in the OP, to get lots of dynamic lights on it's crappy hardware... except, instead of global cube-maps for the scene, each object had it's own cube-map, so that directionality and attenuation worked properly (at least on a per-mesh granularity - not very good for large meshes). Also, instead of cube-maps, we used sphere-maps for simplicity.... and you can't just render a light into a single texel, you have to render a large diffused blob of light.

The lighting is obviously much more approximate than doing it traditionally per-pixel -- the surface normal is evaluated per-pixel, but the attenuation and direction to light are evaluated per mesh. This means that for small meshes, it's pretty good, but for large meshes, all lights start to look like directional lights.

The other down-side is that you can't use nice BRDF's like Blinn-Phong or anything...

 

In general, this is part of a family of techniques known as image based lighting, and yes, it's common to combine a bunch of non-primary lights into a cube-map, etc -- e.g. think of every pixel in your sky-dome as a small directional light. Using it as a replacement for primary lights, across an entire scene, is a bit less popular.

0

Share this post


Link to post
Share on other sites

I used a technique on the Wii that's very similar to the one mentioned in the OP, to get lots of dynamic lights on it's crappy hardware... except, instead of global cube-maps for the scene, each object had it's own cube-map, so that directionality and attenuation worked properly (at least on a per-mesh granularity - not very good for large meshes). Also, instead of cube-maps, we used sphere-maps for simplicity.... and you can't just render a light into a single texel, you have to render a large diffused blob of light.

The lighting is obviously much more approximate than doing it traditionally per-pixel -- the surface normal is evaluated per-pixel, but the attenuation and direction to light are evaluated per mesh. This means that for small meshes, it's pretty good, but for large meshes, all lights start to look like directional lights.

The other down-side is that you can't use nice BRDF's like Blinn-Phong or anything...

 

In general, this is part of a family of techniques known as image based lighting, and yes, it's common to combine a bunch of non-primary lights into a cube-map, etc -- e.g. think of every pixel in your sky-dome as a small directional light. Using it as a replacement for primary lights, across an entire scene, is a bit less popular.

For kinghunt http://www.youtube.com/watch?v=9mU-lcJnyvg

 

I did very similar trick but instead of sphere maps I used spherical harmonics. I also calculated aproximated visibility function per object against all other objects. This was so fast that even particles could be light emitters.

Edited by kalle_h
1

Share this post


Link to post
Share on other sites

While I can see how image-based lighting might work great on mobile devices, how do these translate to desktops where the ALU/TEX ratio is much higher? I would guess that using literally abundant ALU to compute a dozen lights that are visible from one fragment may very well be faster than to do yet an additional texture lookup?

0

Share this post


Link to post
Share on other sites

While I can see how image-based lighting might work great on mobile devices, how do these translate to desktops where the ALU/TEX ratio is much higher? I would guess that using literally abundant ALU to compute a dozen lights that are visible from one fragment may very well be faster than to do yet an additional texture lookup?

In console/PC games, it's standard to use IBL for background/fill/bounce/ambient lights (GI), instead of a flat ambient colour, and then compute the direct lighting analytically.

 

For film-quality IBL, you don't pre-convolve the probes, and each pixel has to read thousands of importance-sampled values from the IBL probes and integrate them using the BRDF (which is both ALU and TEX heavy)...

1

Share this post


Link to post
Share on other sites

 

While I can see how image-based lighting might work great on mobile devices, how do these translate to desktops where the ALU/TEX ratio is much higher? I would guess that using literally abundant ALU to compute a dozen lights that are visible from one fragment may very well be faster than to do yet an additional texture lookup?

In console/PC games, it's standard to use IBL for background/fill/bounce/ambient lights (GI), instead of a flat ambient colour, and then compute the direct lighting analytically.

 

For film-quality IBL, you don't pre-convolve the probes, and each pixel has to read thousands of importance-sampled values from the IBL probes and integrate them using the BRDF (which is both ALU and TEX heavy)...

 

 

Which is why most people pre-convolve the probes. I'm not sure UE4 does, then again I'm not sure exactly what it is they're even doing. All I've gathered is "cube map array" and their ability to relight the probes in realtime.

0

Share this post


Link to post
Share on other sites

 

 

While I can see how image-based lighting might work great on mobile devices, how do these translate to desktops where the ALU/TEX ratio is much higher? I would guess that using literally abundant ALU to compute a dozen lights that are visible from one fragment may very well be faster than to do yet an additional texture lookup?

In console/PC games, it's standard to use IBL for background/fill/bounce/ambient lights (GI), instead of a flat ambient colour, and then compute the direct lighting analytically.

 

For film-quality IBL, you don't pre-convolve the probes, and each pixel has to read thousands of importance-sampled values from the IBL probes and integrate them using the BRDF (which is both ALU and TEX heavy)...

 

 

Which is why most people pre-convolve the probes. I'm not sure UE4 does, then again I'm not sure exactly what it is they're even doing. All I've gathered is "cube map array" and their ability to relight the probes in realtime.

 

 

They pre-convolve their specular probes, by convolving the specular BRDF with a given roughness assuming that V=N. They also take the standard approach of storing the results for different roughness values in the mip levels of the cubemap (higher roughnesses go into lower-res mip levels), and then selecting the mip per-pixel based on the surface roughness. They also refactored things a bit so that they can approximate the appropriate BRDF response for different viewing angles by precomputing values into lookup textures and indexing them at runtime. This sort of approach is becoming fairly common.

I'm not sure what they do for diffuse, but I would assume that they store SH probes which is what most people do these days. 

Edited by MJP
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By mapra99
      Hello

      I am working on a recent project and I have been learning how to code in C# using OpenGL libraries for some graphics. I have achieved some quite interesting things using TAO Framework writing in Console Applications, creating a GLUT Window. But my problem now is that I need to incorporate the Graphics in a Windows Form so I can relate the objects that I render with some .NET Controls.

      To deal with this problem, I have seen in some forums that it's better to use OpenTK instead of TAO Framework, so I can use the glControl that OpenTK libraries offer. However, I haven't found complete articles, tutorials or source codes that help using the glControl or that may insert me into de OpenTK functions. Would somebody please share in this forum some links or files where I can find good documentation about this topic? Or may I use another library different of OpenTK?

      Thanks!
    • By Solid_Spy
      Hello, I have been working on SH Irradiance map rendering, and I have been using a GLSL pixel shader to render SH irradiance to 2D irradiance maps for my static objects. I already have it working with 9 3D textures so far for the first 9 SH functions.
      In my GLSL shader, I have to send in 9 SH Coefficient 3D Texures that use RGBA8 as a pixel format. RGB being used for the coefficients for red, green, and blue, and the A for checking if the voxel is in use (for the 3D texture solidification shader to prevent bleeding).
      My problem is, I want to knock this number of textures down to something like 4 or 5. Getting even lower would be a godsend. This is because I eventually plan on adding more SH Coefficient 3D Textures for other parts of the game map (such as inside rooms, as opposed to the outside), to circumvent irradiance probe bleeding between rooms separated by walls. I don't want to reach the 32 texture limit too soon. Also, I figure that it would be a LOT faster.
      Is there a way I could, say, store 2 sets of SH Coefficients for 2 SH functions inside a texture with RGBA16 pixels? If so, how would I extract them from inside GLSL? Let me know if you have any suggestions ^^.
    • By KarimIO
      EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.
      Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?
      Update: No crash occurs if I don't draw, just clear and swap.
      static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // 24Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC = GetDC(windowHandle))) return false; unsigned int PixelFormat; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return false; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return false; hRC = wglCreateContext(hDC); if (!hRC) { std::cout << "wglCreateContext Failed!\n"; return false; } if (wglMakeCurrent(hDC, hRC) == NULL) { std::cout << "Make Context Current Second Failed!\n"; return false; } ... // OGL Buffer Initialization glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); glUseProgram(myprogram); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart); SwapBuffers(GetDC(window_handle));  
    • By Tchom
      Hey devs!
       
      I've been working on a OpenGL ES 2.0 android engine and I have begun implementing some simple (point) lighting. I had something fairly simple working, so I tried to get fancy and added color-tinting light. And it works great... with only one or two lights. Any more than that, the application drops about 15 frames per light added (my ideal is at least 4 or 5). I know implementing lighting is expensive, I just didn't think it was that expensive. I'm fairly new to the world of OpenGL and GLSL, so there is a good chance I've written some crappy shader code. If anyone had any feedback or tips on how I can optimize this code, please let me know.
       
      Vertex Shader
      uniform mat4 u_MVPMatrix; uniform mat4 u_MVMatrix; attribute vec4 a_Position; attribute vec3 a_Normal; attribute vec2 a_TexCoordinate; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { v_Position = vec3(u_MVMatrix * a_Position); v_TexCoordinate = a_TexCoordinate; v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); gl_Position = u_MVPMatrix * a_Position; } Fragment Shader
      precision mediump float; uniform vec4 u_LightPos["+numLights+"]; uniform vec4 u_LightColours["+numLights+"]; uniform float u_LightPower["+numLights+"]; uniform sampler2D u_Texture; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { gl_FragColor = (texture2D(u_Texture, v_TexCoordinate)); float diffuse = 0.0; vec4 colourSum = vec4(1.0); for (int i = 0; i < "+numLights+"; i++) { vec3 toPointLight = vec3(u_LightPos[i]); float distance = length(toPointLight - v_Position); vec3 lightVector = normalize(toPointLight - v_Position); float diffuseDiff = 0.0; // The diffuse difference contributed from current light diffuseDiff = max(dot(v_Normal, lightVector), 0.0); diffuseDiff = diffuseDiff * (1.0 / (1.0 + ((1.0-u_LightPower[i])* distance * distance))); //Determine attenuatio diffuse += diffuseDiff; gl_FragColor.rgb *= vec3(1.0) / ((vec3(1.0) + ((vec3(1.0) - vec3(u_LightColours[i]))*diffuseDiff))); //The expensive part } diffuse += 0.1; //Add ambient light gl_FragColor.rgb *= diffuse; } Am I making any rookie mistakes? Or am I just being unrealistic about what I can do? Thanks in advance
    • By yahiko00
      Hi,
      Not sure to post at the right place, if not, please forgive me...
      For a game project I am working on, I would like to implement a 2D starfield as a background.
      I do not want to deal with static tiles, since I plan to slowly animate the starfield. So, I am trying to figure out how to generate a random starfield for the entire map.
      I feel that using a uniform distribution for the stars will not do the trick. Instead I would like something similar to the screenshot below, taken from the game Star Wars: Empire At War (all credits to Lucasfilm, Disney, and so on...).

      Is there someone who could have an idea of a distribution which could result in such a starfield?
      Any insight would be appreciated
  • Popular Now