parent
318109158a
commit
83f86eac64
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;
|
|
||||||
}
|
|
||||||
*/
|
|
@ -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
|
@ -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()
|
@ -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
|
@ -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;
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "paintershadermanager.h"
|
|
||||||
#include "painterogl2.h"
|
|
||||||
#include "texture.h"
|
|
||||||
#include "painterogl2_shadersources.h"
|
|
||||||
#include "paintershaderprogram.h"
|
|
||||||
#include "shaderprogram.h"
|
|
||||||
#include "graphics.h"
|
|
||||||
|
|
||||||
PainterShaderManager g_shaders;
|
|
||||||
|
|
||||||
void PainterShaderManager::init()
|
|
||||||
{
|
|
||||||
m_drawTexturedProgram = createShader();
|
|
||||||
assert(m_drawTexturedProgram);
|
|
||||||
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
|
||||||
m_drawTexturedProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslTextureSrcFragmentShader);
|
|
||||||
m_drawTexturedProgram->link();
|
|
||||||
|
|
||||||
m_drawSolidColorProgram = createShader();
|
|
||||||
assert(m_drawSolidColorProgram);
|
|
||||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
|
|
||||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
|
|
||||||
m_drawSolidColorProgram->link();
|
|
||||||
|
|
||||||
PainterShaderProgram::release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PainterShaderManager::terminate()
|
|
||||||
{
|
|
||||||
m_drawTexturedProgram = nullptr;
|
|
||||||
m_drawSolidColorProgram = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
PainterShaderProgramPtr PainterShaderManager::createShader()
|
|
||||||
{
|
|
||||||
if(!g_graphics.canUseShaders())
|
|
||||||
return nullptr;
|
|
||||||
return PainterShaderProgramPtr(new PainterShaderProgram);
|
|
||||||
}
|
|
||||||
|
|
||||||
PainterShaderProgramPtr PainterShaderManager::createTexturedFragmentShader(const std::string& shaderFile)
|
|
||||||
{
|
|
||||||
PainterShaderProgramPtr shader = createShader();
|
|
||||||
if(!shader)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
shader->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
|
||||||
shader->addShaderFromSourceFile(Shader::Fragment, shaderFile);
|
|
||||||
|
|
||||||
if(!shader->link())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "gameshadermanager.h"
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GAMESHADERMANAGER_H
|
|
||||||
#define GAMESHADERMANAGER_H
|
|
||||||
|
|
||||||
class GameShaderManager
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "shadermanager.h"
|
||||||
|
#include <framework/graphics/paintershaderprogram.h>
|
||||||
|
#include <framework/graphics/graphics.h>
|
||||||
|
#include <framework/graphics/painterogl2_shadersources.h>
|
||||||
|
|
||||||
|
ShaderManager g_shaders;
|
||||||
|
|
||||||
|
void ShaderManager::init()
|
||||||
|
{
|
||||||
|
if(!g_graphics.canUseShaders())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_defaultItemShader = createFragmentShaderFromCode("Item", glslMainFragmentShader + glslTextureSrcFragmentShader);
|
||||||
|
setupItemShader(m_defaultItemShader);
|
||||||
|
|
||||||
|
m_defaultMapShader = createFragmentShaderFromCode("Map", glslMainFragmentShader + glslTextureSrcFragmentShader);
|
||||||
|
|
||||||
|
PainterShaderProgram::release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderManager::terminate()
|
||||||
|
{
|
||||||
|
m_defaultItemShader = nullptr;
|
||||||
|
m_defaultMapShader = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PainterShaderProgramPtr ShaderManager::createShader(const std::string& name)
|
||||||
|
{
|
||||||
|
if(!g_graphics.canUseShaders()) {
|
||||||
|
g_logger.error(stdext::format("unable to create shader, shaders are not supported"));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PainterShaderProgramPtr shader(new PainterShaderProgram);
|
||||||
|
m_shaders[name] = shader;
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
PainterShaderProgramPtr ShaderManager::createFragmentShader(const std::string& name, const std::string& file)
|
||||||
|
{
|
||||||
|
PainterShaderProgramPtr shader = createShader(name);
|
||||||
|
if(!shader)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
shader->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
||||||
|
if(!shader->addShaderFromSourceFile(Shader::Fragment, file)) {
|
||||||
|
g_logger.error(stdext::format("unable to load fragment shader '%s' from source file '%s'", name, file));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!shader->link()) {
|
||||||
|
g_logger.error(stdext::format("unable to link shader '%s' from file '%s'", name, file));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_shaders[name] = shader;
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
PainterShaderProgramPtr ShaderManager::createFragmentShaderFromCode(const std::string& name, const std::string& code)
|
||||||
|
{
|
||||||
|
PainterShaderProgramPtr shader = createShader(name);
|
||||||
|
if(!shader)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
shader->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
||||||
|
if(!shader->addShaderFromSourceCode(Shader::Fragment, code)) {
|
||||||
|
g_logger.error(stdext::format("unable to load fragment shader '%s'", name));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!shader->link()) {
|
||||||
|
g_logger.error(stdext::format("unable to link shader '%s'", name));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_shaders[name] = shader;
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
PainterShaderProgramPtr ShaderManager::createItemShader(const std::string& name, const std::string& file)
|
||||||
|
{
|
||||||
|
PainterShaderProgramPtr shader = createFragmentShader(name, file);
|
||||||
|
if(shader)
|
||||||
|
setupItemShader(shader);
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderManager::setupItemShader(const PainterShaderProgramPtr& shader)
|
||||||
|
{
|
||||||
|
if(!shader)
|
||||||
|
return;
|
||||||
|
shader->bindUniformLocation(ITEM_ID_UNIFORM, "u_ItemId");
|
||||||
|
}
|
||||||
|
|
||||||
|
PainterShaderProgramPtr ShaderManager::getShader(const std::string& name)
|
||||||
|
{
|
||||||
|
auto it = m_shaders.find(name);
|
||||||
|
if(it != m_shaders.end())
|
||||||
|
return it->second;
|
||||||
|
return nullptr;
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GAMESHADERS_H
|
||||||
|
#define GAMESHADERS_H
|
||||||
|
|
||||||
|
#include "declarations.h"
|
||||||
|
#include <framework/graphics/paintershaderprogram.h>
|
||||||
|
|
||||||
|
class ShaderManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum {
|
||||||
|
ITEM_ID_UNIFORM = 10
|
||||||
|
};
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void terminate();
|
||||||
|
|
||||||
|
PainterShaderProgramPtr createShader(const std::string& name);
|
||||||
|
PainterShaderProgramPtr createFragmentShader(const std::string& name, const std::string& file);
|
||||||
|
PainterShaderProgramPtr createFragmentShaderFromCode(const std::string& name, const std::string& code);
|
||||||
|
|
||||||
|
PainterShaderProgramPtr createItemShader(const std::string& name, const std::string& file);
|
||||||
|
PainterShaderProgramPtr createMapShader(const std::string& name, const std::string& file) { return createFragmentShader(name, file); }
|
||||||
|
|
||||||
|
PainterShaderProgramPtr getDefaultItemShader() { return m_defaultItemShader; }
|
||||||
|
PainterShaderProgramPtr getDefaultMapShader() { return m_defaultMapShader; }
|
||||||
|
|
||||||
|
PainterShaderProgramPtr getShader(const std::string& name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupItemShader(const PainterShaderProgramPtr& shader);
|
||||||
|
|
||||||
|
PainterShaderProgramPtr m_defaultItemShader;
|
||||||
|
PainterShaderProgramPtr m_defaultMapShader;
|
||||||
|
std::unordered_map<std::string, PainterShaderProgramPtr> m_shaders;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extern ShaderManager g_shaders;
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in new issue