Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
Bonzomatic
Commits
e1a2ca90
Commit
e1a2ca90
authored
Feb 17, 2015
by
Gargaj
Browse files
add code for substitute-tokens to automatically insert incoming textures to default shader
parent
5bbd67d0
Changes
4
Hide whitespace changes
Inline
Side-by-side
main.cpp
View file @
e1a2ca90
...
...
@@ -10,6 +10,35 @@
#include "external/scintilla/src/UniConversion.h"
#include "external/jsonxx/jsonxx.h"
void
ReplaceTokens
(
std
::
string
&
sDefShader
,
const
char
*
sTokenBegin
,
const
char
*
sTokenName
,
const
char
*
sTokenEnd
,
std
::
vector
<
std
::
string
>
&
tokens
)
{
if
(
sDefShader
.
find
(
sTokenBegin
)
!=
std
::
string
::
npos
&&
sDefShader
.
find
(
sTokenName
)
!=
std
::
string
::
npos
&&
sDefShader
.
find
(
sTokenEnd
)
!=
std
::
string
::
npos
&&
sDefShader
.
find
(
sTokenBegin
)
<
sDefShader
.
find
(
sTokenName
)
&&
sDefShader
.
find
(
sTokenName
)
<
sDefShader
.
find
(
sTokenEnd
))
{
int
nTokenStart
=
sDefShader
.
find
(
sTokenBegin
)
+
strlen
(
sTokenBegin
);
std
::
string
sTextureToken
=
sDefShader
.
substr
(
nTokenStart
,
sDefShader
.
find
(
sTokenEnd
)
-
nTokenStart
);
std
::
string
sFinalShader
;
sFinalShader
=
sDefShader
.
substr
(
0
,
sDefShader
.
find
(
sTokenBegin
)
);
//for (std::map<std::string, Renderer::Texture*>::iterator it = tokens.begin(); it != tokens.end(); it++)
for
(
int
i
=
0
;
i
<
tokens
.
size
();
i
++
)
{
std
::
string
s
=
sTextureToken
;
while
(
s
.
find
(
sTokenName
)
!=
std
::
string
::
npos
)
{
s
.
replace
(
s
.
find
(
sTokenName
),
strlen
(
sTokenName
),
tokens
[
i
],
0
,
std
::
string
::
npos
);
}
sFinalShader
+=
s
;
}
sFinalShader
+=
sDefShader
.
substr
(
sDefShader
.
find
(
sTokenEnd
)
+
strlen
(
sTokenEnd
),
std
::
string
::
npos
);
sDefShader
=
sFinalShader
;
}
}
int
main
()
{
RENDERER_SETTINGS
settings
;
...
...
@@ -116,7 +145,19 @@ int main()
}
if
(
!
shaderInitSuccessful
)
{
strncpy
(
szShader
,
Renderer
::
defaultShader
,
65535
);
std
::
string
sDefShader
=
Renderer
::
defaultShader
;
std
::
vector
<
std
::
string
>
tokens
;
for
(
std
::
map
<
std
::
string
,
Renderer
::
Texture
*>::
iterator
it
=
textures
.
begin
();
it
!=
textures
.
end
();
it
++
)
tokens
.
push_back
(
it
->
first
);
ReplaceTokens
(
sDefShader
,
"{%textures:begin%}"
,
"{%textures:name%}"
,
"{%textures:end%}"
,
tokens
);
tokens
.
clear
();
for
(
std
::
map
<
int
,
std
::
string
>::
iterator
it
=
midiRoutes
.
begin
();
it
!=
midiRoutes
.
end
();
it
++
)
tokens
.
push_back
(
it
->
second
);
ReplaceTokens
(
sDefShader
,
"{%midi:begin%}"
,
"{%midi:name%}"
,
"{%midi:end%}"
,
tokens
);
strncpy
(
szShader
,
sDefShader
.
c_str
(),
65535
);
if
(
!
Renderer
::
ReloadShader
(
szShader
,
strlen
(
szShader
),
szError
,
4096
))
{
puts
(
szError
);
...
...
platform_sdl/Renderer.cpp
View file @
e1a2ca90
...
...
@@ -107,34 +107,22 @@ namespace Renderer
char
defaultShader
[
65536
]
=
"#version 430 core
\n
"
"
\n
"
"///////////////////////////////////////////////////////////////////////////////
\n
"
"// shader inputs/outputs
\n
"
"uniform float fGlobalTime; // in seconds
\n
"
"uniform vec2 v2Resolution; // viewport resolution (in pixels) (1080p or 720p)
\n
"
// "uniform mat4 iMidiPad; // 16 buttons of midi controller\n"
// "uniform float iMidiPadValue; // sum of all elements in iMidiPad/16\n"
"uniform vec2 v2Resolution; // viewport resolution (in pixels)
\n
"
"
\n
"
"// all samplers have linear filtering applied, wrapping set to repeat
\n
"
"uniform sampler1D texFFT; // 1024
\n
"
// "uniform float iFFT[8]; // latest frame\n"
// "uniform float iFFTs[8]; // smoothed latest frame\n"
// "uniform sampler2D iFFTsHistory; // smoothed fft history, 8x1024, x coord = bin, y coord n-frames earlier, y=0 is latest frame\n"
"uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
\n
"
"{%textures:begin%}"
// leave off \n here
"uniform sampler2D {%textures:name%};
\n
"
"{%textures:end%}"
// leave off \n here
"{%midi:begin%}"
// leave off \n here
"float {%midi:name%};
\n
"
"{%midi:end%}"
// leave off \n here
"
\n
"
"// predefined textures
\n
"
"uniform sampler2D texTex1;
\n
"
"uniform sampler2D texTex2;
\n
"
"uniform sampler2D texTex3;
\n
"
"uniform sampler2D texTex4;
\n
"
"uniform sampler2D texNoise;
\n
"
"uniform sampler2D texChecker;
\n
"
"
\n
"
"// out_color must be written in order to see anything
\n
"
"layout(location = 0) out vec4 out_color;
\n
"
"///////////////////////////////////////////////////////////////////////////////
\n
"
"layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
\n
"
"
\n
"
"void main(void)
\n
"
"{
\n
"
" vec2 uv =
vec2( gl_FragCoord.xy ) / v2Resolution
;
\n
"
" vec2 uv =
gl_TexCoord[0].xy
;
\n
"
;
" uv -= 0.5;
\n
"
" uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
\n
"
"
\n
"
...
...
platform_w32_dx11/Renderer.cpp
View file @
e1a2ca90
...
...
@@ -62,19 +62,19 @@ namespace Renderer
{
char
*
defaultShaderFilename
=
"shader.dx11.hlsl"
;
char
defaultShader
[
65536
]
=
"Texture2D texFFT;
\n
"
"Texture2D texNoise;
\n
"
"Texture2D texChecker;
\n
"
"Texture2D texTex1;
\n
"
"Texture2D texTex2;
\n
"
"Texture2D texTex3;
\n
"
"Texture2D texTex4;
\n
"
"{%textures:begin%}"
// leave off \n here
"Texture2D {%textures:name%};
\n
"
"{%textures:end%}"
// leave off \n here
"Texture1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
\n
"
"SamplerState smp;
\n
"
"
\n
"
"cbuffer constants
\n
"
"{
\n
"
" float fGlobalTime;
\n
"
" float2 v2Resolution;
\n
"
" float fGlobalTime; // in seconds
\n
"
" float2 v2Resolution; // viewport resolution (in pixels)
\n
"
"{%midi:begin%}"
" float {%midi:name%};
\n
"
"{%midi:end%}"
"}
\n
"
"
\n
"
"float4 main( float4 position : SV_POSITION, float2 TexCoord : TEXCOORD ) : SV_TARGET
\n
"
...
...
@@ -385,7 +385,8 @@ namespace Renderer
ID3D11InputLayout
*
pFullscreenQuadLayout
=
NULL
;
ID3D11SamplerState
*
pFullscreenQuadSamplerState
=
NULL
;
ID3D11Buffer
*
pFullscreenQuadConstantBuffer
=
NULL
;
unsigned
char
pFullscreenQuadConstants
[
128
];
#define FULLSCREENQUADCONSTANTS_SIZE 512
unsigned
char
pFullscreenQuadConstants
[
FULLSCREENQUADCONSTANTS_SIZE
];
ID3D11BlendState
*
pFullscreenQuadBlendState
=
NULL
;
ID3D11RasterizerState
*
pFullscreenQuadRasterizerState
=
NULL
;
...
...
platform_w32_dx9/Renderer.cpp
View file @
e1a2ca90
...
...
@@ -60,15 +60,17 @@ namespace Renderer
char
*
defaultShaderFilename
=
"shader.dx9.hlsl"
;
char
defaultShader
[
65536
]
=
"texture texTFFT; sampler1D texFFT = sampler_state { Texture = <texTFFT>; };
\n
"
"texture texTNoise; sampler2D texNoise = sampler_state { Texture = <texTNoise>; };
\n
"
"texture texTChecker; sampler2D texChecker = sampler_state { Texture = <texTChecker>; };
\n
"
"texture texTTex1; sampler2D texTex1 = sampler_state { Texture = <texTTex1>; };
\n
"
"texture texTTex2; sampler2D texTex2 = sampler_state { Texture = <texTTex2>; };
\n
"
"texture texTTex3; sampler2D texTex3 = sampler_state { Texture = <texTTex3>; };
\n
"
"texture texTTex4; sampler2D texTex4 = sampler_state { Texture = <texTTex4>; };
\n
"
"// towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
\n
"
"
\n
"
"float fGlobalTime;
\n
"
"float2 v2Resolution;
\n
"
"{%textures:begin%}"
// leave off \n here
"texture raw{%textures:name%}; sampler2D {%textures:name%} = sampler_state { Texture = <raw{%textures:name%}>; };
\n
"
"{%textures:end%}"
"
\n
"
"{%midi:begin%}"
// leave off \n here
"float {%midi:name%};
\n
"
"{%midi:end%}"
"float fGlobalTime; // in seconds
\n
"
"float2 v2Resolution; // viewport resolution (in pixels)
\n
"
"
\n
"
"float4 main( float2 TexCoord : TEXCOORD0 ) : COLOR0
\n
"
"{
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment