The circumstances to why I am forced to do things this way are a bit weird, without going into them, I have the following situation:

I have a pointer that points to image data arranged in the form ARGB, that is overlayed over a scene (2d) to give the ambient lighting and colour. What I need to do is blend in image data generated from lights so that the colours combine and each light makes the overlay more transparent based upon its intensity. Doing this pixel by pixel each frame is slow and bogs everything down, but it works just fine for static lights if done at load time (since they don't change, it doesn't need to be redone).

My final solution requires that the final combined overlay for the lighting be contained in the original pointer; so any method that requires using a different setup, or pulling the data from the pointer, then dumping it back in, might be problematic. I do not, unfortunately, have anyway to modify the source and am stuck passing everything thorough a call to a dll, so I have no other means of introducing lights that doesn't use this structure.

I'm working on Windows and using C++. I, also, want to point out that I am not a games programmer, though I am a programmer, so a lot of what I tried looking up is a bit foreign to me.

Thank you for any help:-)

*Currently, everything happens on the CPU, is there a way to shove everything over to the GPU, do the work (ideally using the blending function I wrote), then bring the result back and put it in the pointer? I looked into using Cuda or OpenCL, but they seem a bit dense to just dive into - but, more importantly, I'm not very familiar with them and am not sure how portable everything will be (and, sadly, given the setup I'm working with, I can't do a lot of extensive testing beyond, see if it crashes when the DLL is called, due to the nature of the problem at hand).

  • \$\begingroup\$ Can you include an example image of what your input scene and overlay look like, and what the overlay / composited result should look like when you're done? I'm not sure if I understand the blending operation you need to perform. \$\endgroup\$ – DMGregory Nov 8 '17 at 2:37
  • \$\begingroup\$ I don't have an example right now, I'm on my phone. But, essentially, just to give a rough idea using aloha only. If the original image where nearly opaque black and a light was transparent at center, getting less so as it went out, then the final result would blend so that the original image was more transparent where the light was more transparent. So, if you had multiple lights, their transparent regions would each lower the opacity of the overlay. Short version: more light = more transparent light image, blending more transparency into the overlay makes it more transparent, or brighter. \$\endgroup\$ – Phoenix Starr Nov 8 '17 at 4:01
  • \$\begingroup\$ And these lights, are they just radial gradients in image space, or do they need to relate to the underlying scene in some way? \$\endgroup\$ – DMGregory Nov 8 '17 at 4:02
  • \$\begingroup\$ The positions of the lights are attached to things in the scene and may change frame to frame, but, otherwise, are just radial gradients - they do not cast shadows and are not blocked by objects in the scene. \$\endgroup\$ – Phoenix Starr Nov 8 '17 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.