mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
experimental map shaders
This commit is contained in:
@@ -8,7 +8,6 @@ Module
|
||||
- client_extended
|
||||
- game_tibiafiles
|
||||
- client_background
|
||||
//- game_shaders
|
||||
|
||||
load-later:
|
||||
- game_textmessage
|
||||
@@ -29,6 +28,7 @@ Module
|
||||
- game_questlog
|
||||
- game_ruleviolation
|
||||
- game_bugreport
|
||||
- game_shaders
|
||||
|
||||
@onLoad: |
|
||||
importStyle 'styles/items.otui'
|
||||
|
BIN
modules/game_shaders/images/clouds.png
Normal file
BIN
modules/game_shaders/images/clouds.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
@@ -1,105 +0,0 @@
|
||||
uniform float opacity; // painter opacity
|
||||
uniform vec4 color; // painter color
|
||||
uniform float time; // time in seconds since shader linkage
|
||||
uniform sampler2D tex0; // map texture
|
||||
varying vec2 texCoord; // map texture coords
|
||||
//uniform vec4 awareArea;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(tex0, texCoord);
|
||||
}
|
||||
|
||||
/*
|
||||
vec4 grayScale(vec4 color, float factor)
|
||||
{
|
||||
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
|
||||
return vec4(gray*factor + (1-factor)*color.r,
|
||||
gray*factor + (1-factor)*color.g,
|
||||
gray*factor + (1-factor)*color.b, 1);
|
||||
}
|
||||
|
||||
// grayscale fog
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(texture, textureCoords);
|
||||
float dist = 0;
|
||||
// left
|
||||
if(textureCoords.x < awareArea.x && textureCoords.y < awareArea.y)
|
||||
dist = distance(textureCoords, awareArea.xy);
|
||||
else if(textureCoords.x < awareArea.x && textureCoords.y < awareArea.w)
|
||||
dist = distance(textureCoords, vec2(awareArea.x, textureCoords.y));
|
||||
else if(textureCoords.x < awareArea.x)
|
||||
dist = distance(textureCoords, awareArea.xw);
|
||||
// right
|
||||
else if(textureCoords.x > awareArea.z && textureCoords.y < awareArea.y)
|
||||
dist = distance(textureCoords, awareArea.zy);
|
||||
else if(textureCoords.x > awareArea.z && textureCoords.y < awareArea.w)
|
||||
dist = distance(textureCoords, vec2(awareArea.z, textureCoords.y));
|
||||
else if(textureCoords.x > awareArea.z)
|
||||
dist = distance(textureCoords, awareArea.zw);
|
||||
// top
|
||||
else if(textureCoords.y < awareArea.y)
|
||||
dist = distance(textureCoords, vec2(textureCoords.x, awareArea.y));
|
||||
// bottom
|
||||
else if(textureCoords.y > awareArea.w)
|
||||
dist = distance(textureCoords, vec2(textureCoords.x, awareArea.w));
|
||||
if(dist > 0) {
|
||||
float range = 0.01;
|
||||
float factor = min(dist/range, 1.0);
|
||||
color = grayScale(color, factor);
|
||||
//color.rgb *= 1 - (factor * 0.5);
|
||||
}
|
||||
gl_FragColor = color;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
sepia
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(texture, textureCoords);
|
||||
if(textureCoords.x < awareArea.x || textureCoords.y < awareArea.y || textureCoords.x > awareArea.z || textureCoords.y > awareArea.w) {
|
||||
gl_FragColor.r = dot(color, vec4(.393, .769, .189, .0));
|
||||
gl_FragColor.g = dot(color, vec4(.349, .686, .168, .0));
|
||||
gl_FragColor.b = dot(color, vec4(.272, .534, .131, .0));
|
||||
gl_FragColor.a = 1;
|
||||
} else
|
||||
gl_FragColor = color;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(texture, textureCoords);
|
||||
vec2 awareRange = (awareArea.zw - awareArea.xy)/2.0;
|
||||
float dist = distance(textureCoords, awareArea.xy + awareRange);
|
||||
float start = min(awareRange.x, awareRange.y);
|
||||
float range = awareRange*0.1;
|
||||
float endFactor = 0.3;
|
||||
if(dist >= start) {
|
||||
color.rgb *= 1 - (min((dist - start)/range, 1.0) * (2.0 - endFactor));
|
||||
}
|
||||
gl_FragColor = color;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
void main()
|
||||
{
|
||||
vec4 sum = vec4(0);
|
||||
vec2 texcoord = texCoord;
|
||||
int j;
|
||||
int i;
|
||||
|
||||
for( i= -4 ;i < 4; i++)
|
||||
{
|
||||
for (j = -4; j < 4; j++)
|
||||
{
|
||||
sum += texture2D(tex0, texcoord + vec2(j, i)*0.0025) * 0.0125;
|
||||
}
|
||||
}
|
||||
gl_FragColor = texture2D(tex0, texCoord) + sum;
|
||||
}
|
||||
*/
|
56
modules/game_shaders/shaders.lua
Normal file
56
modules/game_shaders/shaders.lua
Normal file
@@ -0,0 +1,56 @@
|
||||
Shaders = {}
|
||||
|
||||
local HOTKEY = 'Ctrl+X'
|
||||
local SHADERS = {
|
||||
['Default'] = 'shaders/default.frag',
|
||||
['Bloom'] = 'shaders/bloom.frag',
|
||||
['Sepia'] = 'shaders/sepia.frag',
|
||||
['Grayscale'] = 'shaders/grayscale.frag',
|
||||
['Pulse'] = 'shaders/pulse.frag',
|
||||
['Old Tv'] = 'shaders/oldtv.frag',
|
||||
['Fog'] = 'shaders/fog.frag',
|
||||
['Party'] = 'shaders/party.frag',
|
||||
['Radial Blur'] = 'shaders/radialblur.frag',
|
||||
['Zomg'] = 'shaders/zomg.frag',
|
||||
}
|
||||
|
||||
local shadersPanel
|
||||
|
||||
function Shaders.init()
|
||||
importStyle 'shaders.otui'
|
||||
|
||||
|
||||
Keyboard.bindKeyDown(HOTKEY, Shaders.toggle)
|
||||
|
||||
shadersPanel = createWidget('ShadersPanel', GameInterface.getMapPanel())
|
||||
shadersPanel:hide()
|
||||
|
||||
local mapComboBox = shadersPanel:getChildById('mapComboBox')
|
||||
mapComboBox.onOptionChange = function(combobox, option)
|
||||
local map = GameInterface.getMapPanel()
|
||||
map:setMapShader(g_shaders.getShader(option))
|
||||
print(option)
|
||||
end
|
||||
|
||||
for name,file in pairs(SHADERS) do
|
||||
local shader = g_shaders.createFragmentShader(name, file)
|
||||
mapComboBox:addOption(name)
|
||||
|
||||
if name == 'Fog' then
|
||||
shader:addMultiTexture('images/clouds.png')
|
||||
end
|
||||
end
|
||||
|
||||
local map = GameInterface.getMapPanel()
|
||||
map:setMapShader(g_shaders.getShader('Default'))
|
||||
end
|
||||
|
||||
function Shaders.terminate()
|
||||
Keyboard.unbindKeyDown(HOTKEY)
|
||||
shadersPanel:destroy()
|
||||
shadersPanel = nil
|
||||
end
|
||||
|
||||
function Shaders.toggle()
|
||||
shadersPanel:setVisible(not shadersPanel:isVisible())
|
||||
end
|
15
modules/game_shaders/shaders.otmod
Normal file
15
modules/game_shaders/shaders.otmod
Normal file
@@ -0,0 +1,15 @@
|
||||
Module
|
||||
name: game_shaders
|
||||
description: Manage game shaders
|
||||
author: edubart
|
||||
website: www.otclient.info
|
||||
|
||||
dependencies:
|
||||
- game
|
||||
|
||||
@onLoad: |
|
||||
dofile 'shaders'
|
||||
Shaders.init()
|
||||
|
||||
@onUnload: |
|
||||
Shaders.terminate()
|
15
modules/game_shaders/shaders.otui
Normal file
15
modules/game_shaders/shaders.otui
Normal file
@@ -0,0 +1,15 @@
|
||||
ShadersPanel < UIWidget
|
||||
focusable: false
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
border-color: red
|
||||
border-width: 1
|
||||
|
||||
width: 100
|
||||
layout:
|
||||
type: verticalBox
|
||||
fit-children: true
|
||||
|
||||
ComboBox
|
||||
id: mapComboBox
|
16
modules/game_shaders/shaders/bloom.frag
Normal file
16
modules/game_shaders/shaders/bloom.frag
Normal file
@@ -0,0 +1,16 @@
|
||||
uniform float u_Time;
|
||||
uniform sampler2D u_Tex0;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_Tex0, v_TexCoord);
|
||||
int j;
|
||||
int i;
|
||||
|
||||
for(i = -2 ;i <= 2; i++)
|
||||
for(j = -2; j <= 2; j++)
|
||||
color += texture2D(u_Tex0, v_TexCoord + vec2(i, j)*0.0025) * 0.025;
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
8
modules/game_shaders/shaders/default.frag
Normal file
8
modules/game_shaders/shaders/default.frag
Normal file
@@ -0,0 +1,8 @@
|
||||
uniform float u_Time;
|
||||
uniform sampler2D u_Tex0;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(u_Tex0, v_TexCoord);
|
||||
}
|
18
modules/game_shaders/shaders/fog.frag
Normal file
18
modules/game_shaders/shaders/fog.frag
Normal file
@@ -0,0 +1,18 @@
|
||||
uniform float u_Time;
|
||||
uniform sampler2D u_Tex0;
|
||||
uniform sampler2D u_Tex1;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
vec2 direction = vec2(1.0,0.3);
|
||||
float speed = 0.05;
|
||||
float pressure = 0.6;
|
||||
float zoom = 0.5;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 offset = (v_TexCoord + (direction * u_Time * speed)) / zoom;
|
||||
vec3 bgcol = texture2D(u_Tex0, v_TexCoord).xyz;
|
||||
vec3 fogcol = texture2D(u_Tex1, offset).xyz;
|
||||
vec3 col = bgcol + fogcol*pressure;
|
||||
gl_FragColor = vec4(col,1.0);
|
||||
}
|
14
modules/game_shaders/shaders/grayscale.frag
Normal file
14
modules/game_shaders/shaders/grayscale.frag
Normal file
@@ -0,0 +1,14 @@
|
||||
uniform float u_Time;
|
||||
uniform sampler2D u_Tex0;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
vec4 grayscale(vec4 color)
|
||||
{
|
||||
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
|
||||
return vec4(gray, gray, gray, 1);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = grayscale(texture2D(u_Tex0, v_TexCoord));
|
||||
}
|
24
modules/game_shaders/shaders/oldtv.frag
Normal file
24
modules/game_shaders/shaders/oldtv.frag
Normal file
@@ -0,0 +1,24 @@
|
||||
uniform float u_Time;
|
||||
varying vec2 v_TexCoord;
|
||||
uniform sampler2D u_Tex0;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 q = v_TexCoord;
|
||||
vec2 uv = 0.5 + (q-0.5)*(0.9 + 0.1*sin(0.2*u_Time));
|
||||
|
||||
vec3 oricol = texture2D(u_Tex0,vec2(q.x,q.y)).xyz;
|
||||
vec3 col = oricol;
|
||||
|
||||
col = clamp(col*0.5+0.5*col*col*1.2,0.0,1.0);
|
||||
|
||||
col *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y);
|
||||
|
||||
col *= vec3(0.8,1.0,0.7);
|
||||
|
||||
col *= 0.9+0.1*sin(10.0*u_Time+uv.y*1000.0);
|
||||
|
||||
col *= 0.97+0.03*sin(110.0*u_Time);
|
||||
|
||||
gl_FragColor = vec4(col,1.0);
|
||||
}
|
13
modules/game_shaders/shaders/party.frag
Normal file
13
modules/game_shaders/shaders/party.frag
Normal file
@@ -0,0 +1,13 @@
|
||||
uniform float u_Time;
|
||||
uniform sampler2D u_Tex0;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = texture2D(u_Tex0, v_TexCoord);
|
||||
float d = u_Time * 2;
|
||||
col.x += (1.0 + sin(d))*0.25;
|
||||
col.y += (1.0 + sin(d*2))*0.25;
|
||||
col.z += (1.0 + sin(d*4))*0.25;
|
||||
gl_FragColor = col;
|
||||
}
|
19
modules/game_shaders/shaders/pulse.frag
Normal file
19
modules/game_shaders/shaders/pulse.frag
Normal file
@@ -0,0 +1,19 @@
|
||||
uniform float u_Time;
|
||||
uniform vec2 u_Resolution;
|
||||
uniform sampler2D u_Tex0;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 halfres = u_Resolution.xy/2.0;
|
||||
vec2 cPos = v_TexCoord.xy * u_Resolution;
|
||||
|
||||
cPos.x -= 0.5*halfres.x*sin(u_Time/2.0)+0.3*halfres.x*cos(u_Time)+halfres.x;
|
||||
cPos.y -= 0.4*halfres.y*sin(u_Time/5.0)+0.3*halfres.y*cos(u_Time)+halfres.y;
|
||||
float cLength = length(cPos);
|
||||
|
||||
vec2 uv = v_TexCoord.xy+ ((cPos/cLength)*sin(cLength/30.0-u_Time*10.0)/25.0)*0.15;
|
||||
vec3 col = texture2D(u_Tex0,uv).xyz * 250.0/cLength;
|
||||
|
||||
gl_FragColor = vec4(col,1.0);
|
||||
}
|
46
modules/game_shaders/shaders/radialblur.frag
Normal file
46
modules/game_shaders/shaders/radialblur.frag
Normal file
@@ -0,0 +1,46 @@
|
||||
uniform sampler2D u_Tex0;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
// some const, tweak for best look
|
||||
const float sampleDist = 1.0;
|
||||
const float sampleStrength = 2.2;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// some sample positions
|
||||
float samples[10] =
|
||||
float[](-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08);
|
||||
|
||||
// 0.5,0.5 is the center of the screen
|
||||
// so substracting v_TexCoord from it will result in
|
||||
// a vector pointing to the middle of the screen
|
||||
vec2 dir = 0.5 - v_TexCoord;
|
||||
|
||||
// calculate the distance to the center of the screen
|
||||
float dist = sqrt(dir.x*dir.x + dir.y*dir.y);
|
||||
|
||||
// normalize the direction (reuse the distance)
|
||||
dir = dir/dist;
|
||||
|
||||
// this is the original colour of this fragment
|
||||
// using only this would result in a nonblurred version
|
||||
vec4 color = texture2D(u_Tex0,v_TexCoord);
|
||||
|
||||
vec4 sum = color;
|
||||
|
||||
// take 10 additional blur samples in the direction towards
|
||||
// the center of the screen
|
||||
for(int i = 0; i < 10; i++)
|
||||
sum += texture2D(u_Tex0, v_TexCoord + dir * samples[i] * sampleDist);
|
||||
|
||||
// we have taken eleven samples
|
||||
sum *= 1.0/11.0;
|
||||
|
||||
// weighten the blur effect with the distance to the
|
||||
// center of the screen ( further out is blurred more)
|
||||
float t = dist * sampleStrength;
|
||||
t = clamp(t ,0.0,1.0); //0 <= t <= 1
|
||||
|
||||
//Blend the original color with the averaged pixels
|
||||
gl_FragColor = mix(color, sum, t);
|
||||
}
|
16
modules/game_shaders/shaders/sepia.frag
Normal file
16
modules/game_shaders/shaders/sepia.frag
Normal file
@@ -0,0 +1,16 @@
|
||||
uniform float u_Time;
|
||||
uniform sampler2D u_Tex0;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
vec4 sepia(vec4 color)
|
||||
{
|
||||
return vec4(dot(color, vec4(.393, .769, .189, .0)),
|
||||
dot(color, vec4(.349, .686, .168, .0)),
|
||||
dot(color, vec4(.272, .534, .131, .0)),
|
||||
1);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = sepia(texture2D(u_Tex0, v_TexCoord));
|
||||
}
|
13
modules/game_shaders/shaders/zomg.frag
Normal file
13
modules/game_shaders/shaders/zomg.frag
Normal file
@@ -0,0 +1,13 @@
|
||||
uniform sampler2D u_Tex0;
|
||||
uniform float u_Time;
|
||||
varying vec2 v_TexCoord;
|
||||
|
||||
vec2 tibiaDir = vec2(1.0, 1.0);
|
||||
void main(void)
|
||||
{
|
||||
vec2 dir = 0.5 - v_TexCoord;
|
||||
float dist = sqrt(dir.x*dir.x + dir.y*dir.y);
|
||||
float scale = 0.8 + dist*0.5;
|
||||
vec4 color = texture2D(u_Tex0, -(dir*scale - 0.5));
|
||||
gl_FragColor = color;
|
||||
}
|
Reference in New Issue
Block a user