-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add normal maps #5643
Add normal maps #5643
Changes from all commits
69172ac
19fe76c
f3874c7
a6433f4
ddde708
271badb
e5b40d2
bafcc9a
329f3eb
49b73be
4371fc8
cb16b06
b361b90
d1f4491
a06e422
b9b5d79
dc8e6a4
c053bca
3c6dc64
7263940
5e31e1a
c038d5a
487f341
670d5b9
b895e0e
37d5cf4
3b51002
52b9c9c
f53350d
24ed251
fb480e6
653eb41
af926d4
c3c011f
ad42758
2a81568
e5dd9be
05db39e
1337b3f
91a4df2
9a26bff
09a5f72
5a41c7e
7ef6074
76e0600
9898327
7638708
4e34fe7
42b209c
15c6bff
8a8d2e8
50e77c5
9807f6f
fe58ea5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
uniform highp vec4 InputColor; | ||
|
||
void fragment() { | ||
COLOR = InputColor; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
uniform highp float rotation; | ||
const highp float COLOR_POWER = 0.452; | ||
const highp float COLOR_POWERNT = 2.212; | ||
|
||
void fragment() | ||
{ | ||
highp vec4 Col = zTexture(UV); | ||
Col = vec4(pow(Col.xy, vec2(COLOR_POWER)) - vec2(0.5, 0.5), Col.zw); | ||
Col = vec4(Col.xy * cos(rotation) + vec2(-1.0, 1.0) * Col.yx * sin(rotation), Col.zw); | ||
Col = vec4(pow(Col.xy + vec2(0.5, 0.5), vec2(COLOR_POWERNT)), Col.zw); | ||
COLOR = Col; | ||
Comment on lines
+1
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PLEASE comment shaders, especially when using magic numbers. This also has 0 flexibility for content. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,15 @@ namespace Robust.Client.Graphics | |
[PublicAPI] | ||
public sealed class AtlasTexture : Texture | ||
{ | ||
public AtlasTexture(Texture texture, UIBox2 subRegion) : base((Vector2i) subRegion.Size) | ||
public AtlasTexture(Texture texture, UIBox2 subRegion, int? width = null) : base((Vector2i) subRegion.Size) | ||
{ | ||
DebugTools.Assert(SubRegion.Right < texture.Width); | ||
DebugTools.Assert(SubRegion.Bottom < texture.Height); | ||
DebugTools.Assert(SubRegion.Left >= 0); | ||
DebugTools.Assert(SubRegion.Top >= 0); | ||
|
||
SubRegion = subRegion; | ||
RegionWidth = width ?? (int)subRegion.Width; | ||
SourceTexture = texture; | ||
} | ||
|
||
|
@@ -33,6 +34,11 @@ public AtlasTexture(Texture texture, UIBox2 subRegion) : base((Vector2i) subRegi | |
/// </summary> | ||
public UIBox2 SubRegion { get; } | ||
|
||
/// <summary> | ||
/// The width of the texture we came from, used for offsetting to get normals | ||
/// </summary> | ||
public int RegionWidth { get; } | ||
|
||
Comment on lines
36
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think knowing other texture areas should be something callers should worry about . AtlasTexture is just an abstraction to handle GPU memory in a more sane way. |
||
public override Color GetPixel(int x, int y) | ||
{ | ||
DebugTools.Assert(x < SubRegion.Right); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
using System.Collections.Generic; | ||
using System.Linq; | ||
using OpenToolkit.Graphics.OpenGL4; | ||
using Robust.Shared; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Enums; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Graphics; | ||
|
@@ -27,8 +29,14 @@ internal partial class Clyde | |
|
||
private List<Entity<MapGridComponent>> _grids = new(); | ||
|
||
private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBounds, IEye eye) | ||
private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBounds, IEye eye, bool normal = false) | ||
{ | ||
if (normal && (!_lightManager.Enabled | ||
|| !_lightManager.DrawLighting | ||
|| !_cfg.GetCVar(CVars.LightNormals) | ||
|| !_resourceCache.GetNormalsEnabled())) | ||
return; | ||
|
||
Comment on lines
+32
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really sure why drawing is dropped entirely if lighting isn't enabled? |
||
var mapId = eye.Position.MapId; | ||
if (!_mapManager.MapExists(mapId)) | ||
{ | ||
|
@@ -55,12 +63,16 @@ private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBoun | |
{ | ||
SetTexture(TextureUnit.Texture0, _tileDefinitionManager.TileTextureAtlas); | ||
SetTexture(TextureUnit.Texture1, _lightingReady ? viewport.LightRenderTarget.Texture : _stockTextureWhite); | ||
gridProgram = ActivateShaderInstance(_defaultShader.Handle).Item1; | ||
|
||
gridProgram = ActivateShaderInstance((normal ? _colorShader : _defaultShader).Handle).Item1; | ||
if (normal) | ||
gridProgram.SetUniformMaybe("InputColor", new Color(0.5f, 0.5f, 1f)); | ||
SetupGlobalUniformsImmediate(gridProgram, (ClydeTexture) _tileDefinitionManager.TileTextureAtlas); | ||
|
||
gridProgram.SetUniformTextureMaybe(UniIMainTexture, TextureUnit.Texture0); | ||
gridProgram.SetUniformTextureMaybe(UniILightTexture, TextureUnit.Texture1); | ||
gridProgram.SetUniform(UniIModUV, new Vector4(0, 0, 1, 1)); | ||
if (!normal) | ||
gridProgram.SetUniform(UniIModUV, new Vector4(0, 0, 1, 1)); | ||
} | ||
|
||
var transform = _entityManager.GetComponent<TransformComponent>(mapGrid); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't if statements expensive as shit in shaders.
Would it be better to just draw the normals to a separate texture and use that or somethin