This disclosure relates generally to the field of image processing and, more particularly, to various techniques for allowing 2D graphics rendering and animation infrastructures to be able to dynamically render three-dimensional lighting effects on two-dimensional texture maps—without the need for the corresponding normal maps to be created and/or supplied to the rendering and animation infrastructure by the designer or programmer.
Two-dimensional graphics rendering and animation infrastructures are commonly used by programmers today and provide a convenient means for rapid application development, such as for the development of gaming applications on mobile devices. Because two-dimensional graphics rendering and animation infrastructures may utilize the graphics hardware available on the hosting device to composite 2D images at high frame rates, programmers can create and use complex special effects and texture atlases in games and other application with limited programming overhead.
For example, Sprite Kit, developed by APPLE INC., provides a graphics rendering and animation infrastructure that programmers may use to animate arbitrary textured images, or “sprites.” Sprite Kit uses a traditional rendering loop, whereby the contents of each frame are processed before the frame is rendered. Each individual game determines the contents of the scene and how those contents change in each frame. Sprite Kit then does the work to render the frames of animation efficiently using the graphics hardware on the hosting device. Sprite Kit is optimized so that the positions of sprites may be changed arbitrarily in each frame of animation.
Sprite Kit supports many different kinds of content, including: untextured or textured rectangles (i.e., sprites); text; arbitrary CGPath-based shapes; and video. Sprite Kit also provides support for cropping and other special effects. Because Sprite Kit supports a rich rendering infrastructure and handles all of the low-level work to submit drawing commands to OpenGL, the programmer may focus his or her efforts on solving higher-level design problems and creating great gameplay. The “Sprite Kit Programming Guide” (last updated Feb. 11, 2014) is hereby incorporated by reference in its entirety.
The inventors have realized new and non-obvious ways to dynamically render three-dimensional lighting effects on two-dimensional texture maps—without the need for the programmer to undertake the sometimes complicated and time-consuming process of providing a corresponding normal map for each texture that is to be used in his or her application. Using the techniques disclosed herein, the two-dimensional graphics rendering and animation infrastructure may provide the same or similar lighting effects on the texture in “real-time” as would be provided on a texture that was explicitly supplied with normal map by the programmer.
Methods, computer readable media, and systems for allowing 2D graphics rendering and animation infrastructures to be able to dynamically render three-dimensional lighting effects on two-dimensional texture maps—without the need for the corresponding normal maps to be created and/or supplied to the rendering and animation infrastructure by the designer or programmer are described herein. The traditional method of rendering lighting and shadows by 2D graphics rendering and animation infrastructures requires the programmer to supply a surface texture and a surface normal map (i.e., two separate files) to the rendering infrastructure. In such a method, a normal vector for each pixel is taken from the surface normal map, read in by a Graphics Processing Unit (GPU), and used to create the appropriate light reflections and shadows on the surface texture.
According to some embodiments described herein, lighting effects may be dynamically rendered for the texture without the need for the programmer to supply a normal map. According to some embodiments, an algorithm may inspect the pixel values (e.g., RGB values) of each individual pixel of the texture, and, based on the pixel values, can accurately estimate where the lighting and shadow effects should be in the source texture file to simulate 3D lighting. The algorithm may then inform a GPU(s) where the lighting effects should appropriately be applied to the texture—and thus still have the same effect as a texture map that was supplied with a normal map. The lighting effects estimation process may be distributed between a CPU and GPU(s) in order to achieve near real-time speed, e.g., by splitting each source texture into blocks of image data and then distributively processing the blocks of image data on the CPU and GPU(s), gathering the results directly back on the GPU(s), and then using the result immediately for the current rendering draw call. Further, because these effects are being rendered dynamically by the rendering and animation infrastructure, the techniques described herein work for “dynamic content,” e.g., user-downloaded data, in-application user-created content, operating system (OS) icons, and other user interface (UI) elements—for which programmers do not have access to normal maps a priori, i.e., before the application is executed.
Thus, in one embodiment disclosed herein, a non-transitory program storage device, readable by a programmable control device, may comprise instructions stored thereon to cause one or more processing units to: obtain a first representation of a first two-dimensional image, wherein the first representation comprises a first plurality of pixels, and wherein each pixel in the first plurality of pixels comprises a first plurality of pixel color values and a transparency value; convert the first plurality of pixel color values into a luminance value for each pixel in the first plurality of pixels; create a height map over the first two-dimensional image using the converted luminance values for each pixel in the first plurality of pixels, wherein each position in the height map corresponds to a pixel from the first plurality of pixels; calculate a normal vector for each pixel in the first plurality of pixels, wherein calculating the normal vector for a respective pixel comprises calculating the gradient of the height map at the position corresponding to the respective pixel; and cause at least one of the one or more processing units to render three-dimensional lighting effects on the first representation of the first two-dimensional image, wherein the calculated normal vectors for each pixel in the first plurality of pixels are used as the normal map for the three-dimensional rendering, and wherein the first plurality of pixel color values and the transparency value for each pixel in the first plurality of pixels are used as the texture map for the three-dimensional rendering.
In still other embodiments, the techniques described herein may be implemented as methods or in apparatuses and/or systems, such as electronic devices having memory and programmable control devices.
Systems, methods and program storage devices are disclosed, which comprise instructions to cause one or more processing units to: obtain a representation of a two-dimensional image; convert the pixel color values from the image into luminance values; create a height map over the image using the converted luminance values; calculate a normal vector for each pixel in the image, wherein calculating the normal vector for a respective pixel comprises calculating the gradient of the height map at the position corresponding to the respective pixel; and cause one or more processing units to render three-dimensional lighting effects on the representation of the two-dimensional image, wherein the calculated normal vectors for each pixel in the image are used as the normal map for the three-dimensional rendering, and wherein the pixel color values and the transparency value for each pixel in the image are used as the texture map for the three-dimensional rendering. The techniques disclosed herein are applicable to any number of electronic devices with displays: such as digital cameras, digital video cameras, mobile phones, personal data assistants (PDAs), portable music players, monitors, and, of course, desktop, laptop, and tablet computer displays.
In the following description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the inventive concept. As part of this description, some of this disclosure's drawings represent structures and devices in block diagram form in order to avoid obscuring the invention. In the interest of clarity, not all features of an actual implementation are described in this specification. Moreover, the language used in this disclosure has been principally selected for readability and instructional purposes, and may not have been selected to delineate or circumscribe the inventive subject matter, resort to the claims being necessary to determine such inventive subject matter. Reference in this disclosure to “one embodiment” or to “an embodiment” means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one implementation of the invention, and multiple references to “one embodiment” or “an embodiment” should not be understood as necessarily all referring to the same embodiment.
It will be appreciated that, in the development of any actual implementation (as in any development project), numerous decisions must be made to achieve the developers' specific goals (e.g., compliance with system- and business-related constraints), and that these goals may vary from one implementation to another. It will also be appreciated that such development efforts might be complex and time-consuming, but would nevertheless be a routine undertaking for those of ordinary skill in the design of an implementation of image processing systems having the benefit of this disclosure.
Referring now to
Moving to the central portion of
Finally, in the right-hand portion of
Referring now to
Referring now to
The first approach may be to actually build a 3D mesh 304 representative of the texture map 302. Such a process may proceed according to known techniques, such as creating vertices over the surface of the texture at the locations of significant changes in height on a height map created over the texture. The mesh could then be constructed by connecting the resulting vertices.
Alternately, as discussed above, the process may proceed to dynamically generate a normal map 306 for the texture map. The normal map 306 may be created by taking the gradient, i.e., the derivative, of a height map created over the texture. Using this approach, the “bumpiness” or “smoothness” of the normal map may be controlled, e.g., by programmer-controlled parameters, system defaults, the size of the normal map being created, dynamic properties being controlled at run-time by the user of the application, or any other possible means. The amount of “bumpiness” or “smoothness” of the normal map may also be based, at least in part, on what type of texture is being analyzed. For example, a hand-drawn texture or computer-generated art with large portions of uniformly-colored flat surfaces may need less smoothing than a photographic image that has a large amount of noise in it. Edge detection algorithms may also be used to create masks as input to smoothing operations to ensure that important details in the image are not overly smoothed. Adjusting the bumpiness” or “smoothness” of the normal map in real-time allows the program or programmer a finer degree of control over the “look and feel” of the rendered 3D effects to suit the needs of a given implementation. Such a degree of control would not be possible in prior art rendering/animation systems, wherein the normal map is constructed a priori by an artist or the programmer, and then passed to the program, where it remains static during the execution of the application.
Finally, the process may proceed to create a height map 308 for the texture map, for example by converting the color values of the pixels in the texture map to luminance values, according to known techniques. This approach, while requiring the least amount of preprocessing, would potentially require the greatest amount of run-time processing, due to the fact that the shader would be forced to estimate the normal vectors for each pixel in the surface in real-time, which may involve sampling neighboring pixels. This process is also not necessarily cache coherent, and therefore potentially more costly for this reason, as well.
The result of the various potential processes shown in
Referring now to
Referring now to
Referring now to
Referring now to
Processor 705 may be any suitable programmable control device capable of executing instructions necessary to carry out or control the operation of the many functions performed by device 700 (e.g., such as the processing of texture maps in accordance with operations in any one or more of the Figures). Processor 705 may, for instance, drive display 710 and receive user input from user interface 715 which can take a variety of forms, such as a button, keypad, dial, a click wheel, keyboard, display screen and/or a touch screen. Processor 705 may be a system-on-chip such as those found in mobile devices and include a dedicated graphics processing unit (GPU). Processor 705 may be based on reduced instruction-set computer (RISC) or complex instruction-set computer (CISC) architectures or any other suitable architecture and may include one or more processing cores. Graphics hardware 720 may be special purpose computational hardware for processing graphics and/or assisting processor 705 process graphics information. In one embodiment, graphics hardware 720 may include one or more programmable graphics processing units (GPUs).
Sensor and camera circuitry 750 may capture still and video images that may be processed to generate images, at least in part, by video codec(s) 755 and/or processor 705 and/or graphics hardware 720, and/or a dedicated image processing unit incorporated within circuitry 750. Images so captured may be stored in memory 760 and/or storage 765. Memory 760 may include one or more different types of media used by processor 705, graphics hardware 720, and image capture circuitry 750 to perform device functions. For example, memory 760 may include memory cache, read-only memory (ROM), and/or random access memory (RAM). Storage 765 may store media (e.g., audio, image and video files), computer program instructions or software, preference information, device profile information, and any other suitable data. Storage 765 may include one more non-transitory storage mediums including, for example, magnetic disks (fixed, floppy, and removable) and tape, optical media such as CD-ROMs and digital video disks (DVDs), and semiconductor memory devices such as Electrically Programmable Read-Only Memory (EPROM), and Electrically Erasable Programmable Read-Only Memory (EEPROM). Memory 760 and storage 765 may be used to retain computer program instructions or code organized into one or more modules and written in any desired computer programming language. When executed by, for example, processor 705, such computer program code may implement one or more of the methods described herein.
In one embodiment, the host systems 810 may support a software stack. The software stack can include software stack components such as applications 820, compute application libraries 830, a compute platform layer 840, e.g., an OpenCL platform, a compute runtime layer 850, and a compute compiler 860. An application 820 may interface with other stack components through API calls. One or more processing elements or threads may be running concurrently for the application 820 in the host systems 810. The compute platform layer 840 may maintain a data structure, or a computing device data structure, storing processing capabilities for each attached physical computing device. In one embodiment, an application may retrieve information about available processing resources of the host systems 810 through the compute platform layer 840. An application may select and specify capability requirements for performing a processing task through the compute platform layer 840. Accordingly, the compute platform layer 840 may determine a configuration for physical computing devices to allocate and initialize processing resources from the attached CPUs 870 and/or GPUs 880 for the processing task.
The compute runtime layer 809 may manage the execution of a processing task according to the configured processing resources for an application 803, for example, based on one or more logical computing devices. In one embodiment, executing a processing task may include creating a compute program object representing the processing task and allocating memory resources, e.g. for holding executables, input/output data etc. An executable loaded for a compute program object may be a compute program executable. A compute program executable may be included in a compute program object to be executed in a compute processor or a compute unit, such as a CPU or a GPU. The compute runtime layer 809 may interact with the allocated physical devices to carry out the actual execution of the processing task. In one embodiment, the compute runtime layer 809 may coordinate executing multiple processing tasks from different applications according to run time states of each processor, such as CPU or GPU configured for the processing tasks. The compute runtime layer 809 may select, based on the run time states, one or more processors from the physical computing devices configured to perform the processing tasks. Performing a processing task may include executing multiple threads of one or more executables in a plurality of physical computing devices concurrently. In one embodiment, the compute runtime layer 809 may track the status of each executed processing task by monitoring the run time execution status of each processor.
The runtime layer may load one or more executables as compute program executables corresponding to a processing task from the application 820. In one embodiment, the compute runtime layer 850 automatically loads additional executables required to perform a processing task from the compute application library 830. The compute runtime layer 850 may load both an executable and its corresponding source program for a compute program object from the application 820 or the compute application library 830. A source program for a compute program object may be a compute program source. A plurality of executables based on a single compute program source may be loaded according to a logical computing device configured to include multiple types and/or different versions of physical computing devices. In one embodiment, the compute runtime layer 850 may activate the compute compiler 860 to online compile a loaded source program into an executable optimized for a target processor, e.g., a CPU or a GPU, configured to execute the executable.
An online compiled executable may be stored for future invocation in addition to existing executables according to a corresponding source program. In addition, the executables may be compiled offline and loaded to the compute runtime 850 using API calls. The compute application library 830 and/or application 820 may load an associated executable in response to library API requests from an application. Newly compiled executables may be dynamically updated for the compute application library 830 or for the application 820. In one embodiment, the compute runtime 850 may replace an existing compute program executable in an application by a new executable online compiled through the compute compiler 860 for a newly upgraded version of computing device. The compute runtime 850 may insert a new executable online compiled to update the compute application library 830. In one embodiment, the compute runtime 850 may invoke the compute compiler 860 when loading an executable for a processing task. In another embodiment, the compute compiler 860 may be invoked offline to build executables for the compute application library 830. The compute compiler 860 may compile and link a compute kernel program to generate a computer program executable. In one embodiment, the compute application library 830 may include a plurality of functions to support, for example, development toolkits and/or image processing. Each library function may correspond to a computer program source and one or more compute program executables stored in the compute application library 830 for a plurality of physical computing devices.
It is to be understood that the above description is intended to be illustrative, and not restrictive. The material has been presented to enable any person skilled in the art to make and use the invention as claimed and is provided in the context of particular embodiments, variations of which will be readily apparent to those skilled in the art (e.g., some of the disclosed embodiments may be used in combination with each other). In addition, it will be understood that some of the operations identified herein may be performed in different orders. The scope of the invention therefore should be determined with reference to the appended claims, along with the full scope of equivalents to which such claims are entitled. In the appended claims, the terms “including” and “in which” are used as the plain-English equivalents of the respective terms “comprising” and “wherein.”