diff --git a/examples/06-bump/fs_bump.sc b/examples/06-bump/fs_bump.sc index fe530bd1..e1e508d6 100644 --- a/examples/06-bump/fs_bump.sc +++ b/examples/06-bump/fs_bump.sc @@ -41,16 +41,6 @@ vec4 powRgba(vec4 _rgba, float _pow) return result; } -vec4 toLinear(vec4 _rgba) -{ - return powRgba(_rgba, 2.2); -} - -vec4 toGamma(vec4 _rgba) -{ - return powRgba(_rgba, 1.0/2.2); -} - vec3 calcLight(int _idx, mat3 _tbn, vec3 _wpos, vec3 _normal, vec3 _view) { vec3 lp = u_lightPosRadius[_idx].xyz - _wpos; diff --git a/examples/runtime/shaders/gles/fs_bump.bin b/examples/runtime/shaders/gles/fs_bump.bin index cef661ba..b1296e55 100644 Binary files a/examples/runtime/shaders/gles/fs_bump.bin and b/examples/runtime/shaders/gles/fs_bump.bin differ diff --git a/examples/runtime/shaders/glsl/fs_bump.bin b/examples/runtime/shaders/glsl/fs_bump.bin index 4b235f82..d7bc7adb 100644 Binary files a/examples/runtime/shaders/glsl/fs_bump.bin and b/examples/runtime/shaders/glsl/fs_bump.bin differ diff --git a/makefile b/makefile index e0380817..a1b7297a 100755 --- a/makefile +++ b/makefile @@ -78,6 +78,16 @@ osx-release64: make -C .build/projects/gmake-osx config=release64 osx: osx-debug32 osx-release32 osx-debug64 osx-release64 +rebuild-shaders: + make -C examples/01-cubes rebuild + make -C examples/02-metaballs rebuild + make -C examples/03-raymarch rebuild + make -C examples/04-mesh rebuild + make -C examples/05-instancing rebuild + make -C examples/06-bump rebuild + make -C examples/07-callback rebuild + make -C examples/08-update rebuild + docs: markdown README.md > .build/docs/readme.html diff --git a/src/dds.cpp b/src/dds.cpp index 1a6eb0cf..6c0e99da 100644 --- a/src/dds.cpp +++ b/src/dds.cpp @@ -21,7 +21,9 @@ namespace bgfx #define DDS_DXT4 BX_MAKEFOURCC('D', 'X', 'T', '4') #define DDS_DXT5 BX_MAKEFOURCC('D', 'X', 'T', '5') #define DDS_ATI1 BX_MAKEFOURCC('A', 'T', 'I', '1') +#define DDS_BC4U BX_MAKEFOURCC('B', 'C', '4', 'U') #define DDS_ATI2 BX_MAKEFOURCC('A', 'T', 'I', '2') +#define DDS_BC5U BX_MAKEFOURCC('B', 'C', '5', 'U') #define D3DFMT_A16B16G16R16 36 #define D3DFMT_A16B16G16R16F 113 @@ -466,34 +468,36 @@ bool parseDds(Dds& _dds, const Memory* _mem) { case DDS_DXT1: type = TextureFormat::BC1; - blockSize = 8; bpp = 4; + blockSize = 4*4*bpp/8; break; case DDS_DXT2: case DDS_DXT3: type = TextureFormat::BC2; - blockSize = 16; - bpp = 4; + bpp = 8; + blockSize = 4*4*bpp/8; break; case DDS_DXT4: case DDS_DXT5: type = TextureFormat::BC3; - blockSize = 16; - bpp = 4; + bpp = 8; + blockSize = 4*4*bpp/8; break; case DDS_ATI1: + case DDS_BC4U: type = TextureFormat::BC4; - blockSize = 16; bpp = 4; + blockSize = 4*4*bpp/8; break; case DDS_ATI2: + case DDS_BC5U: type = TextureFormat::BC5; - blockSize = 16; - bpp = 4; + bpp = 8; + blockSize = 4*4*bpp/8; break; case D3DFMT_A16B16G16R16: diff --git a/tools/bin/shaderc.exe b/tools/bin/shaderc.exe index 1b6a0170..070af950 100644 Binary files a/tools/bin/shaderc.exe and b/tools/bin/shaderc.exe differ diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index 1b3e606b..fd393c8b 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -1478,96 +1478,103 @@ int main(int _argc, const char* _argv[]) } } - const size_t padding = 16; - uint32_t size = (uint32_t)fsize(file); - char* data = new char[size+padding]; - size = (uint32_t)fread(data, 1, size, file); - memset(&data[size], 0, padding); - fclose(file); + const size_t padding = 16; + uint32_t size = (uint32_t)fsize(file); + char* data = new char[size+padding+1]; + size = (uint32_t)fread(data, 1, size, file); + // Compiler generates "error X3000: syntax error: unexpected end of file" + // if input doesn't have empty line at EOF. + data[size] = '\n'; + memset(&data[size+1], 0, padding); + fclose(file); + + char* entry = strstr(data, "void main()"); + if (NULL == entry) + { + fprintf(stderr, "Shader entry point 'void main()' is not found.\n"); + } + else + { + InOut shaderInputs; + InOut shaderOutputs; + uint32_t inputHash = 0; + uint32_t outputHash = 0; - InOut shaderInputs; - InOut shaderOutputs; - uint32_t inputHash = 0; - uint32_t outputHash = 0; - - const char* input = data; - while (input[0] == '$') - { - const char* str = input+1; - const char* eol = bx::streol(str); - const char* nl = bx::strnl(eol); - input = nl; - - if (0 == strncmp(str, "input", 5) ) + const char* input = data; + while (input[0] == '$') { - str += 5; - inputHash = parseInOut(shaderInputs, str, eol); - } - else if (0 == strncmp(str, "output", 6) ) - { - str += 6; - outputHash = parseInOut(shaderOutputs, str, eol); - } - } + const char* str = input+1; + const char* eol = bx::streol(str); + const char* nl = bx::strnl(eol); + input = nl; - if (glsl) - { - preprocessor.writef( - "#define ivec2 vec2\n" - "#define ivec3 vec3\n" - "#define ivec4 vec4\n" - ); - - - for (InOut::const_iterator it = shaderInputs.begin(), itEnd = shaderInputs.end(); it != itEnd; ++it) - { - VaryingMap::const_iterator varyingIt = varyingMap.find(*it); - if (varyingIt != varyingMap.end() ) + if (0 == strncmp(str, "input", 5) ) { - const Varying& var = varyingIt->second; - const char* name = var.m_name.c_str(); - if (0 == strncmp(name, "a_", 2) - || 0 == strncmp(name, "i_", 2) ) - { - preprocessor.writef("attribute %s %s;\n", var.m_type.c_str(), name); - } - else - { - preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), name); - } + str += 5; + inputHash = parseInOut(shaderInputs, str, eol); + } + else if (0 == strncmp(str, "output", 6) ) + { + str += 6; + outputHash = parseInOut(shaderOutputs, str, eol); } } - for (InOut::const_iterator it = shaderOutputs.begin(), itEnd = shaderOutputs.end(); it != itEnd; ++it) + if (glsl) { - VaryingMap::const_iterator varyingIt = varyingMap.find(*it); - if (varyingIt != varyingMap.end() ) + preprocessor.writef( + "#define ivec2 vec2\n" + "#define ivec3 vec3\n" + "#define ivec4 vec4\n" + ); + + + for (InOut::const_iterator it = shaderInputs.begin(), itEnd = shaderInputs.end(); it != itEnd; ++it) { - const Varying& var = varyingIt->second; - preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), var.m_name.c_str() ); + VaryingMap::const_iterator varyingIt = varyingMap.find(*it); + if (varyingIt != varyingMap.end() ) + { + const Varying& var = varyingIt->second; + const char* name = var.m_name.c_str(); + if (0 == strncmp(name, "a_", 2) + || 0 == strncmp(name, "i_", 2) ) + { + preprocessor.writef("attribute %s %s;\n", var.m_type.c_str(), name); + } + else + { + preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), name); + } + } + } + + for (InOut::const_iterator it = shaderOutputs.begin(), itEnd = shaderOutputs.end(); it != itEnd; ++it) + { + VaryingMap::const_iterator varyingIt = varyingMap.find(*it); + if (varyingIt != varyingMap.end() ) + { + const Varying& var = varyingIt->second; + preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), var.m_name.c_str() ); + } } } - } - else - { - preprocessor.writef( - "#define lowp\n" - "#define mediump\n" - "#define highp\n" - "#define ivec2 int2\n" - "#define ivec3 int3\n" - "#define ivec4 int4\n" - "#define vec2 float2\n" - "#define vec3 float3\n" - "#define vec4 float4\n" - "#define mat2 float2x2\n" - "#define mat3 float3x3\n" - "#define mat4 float4x4\n" - ); - - char* entry = strstr(data, "void main()"); - if (NULL != entry) + else { + preprocessor.writef( + "#define lowp\n" + "#define mediump\n" + "#define highp\n" + "#define ivec2 int2\n" + "#define ivec3 int3\n" + "#define ivec4 int4\n" + "#define vec2 float2\n" + "#define vec3 float3\n" + "#define vec4 float4\n" + "#define mat2 float2x2\n" + "#define mat3 float3x3\n" + "#define mat4 float4x4\n" + ); + entry[4] = '_'; if (fragment) @@ -1667,109 +1674,109 @@ int main(int _argc, const char* _argv[]) ); } } - } - if (preprocessor.run(input) ) - { - BX_TRACE("Input file: %s", filePath); - BX_TRACE("Output file: %s", outFilePath); - - if (preprocessOnly) + if (preprocessor.run(input) ) { - bx::CrtFileWriter writer; + BX_TRACE("Input file: %s", filePath); + BX_TRACE("Output file: %s", outFilePath); - if (0 != writer.open(outFilePath) ) + if (preprocessOnly) { - fprintf(stderr, "Unable to open output file '%s'.", outFilePath); - return false; - } - - if (glsl) - { - const char* profile = cmdLine.findOption('p', "profile"); - if (NULL == profile) - { - writef(&writer, "#ifdef GL_ES\n"); - writef(&writer, "precision highp float;\n"); - writef(&writer, "#endif // GL_ES\n\n"); - } - else - { - writef(&writer, "#version %s\n\n", profile); - } - } - writer.write(preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() ); - writer.close(); - - return EXIT_SUCCESS; - } - - bool compiled = false; - - { - bx::CrtFileWriter* writer = NULL; - - if (NULL != bin2c) - { - writer = new Bin2cWriter(bin2c); - } - else - { - writer = new bx::CrtFileWriter; - } - - if (0 != writer->open(outFilePath) ) - { - fprintf(stderr, "Unable to open output file '%s'.", outFilePath); - return false; - } - - if (fragment) - { - bx::write(writer, BGFX_CHUNK_MAGIC_FSH); - bx::write(writer, inputHash); - } - else - { - bx::write(writer, BGFX_CHUNK_MAGIC_VSH); - bx::write(writer, outputHash); - } - - if (glsl) - { - compiled = compileGLSLShader(cmdLine, preprocessor.m_preprocessed, writer); - } - else - { - if (hlsl > 3) - { - compiled = compileHLSLShaderDx11(cmdLine, preprocessor.m_preprocessed, writer); - } - else - { - compiled = compileHLSLShaderDx9(cmdLine, preprocessor.m_preprocessed, writer); - } - } - - writer->close(); - delete writer; - } - - if (compiled) - { - if (depends) - { - std::string ofp = outFilePath; - ofp += ".d"; bx::CrtFileWriter writer; - if (0 == writer.open(ofp.c_str() ) ) + + if (0 != writer.open(outFilePath) ) { - writef(&writer, "%s : %s\n", outFilePath, preprocessor.m_depends.c_str() ); - writer.close(); + fprintf(stderr, "Unable to open output file '%s'.", outFilePath); + return false; } + + if (glsl) + { + const char* profile = cmdLine.findOption('p', "profile"); + if (NULL == profile) + { + writef(&writer, "#ifdef GL_ES\n"); + writef(&writer, "precision highp float;\n"); + writef(&writer, "#endif // GL_ES\n\n"); + } + else + { + writef(&writer, "#version %s\n\n", profile); + } + } + writer.write(preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() ); + writer.close(); + + return EXIT_SUCCESS; } - return EXIT_SUCCESS; + bool compiled = false; + + { + bx::CrtFileWriter* writer = NULL; + + if (NULL != bin2c) + { + writer = new Bin2cWriter(bin2c); + } + else + { + writer = new bx::CrtFileWriter; + } + + if (0 != writer->open(outFilePath) ) + { + fprintf(stderr, "Unable to open output file '%s'.", outFilePath); + return false; + } + + if (fragment) + { + bx::write(writer, BGFX_CHUNK_MAGIC_FSH); + bx::write(writer, inputHash); + } + else + { + bx::write(writer, BGFX_CHUNK_MAGIC_VSH); + bx::write(writer, outputHash); + } + + if (glsl) + { + compiled = compileGLSLShader(cmdLine, preprocessor.m_preprocessed, writer); + } + else + { + if (hlsl > 3) + { + compiled = compileHLSLShaderDx11(cmdLine, preprocessor.m_preprocessed, writer); + } + else + { + compiled = compileHLSLShaderDx9(cmdLine, preprocessor.m_preprocessed, writer); + } + } + + writer->close(); + delete writer; + } + + if (compiled) + { + if (depends) + { + std::string ofp = outFilePath; + ofp += ".d"; + bx::CrtFileWriter writer; + if (0 == writer.open(ofp.c_str() ) ) + { + writef(&writer, "%s : %s\n", outFilePath, preprocessor.m_depends.c_str() ); + writer.close(); + } + } + + return EXIT_SUCCESS; + } } }