Commit Graph

68 Commits (368a073415064957c292242483e2967a4c3e28b3)

Author SHA1 Message Date
Peter Wortmann 480ade634d Shiny materials, shader reorganisation
This implements the proposal made in the forum for "shiny" materials -
material can now determine the angle at which the most light is reflected.
Shiny materials might set this lower to approximate a "reflection" effect,
and increase the "spottiness" at the same time. To compensate for the
lack of brightness without light, "emittance" can be used.

Not sure this is the most elegant way to model this - the "proper" way
here would be to have emittance, shading and specular as three separate
light parameters instead of molding one into the other and using the third
to compensate.

Furthermore, this reorganises shaders in a major way: We reduce the
number of shader files down to three, pushing a number of possible
configurations into preprocessor. I believe this should be easier to
understand, which for the moment trumps theoretical extensibility
benefits.
2015-09-20 14:50:22 +01:00
Peter Wortmann 30857e835e Shader gamma implementation
In comparison to the old system, this is a downgrade - instead of being
able to set a full color mapping by gamma ramp, we now get just a value
per colour channel.

Upside is that we do not need to play around with the global gamma ramps
any more, which was arguably the wrong way to do it.

This commit will likely break everything that has been using gamma so far.
2015-08-31 17:35:08 +01:00
Armin Burgmeier a172245c1e Illuminate materials with no backface culling from both sides
This might need adaptions in some materials, but is probably the right thing
to do.
2015-07-20 22:11:19 -04:00
Nicolas Hake 0db5950c8d GL: Test for GL_KHR_debug before enabling GL_DEBUG_OUTPUT
The GLEW headers of Ubuntu 12.04 LTS don't know about GL_KHR_debug yet,
so we have to test for it before using its enum. Additionally, drivers
without support for GL_KHR_debug would emit INVALID_ENUM, so we test for
driver support too.
2015-05-28 22:56:48 +02:00
Fabian Pietsch 0f65ab4b35 GL: Avoid endless recursion via OpenGLDebugProc
When an error's log output is represented graphically the graphics
operation can lead to another error (or the same error again), which
will be logged graphically again and so forth, until stack overflow.
So log to the log file only.
2015-05-28 21:34:15 +02:00
Fabian Pietsch 8ef6d65520 GLX: More debug output, to be able to trace the code paths taken 2015-05-28 21:34:14 +02:00
Fabian Pietsch 72366a56b7 GLX: Get debug callback to work even when the driver violates the specs
According to Isilkor, the initial state of DEBUG_OUTPUT should be TRUE
on a debug context. This was not the case on my system (Mesa 10.3.2).
2015-05-28 21:34:12 +02:00
Nicolas Hake 5562b09dc4 Remove a lot of disabled legacy code, round 2
Maybe at some point we'll be rid of all the commented-out code that
nobody has looked at in years.
2015-03-25 20:02:53 +01:00
Nicolas Hake d6f219a3df Use 3x4 bones on low MAX_VTX_UNIFORM_COMPS (#1285)
4x3 matrices use the same number of uniform components as 4x4 ones.
If we're short on uniform components, don't transpose the transformation
matrix before sending it to the shader, and transpose it in the shader
itself instead, saving 4 components per bone.
2015-03-18 23:38:20 +01:00
Nicolas Hake d2563fe345 Do skinning in hardware
Instead of transforming all vertices on the CPU every time an animation
progresses, we now only recalculate the skeleton, leaving the heavy
lifting for the GPU. This also means we no longer have to push all
vertices onto the bus every frame, because the mesh isn't changing and
can therefore be stored in a GL_STATIC_DRAW VBO when it's first loaded.
The downside of this approach is that there's only a limited number of
uniforms and vertex attributes we can pass to the shader. At the moment
these limits are a maximum of 128 bones per skeleton, and no vertex can
be influenced by more than 8 bones at once. So far this is no problem,
as the most complex skeleton in the base game uses less than 64 bones
and no more than 6 bone weights per vertex.
2015-02-27 21:51:58 +01:00
Nicolas Hake 75c2b8e61c GL: Dump list of supported extensions with --debug-opengl
glGetString(GL_EXTENSIONS) is deprecated starting with OpenGL 3.0.
Instead, you're now supposed to retrieve the list of extensions one by
one with glGetStringi.
2015-02-22 15:52:38 +01:00
Nicolas Hake 6e41694495 GL: Check for OpenGL 2.1 on startup
We've been using OpenGL 2.1 features for some time now, and hardware has
started supporting OpenGL 2.1 in 2005. I doubt this will make anyone
unable to run the game, and it's certainly better than crashing because
of a nullpointer dereference when some GL function we use can't be
found.
2015-02-19 13:36:01 +01:00
Nicolas Hake 26043e7e81 GL: Return a reasonable string for GL_DEBUG_SEVERITY_NOTIFICATION 2015-02-17 19:45:08 +01:00
Nicolas Hake 9bfd232ab5 Test whether GLDEBUGPROCARB's userParam is const or not
Depending on how current your headers are, the userParam parameter to
GLDEBUGPROCARB may be const, or it may not. The ARB has added the const
qualifier at some point after publishing the specs. Hooray for breaking
API changes.
2015-02-16 21:21:31 +01:00
Nicolas Hake feb9513666 GL: Use GLAPIENTRY instead of APIENTRY
They're the same on Windows, but Linux doesn't have APIENTRY at all.
2015-02-16 18:48:35 +01:00
Nicolas Hake cac94659d0 wGL: Allow OpenGL debugging
This introduces a new command line parameter "--debug-opengl", which
will create special debug OpenGL contexts and attach a callback that the
driver will invoke when it detects a problem. The callback will then
write the error message to the logfile, and break into the debugger if
one is attached.
Currently only works on Windows.
2015-02-16 17:45:10 +01:00
Nicolas Hake 00a24846cc GL: cast gluErrorString rv to const char* before handing to StdStrBuf 2015-02-16 17:44:20 +01:00
Nicolas Hake eed1c43b8a GL: Correctly encode error strings
gluErrorString returns latin-1 encoded strings. Our code expects to
receive UTF-8 encoded strings everywhere, so make sure that the strings
are converted before passing them on.
2015-02-16 15:39:05 +01:00
Günther Brammer 5bcedb5bbf Remove some redundant #includes 2015-01-25 18:53:48 +01:00
Nicolas Hake fef96eca9c Replace C4Surface::ppTex by a vector
This should improve cache coherency by having all surface tiles adjacent
instead of strewn across the heap. This will also remove an indirection
in the common case of only using one tile.
2015-01-18 22:59:44 +01:00
Sven Eberhardt 1c994ad3c7 Windows: Do not deselect GL context when losing focus (#1208).
Fixes engine intialization when tabbing out.
2015-01-11 17:01:27 +01:00
Armin Burgmeier e1d1d540c7 Allow independent viewport and light regions in C4FoWRegion (#1211)
With this change, an additional rectangle is stored in C4FoWRegion that
represents the area covered by the viewport in fractional floating point
coordinates. This allows the light texture to be created for an arbitrary
portion of the landscape, and the coordinate transformations for the
shaders will still work.

Also, since the additional rectangle uses floating point precision, the
computed coordinate transformations do now give the exact same result as for
the landscape pixel-by-pixel, and there should not be any offsets left.

I also hope that this change improves or fixes the single-pixel-lines of sky
that are sometimes seen at the edges of the viewport.
2015-01-07 19:44:31 +01:00
Armin Burgmeier 1c68526440 Remove unused function C4DrawGL::EnsureAnyContext() 2015-01-04 13:36:29 +01:00
Armin Burgmeier a3049207c9 Use full ambient lighting in global viewports
This allows to see the whole landscape without any areas covered by FoW
in the global viewport. Basically the ambient lighting is set to 1.0
independent of the ambient light map. In the course of this, a second
shader for the landscape has been introduced.
2014-12-28 15:07:42 +01:00
Armin Burgmeier 8116a96ed4 Fix fragment coordinate transforms (#1192)
There were two problems with the previous transforms:
  1) For inverting the Y axis for the ambient map, the total height of the
     output window is needed, not only the viewport region.
  2) The Y offset to only use the part of the light texture that is being
     rendered to was not applied.

In order to keep the transformations more readable, a new lightweight class
C4FragTransform has been introduced which can only handle translations
and scales in x and y.
2014-12-26 16:16:09 +01:00
Armin Burgmeier 8686441d45 Make mesh shaders use the C4Shader slice machinery 2014-12-22 22:56:30 +01:00
Armin Burgmeier 8c42704181 Rename some shader files and add basic shader for meshes 2014-12-22 22:56:30 +01:00
Tobias Zwick 4981182cf8 Merge remote-tracking branch '_origin/master' into lights
Conflicts:
	src/c4group/C4Components.h
2014-12-15 21:16:40 +01:00
Sven Eberhardt dd9fdbb159 Log information about GPU used by OpenGL on startup. 2014-12-14 12:35:22 +01:00
Armin Burgmeier ab4de05b4f Fix light/ambient drawing offset when upperboard is active 2014-12-07 21:54:12 -05:00
Armin Burgmeier 254e1e4631 Apply drawtransform on sprite normal map
This makes the normals point into the correct direction for transformed
objects, which is for example the case when they are rotated with SetR.
2014-11-26 17:56:43 -05:00
Armin Burgmeier e58b62920c Change extension of shader files from .c to .glsl 2014-11-25 11:54:36 -05:00
Armin Burgmeier 192dddec6f Use the new shader system for rendering sprites
This now also avoids the use of conditionals in shaders by using different
shaders instead.
2014-11-24 14:51:08 -05:00
Armin Burgmeier 292f8e8191 Improve GL error outputs 2014-11-24 14:51:08 -05:00
Armin Burgmeier f550fcdf43 Add C4Draw::GetClipRect()
This will allow to avoid some code duplication when computing the coordinate
transform from fragment coordinates to ambient and light texture coordinates.
2014-11-24 14:51:08 -05:00
Armin Burgmeier db6df15377 Add SetAmbientBrightness and GetAmbientBrightness script functions 2014-11-20 17:07:31 -05:00
Armin Burgmeier d60c74c6b6 Fix viewport offset for lightmap lookup 2014-11-20 16:45:34 -05:00
Armin Burgmeier b43e1a9369 Fix ambient texture coords when viewport is smaller than full render target 2014-11-18 16:44:06 -05:00
Armin Burgmeier 88f8f75441 Add ambient lighting
This introduces a new texture, an ambient light map, that is generated
automatically at the beginning of the round by the sky portion of the
landscape. This basically makes everything that is close to sky visible
by default.

The shaders have been adapted so that they deploy direction-independent
lighting for the ambient component, and the current (diffuse) behaviour
for the diffuse component. This makes the shaders use an additional
texture unit that represents the ambient light. We can think about merging
this information into the light texture, but the coordinate systems are
different at the moment, so this could be performed at the stage of light
texture generation.

For meshes, the ambient material is not actually used, but instead a
diffuse light from the front is used. This makes many meshes look more
interesting, maybe also because the ambient material setting of most
meshes are not set correctly at the moment.
2014-11-17 09:35:50 -05:00
Armin Burgmeier 137abb89df Implement normal maps for sprite graphics 2014-11-07 15:29:09 -05:00
Armin Burgmeier aed907e30d Remove old fog of war 2014-11-07 11:53:10 -05:00
Armin Burgmeier 0795715465 Apply lighting on sprites 2014-11-06 15:56:19 -05:00
Armin Burgmeier 73e4f5a89c Remove some unused code in C4Draw 2014-11-04 11:24:55 -05:00
Armin Burgmeier a1bafb937f Implement DrawQuadDw with PerformMultiTris
This simplifies the code further.
2014-11-04 11:02:40 -05:00
Armin Burgmeier fe7897539a Remove unused code 2014-11-02 16:57:28 -05:00
Armin Burgmeier 233e5e7c13 Remove CStdGL::BlitLandscape
This code is only used for the low-resolution landscape that is hardly in use
anymore. The code was mostly a duplicate of the standard C4Surface blit
function, CStdGL::PerformBlt, with some added code for blitting material
textures with higher resolution. However, that code was not enabled anymore
by the classic landscape renderer either, so it seems safe to remove it.

The landscape is now simply drawn by C4Draw::Blit.
2014-11-02 11:15:06 -05:00
Armin Burgmeier 373b992f45 Tweak the shader a bit 2014-11-01 22:45:14 -04:00
Armin Burgmeier 2b2bc56e77 Remove unused PerformBlt function 2014-11-01 22:28:03 -04:00
Armin Burgmeier b58fde88aa Add option to draw overlay with PerformMultiTris
This allows drawing images with overlay in a single rendering pass.
2014-11-01 22:28:03 -04:00
Armin Burgmeier 178008928b Apply ClrModMap to meshes pixel-by-pixel
The support is not yet fully implemented; there are some transformations
missing. However, since the FoW support at the moment seems to be broken
(#1168) this feature cannot be tested properly.
2014-10-21 17:26:22 -04:00