Commit Graph

42 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
Peter Wortmann 65d9953d32 Some clean-ups
Nothing spectacular. Main thing is that the light debug view is now even
more colourful.
2015-02-23 11:54:41 +01:00
Nicolas Hake 4db690b0c6 Add copyright header to files that were missing it 2015-02-16 18:40:52 +01:00
Nicolas Hake c809ab4ae3 gl: Use glDeleteTextures instead of glDeleteObject to delete textures
glDeleteObject doesn't delete textures, it deletes shader objects.
2015-02-16 18:07:03 +01:00
Nicolas Hake 50a81a8dc7 gl: Don't call glDeleteObjectARB on null objects
glDeleteObjectARB will flag GL_INVALID_PARAMETER when it's called with a
null parameter. Avoid this so the error list doesn't get tainted.
2015-02-16 17:45:17 +01:00
Nicolas Hake e21a5bdd44 Rename BoundBy to Clamp
"BoundBy" sounds like a predicate. "Clamp" is a common function name for
the operation in graphics processing, so it should be familiar to users.
2015-02-12 23:05:55 +01:00
Sven Eberhardt cd3b969fc4 Silence a few warnings in render and SolidMask code. 2015-02-08 12:37:00 +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
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
Tobias Zwick 3e307fc843 fix previous commit 2015-01-01 17:27:41 +01:00
Tobias Zwick 2a4b268087 fix the same bug as Sven2 10 minutes ago, but also clean up the update function, rename variables, add comments, etc. 2015-01-01 16:08:32 +01:00
Sven Eberhardt 9a87240d47 Fix off-by-one error in landscape X bias calculation. 2015-01-01 15:52:15 +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 8c42704181 Rename some shader files and add basic shader for meshes 2014-12-22 22:56:30 +01: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 a7f9ba1e91 Compute ambient texture coordinate based on fragment coordinate
This will allow to use the same shader slice also for the sprite and mesh
shaders.
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
Peter Wortmann 7fea618221 Collected trivial bug-fixes
Turns out we actually can't optimise out the second texture normal
lookup - it makes a noticeable difference in-game. Also there was
possible slice collision, it might be worth warning about this kind
of stuff.

Also removed unused variable, and made error messages more consistent
in terms of whitespace.
2014-11-20 21:44:11 +01:00
Peter Wortmann 72289713f9 Modular shader system
The idea here is that we compose shaders out of "slices", which can
come from the engine ("built-in"), from files or possibly even from
models. This should allow us to more easily share the code between
different rendering shaders (e.g. for lights / normals).

TODO: Workarounds not yet implemented, so this might degrade less
gracefully.
2014-11-20 11:52:14 +01: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
Tobias Zwick 21e532da23 split up C4FoW header and source file into one file for each class
* added some class and method documentation, removed some superfluous comments like

	void C4FoW::Update(C4Rect r)
	{
		// Update all lights
		...

* added ASK comments that need clarification before proper documentation
2014-10-11 23:13:10 +02:00
Peter Wortmann c2f57db54b fix merge 2014-10-07 23:38:24 +02:00
Tobias Zwick b11e8d5d7a Merge branch 'master' into lights
Conflicts:
	planet/Graphics.ocg/LandscapeShader.c
	src/graphics/C4DrawGLMesh.cpp
	src/graphics/C4DrawGL.cpp
	src/landscape/C4Landscape.cpp
	src/landscape/C4Landscape.h
	src/landscape/C4LandscapeRender.cpp
	src/landscape/C4Scenario.cpp
	src/landscape/C4Scenario.h
2014-10-06 23:27:16 +02:00
Julius Michaelis 2c7d9c0549 Fix a load of warnings (two were actual errors, only in diagnostics though) 2014-04-17 19:24:41 +02:00
Tobias Zwick fe2a400c02 replace global function GetTime() with class function C4TimeMilliseconds::Now() 2013-12-07 21:27:01 +07:00
Tobias Zwick 94c618d153 add new type C4TimeMilliseconds for time measurements to solve problems when GetTime() overflows (#251)
The new type C4TimeMilliseconds behaves for the most part like a uint32_t but is overflow-proof in comparisons.
In some places, a 0-value (or uint_max) of the variable storing the time had the special meaning "not set yet". This has been resolved by having it as a pointer to C4TimeMilliseconds with NULL meaning that it has not been set yet.
2013-12-04 19:35:07 +07:00
Martin Plicht 60bafd6b3b Change remaining #ifdef USE_GL blocks into #ifndef USE_CONSOLE blocks (this makes Linux version work again) 2013-11-09 00:20:14 +01:00
Tim Blume 240193ad5a Remove remains of Direct3D support
Direct3D hasn't worked for more than a year now, and there don't seem to
be any efforts to revive it. Remove it and concentrate on better OpenGL
support.
2013-11-02 21:39:34 +01:00
Sven Eberhardt 324a1f03c0 Fix LandscapeRender ReInit when loading scenario sections.
The LandscapeRender Init() proc loads graphics from the main graphics group, which is already closed when a section is loaded. So just keep the renderer around on landscape recreation now.
2013-07-03 22:28:50 +02:00
Peter Wortmann be0fe99126 Made material zoom configurable
Also set default to 8. This might be a pretty controversial change, but
the amounts of screenshots we have at zoom levels beyond 4 just calls for
a more high-res approach.
2012-11-05 16:50:59 +00:00
Peter Wortmann f339572e95 Officially make BROKEN_ARRAYS_WORKAROUND the default
Pretty awkward compromise, but the array version seems to confuse a lot of
drivers, without causing an actual error. So this is probably better in
practice until better drivers are more common.
2012-11-05 16:10:55 +00:00
Peter Wortmann a4b4065206 Made material zoom configurable
Also set default to 8. This might be a pretty controversial change, but
the amounts of screenshots we have at zoom levels beyond 4 just calls for
a more high-res approach.
2012-11-05 17:17:12 +00:00
Peter Wortmann 41b51907c6 Officially make BROKEN_ARRAYS_WORKAROUND the default
Pretty awkward compromise, but the array version seems to confuse a lot of
drivers, without causing an actual error. So this is probably better in
practice until better drivers are more common.
2012-11-05 16:57:33 +00:00
Peter Wortmann d1c28227f3 Normal map support for lights
- The light direction change isn't really consistent, as I can only give
  GL the vectors at the triangle edges. So for deep rays, the light
  distribution often ends up being significantly different than for short
  rays.

- I *am* distorting the normal map vectors, quite badly actually. I'll leave
  it for the moment, because it definetely looks best for the light vectors,
  but I will have to correct that a bit once I have the time.
2012-09-05 21:51:25 +01:00
Peter Wortmann 6b04c9cc45 Use largest texture as reference, not first one
This should make it easier to experiment with bigger texture resolutions
2012-08-26 00:11:22 +01:00
Peter Wortmann 56bdeec585 FoW/lights preview
This is pretty much still prototype stage. Lots of bug, lots of stuff missing.
2012-08-19 19:35:10 +01:00
Günther Brammer 20577f8575 GL: Identifiers starting with GL_ are reserved for the implementation
Some compilers are less strict about this than others, unfortunately.
The Gallium one complains with

preprocessor error: Macro names starting with "GL_" are reserved.
2012-05-30 23:34:08 +02:00
Nicolas Hake e0bde2256a GL: Make max uniform count available to shader and work around low limits (#786)
beliar reports that his driver doesn't support the number of fragment shader
uniforms that we're using in the landscape scaler. By making the reported limit
available to the GLSL code, it can use a workaround using a 1D texture to
transfer data.
2012-05-28 16:05:30 +02:00
Günther Brammer 1a29f8625d Reorder engine source file organization a bit
This mostly consists of flattening the hierarchy, splitting the
graphics stuff out of platform, and a few smaller cleanups.
2012-04-27 19:04:43 +02:00