diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp index 4a73940f36..85650fb322 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp @@ -401,17 +401,25 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) void SpriteBlur::initGLProgram() { - GLchar * fragSource = (GLchar*) FileUtils::getInstance()->getStringFromFile( - FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh")).c_str(); - auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, fragSource); + GLchar * fragSource = nullptr; +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) + fragSource = (GLchar*) String::createWithContentsOfFile( + FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString(); +#else + fragSource = (GLchar*)String::createWithContentsOfFile( + FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur_winrt.fsh").c_str())->getCString(); +#endif + auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, fragSource); auto glProgramState = GLProgramState::getOrCreateWithGLProgram(program); setGLProgramState(glProgramState); auto size = getTexture()->getContentSizeInPixels(); getGLProgramState()->setUniformVec2("resolution", size); +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) getGLProgramState()->setUniformFloat("blurRadius", _blurRadius); getGLProgramState()->setUniformFloat("sampleNum", 7.0f); +#endif } void SpriteBlur::setBlurRadius(float radius) @@ -487,7 +495,6 @@ bool ShaderBlur::init() { if( ShaderTestDemo::init() ) { -#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) _blurSprite = SpriteBlur::create("Images/grossini.png"); auto sprite = Sprite::create("Images/grossini.png"); auto s = Director::getInstance()->getWinSize(); @@ -496,7 +503,7 @@ bool ShaderBlur::init() addChild(_blurSprite); addChild(sprite); - +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) createSliderCtls(); #endif return true; diff --git a/tests/cpp-tests/Resources/Shaders/example_Blur_winrt.fsh b/tests/cpp-tests/Resources/Shaders/example_Blur_winrt.fsh new file mode 100644 index 0000000000..872b30f234 --- /dev/null +++ b/tests/cpp-tests/Resources/Shaders/example_Blur_winrt.fsh @@ -0,0 +1,36 @@ +#ifdef GL_ES +precision mediump float; +#endif + +varying vec4 v_fragmentColor; +varying vec2 v_texCoord; + +uniform vec2 resolution; + +vec4 blur(vec2); + +void main(void) +{ + vec4 col = blur(v_texCoord); //* v_fragmentColor.rgb; + gl_FragColor = vec4(col) * v_fragmentColor; +} + +vec4 blur(vec2 p) +{ + vec4 col = vec4(0); + vec2 unit = 1.0 / resolution.xy; + + float count = 0.0; + + for(float x = -4.0; x <= 4.0; x += 2.0) + { + for(float y = -4.0; y <= 4.0; y += 2.0) + { + float weight = (4.0 - abs(x)) * (4.0 - abs(y)); + col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)) * weight; + count += weight; + } + } + + return col / count; +}