mirror of
https://github.com/ReactionQuake3/reaction.git
synced 2024-11-10 07:11:36 +00:00
Remove DiffuseRoughness shader param, add SpecularExponent shader param
This commit is contained in:
parent
a19627d2c9
commit
0296de3d1a
5 changed files with 154 additions and 158 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
- Remove DiffuseRoughness shader param, add SpecularExponent shader param
|
||||||
- Change R_SubdividePatchToGrid() to subdivide patches more evenly
|
- Change R_SubdividePatchToGrid() to subdivide patches more evenly
|
||||||
- Calculate tangent space in fragment shader instead of storing per vertex
|
- Calculate tangent space in fragment shader instead of storing per vertex
|
||||||
- Fix sun flare with sky portals. Sun flare must be inside sky portal.
|
- Fix sun flare with sky portals. Sun flare must be inside sky portal.
|
||||||
|
|
|
@ -305,133 +305,131 @@ static const char *fallbackLightallShader_fp =
|
||||||
"WMAP)\r\nuniform samplerCube u_ShadowMap;\r\n#endif\r\n\r\nuniform vec3 "
|
"WMAP)\r\nuniform samplerCube u_ShadowMap;\r\n#endif\r\n\r\nuniform vec3 "
|
||||||
" u_ViewOrigin;\r\n\r\n#if defined(USE_LIGHT_VECTOR)\r\nuniform vec3 u"
|
" u_ViewOrigin;\r\n\r\n#if defined(USE_LIGHT_VECTOR)\r\nuniform vec3 u"
|
||||||
"_DirectedLight;\r\nuniform vec3 u_AmbientLight;\r\nuniform float u"
|
"_DirectedLight;\r\nuniform vec3 u_AmbientLight;\r\nuniform float u"
|
||||||
"_LightRadius;\r\n#endif\r\n\r\n#if defined(USE_SPECULARMAP)\r\nuniform floa"
|
"_LightRadius;\r\n#endif\r\n\r\n#if defined(USE_LIGHT)\r\nuniform vec2 "
|
||||||
"t u_SpecularReflectance;\r\n#endif\r\n\r\n#if !defined(USE_FAST_LIGHT)"
|
"u_MaterialInfo;\r\n#endif\r\n\r\nvarying vec2 var_DiffuseTex;\r\n#if d"
|
||||||
"\r\nuniform float u_DiffuseRoughness;\r\n#endif\r\n\r\nvarying vec2 "
|
"efined(USE_LIGHTMAP)\r\nvarying vec2 var_LightTex;\r\n#endif\r\nvaryin"
|
||||||
" var_DiffuseTex;\r\n#if defined(USE_LIGHTMAP)\r\nvarying vec2 var_Lig"
|
"g vec4 var_Color;\r\nvarying vec3 var_Position;\r\n\r\nvarying ve"
|
||||||
"htTex;\r\n#endif\r\nvarying vec4 var_Color;\r\nvarying vec3 var_P"
|
"c3 var_SampleToView;\r\n\r\nvarying vec3 var_Normal;\r\n#if defin"
|
||||||
"osition;\r\n\r\nvarying vec3 var_SampleToView;\r\n\r\nvarying vec3 "
|
"ed(USE_VERT_TANGENT_SPACE)\r\nvarying vec3 var_Tangent;\r\nvarying vec"
|
||||||
" var_Normal;\r\n#if defined(USE_VERT_TANGENT_SPACE)\r\nvarying vec3 v"
|
"3 var_Bitangent;\r\n#endif\r\n\r\n#if defined(USE_LIGHT_VECTOR) && def"
|
||||||
"ar_Tangent;\r\nvarying vec3 var_Bitangent;\r\n#endif\r\n\r\n#if define"
|
"ined(USE_FAST_LIGHT)\r\nvarying vec3 var_VectLight;\r\n#endif\r\n\r\n#"
|
||||||
"d(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)\r\nvarying vec3 var_Vec"
|
"if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)\r\nvarying vec3 var_W"
|
||||||
"tLight;\r\n#endif\r\n\r\n#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)"
|
"orldLight;\r\n#endif\r\n\r\n#define EPSILON 0.00000001\r\n\r\n#if defined(U"
|
||||||
"\r\nvarying vec3 var_WorldLight;\r\n#endif\r\n\r\n#define EPSILON 0.00"
|
"SE_PARALLAXMAP)\r\nfloat SampleHeight(sampler2D normalMap, vec2 t)\r\n{\r\n"
|
||||||
"000001\r\n\r\n#if defined(USE_PARALLAXMAP)\r\nfloat SampleHeight(sampler2D "
|
" #if defined(SWIZZLE_NORMALMAP)\r\n\treturn texture2D(normalMap, t).r;\r\n"
|
||||||
"normalMap, vec2 t)\r\n{\r\n #if defined(SWIZZLE_NORMALMAP)\r\n\treturn tex"
|
" #else\r\n\treturn texture2D(normalMap, t).a;\r\n #endif\r\n}\r\n\r\nfloa"
|
||||||
"ture2D(normalMap, t).r;\r\n #else\r\n\treturn texture2D(normalMap, t).a;\r"
|
"t RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)\r\n{\r\n\t"
|
||||||
"\n #endif\r\n}\r\n\r\nfloat RayIntersectDisplaceMap(vec2 dp, vec2 ds, samp"
|
"const int linearSearchSteps = 16;\r\n\tconst int binarySearchSteps = 6;\r\n"
|
||||||
"ler2D normalMap)\r\n{\r\n\tconst int linearSearchSteps = 16;\r\n\tconst int"
|
"\r\n\tfloat depthStep = 1.0 / float(linearSearchSteps);\r\n\r\n\t// current"
|
||||||
" binarySearchSteps = 6;\r\n\r\n\tfloat depthStep = 1.0 / float(linearSearch"
|
" size of search window\r\n\tfloat size = depthStep;\r\n\r\n\t// current dep"
|
||||||
"Steps);\r\n\r\n\t// current size of search window\r\n\tfloat size = depthSt"
|
"th position\r\n\tfloat depth = 0.0;\r\n\r\n\t// best match found (starts wi"
|
||||||
"ep;\r\n\r\n\t// current depth position\r\n\tfloat depth = 0.0;\r\n\r\n\t// "
|
"th last position 1.0)\r\n\tfloat bestDepth = 1.0;\r\n\r\n\t// search front "
|
||||||
"best match found (starts with last position 1.0)\r\n\tfloat bestDepth = 1.0"
|
"to back for first point inside object\r\n\tfor(int i = 0; i < linearSearchS"
|
||||||
";\r\n\r\n\t// search front to back for first point inside object\r\n\tfor(i"
|
"teps - 1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n\t\t\r\n\t\tfloat t = Sample"
|
||||||
"nt i = 0; i < linearSearchSteps - 1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n"
|
"Height(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(bestDepth > 0.996)\t"
|
||||||
"\t\t\r\n\t\tfloat t = SampleHeight(normalMap, dp + ds * depth);\r\n\t\t\r\n"
|
"\t// if no depth found yet\r\n\t\t\tif(depth >= t)\r\n\t\t\t\tbestDepth = d"
|
||||||
"\t\tif(bestDepth > 0.996)\t\t// if no depth found yet\r\n\t\t\tif(depth >= "
|
"epth;\t// store best depth\r\n\t}\r\n\r\n\tdepth = bestDepth;\r\n\t\r\n\t//"
|
||||||
"t)\r\n\t\t\t\tbestDepth = depth;\t// store best depth\r\n\t}\r\n\r\n\tdepth"
|
" recurse around first point (depth) for closest match\r\n\tfor(int i = 0; i"
|
||||||
" = bestDepth;\r\n\t\r\n\t// recurse around first point (depth) for closest "
|
" < binarySearchSteps; ++i)\r\n\t{\r\n\t\tsize *= 0.5;\r\n\r\n\t\tfloat t = "
|
||||||
"match\r\n\tfor(int i = 0; i < binarySearchSteps; ++i)\r\n\t{\r\n\t\tsize *="
|
"SampleHeight(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(depth >= t)\r\n"
|
||||||
" 0.5;\r\n\r\n\t\tfloat t = SampleHeight(normalMap, dp + ds * depth);\r\n\t"
|
"\t\t{\r\n\t\t\tbestDepth = depth;\r\n\t\t\tdepth -= 2.0 * size;\r\n\t\t}\r"
|
||||||
"\t\r\n\t\tif(depth >= t)\r\n\t\t{\r\n\t\t\tbestDepth = depth;\r\n\t\t\tdept"
|
"\n\r\n\t\tdepth += size;\r\n\t}\r\n\r\n\treturn bestDepth;\r\n}\r\n#endif\r"
|
||||||
"h -= 2.0 * size;\r\n\t\t}\r\n\r\n\t\tdepth += size;\r\n\t}\r\n\r\n\treturn "
|
"\n\r\nfloat CalcDiffuse(vec3 N, vec3 L, vec3 E, float NE, float NL, float f"
|
||||||
"bestDepth;\r\n}\r\n#endif\r\n\r\nfloat CalcDiffuse(vec3 N, vec3 L, vec3 E, "
|
"zero, float shininess)\r\n{\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat rou"
|
||||||
"float NE, float NL, float fzero, float roughness)\r\n{\r\n #if defined(USE"
|
"ghness = sqrt(2.0 / max(shininess, EPSILON));\r\n\r\n\tfloat gamma = dot(E "
|
||||||
"_OREN_NAYAR)\r\n\tfloat gamma = dot(E - N * NE, L - N * NL);\r\n\tfloat r_s"
|
"- N * NE, L - N * NL);\r\n\tfloat r_sq = roughness * roughness;\r\n\r\n\tfl"
|
||||||
"q = roughness * roughness;\r\n\r\n\tfloat A = 1.0 - 0.5 * (r_sq / (r_sq + 0"
|
"oat A = 1.0 - 0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloat B = 0.45 * (r_sq / ("
|
||||||
".57));\r\n\tfloat B = 0.45 * (r_sq / (r_sq + 0.09));\r\n\r\n\tfloat alpha ="
|
"r_sq + 0.09));\r\n\r\n\tfloat alpha = max(acos(NE), acos(NL));\r\n\tfloat b"
|
||||||
" max(acos(NE), acos(NL));\r\n\tfloat beta = min(acos(NE), acos(NL));\r\n\r"
|
"eta = min(acos(NE), acos(NL));\r\n\r\n\tfloat C = sin(alpha) * tan(beta);"
|
||||||
"\n\tfloat C = sin(alpha) * tan(beta);\r\n\r\n\treturn A + B * clamp(gamma, "
|
"\r\n\r\n\treturn A + B * clamp(gamma, 0.0, 1.0) * C;\r\n #else\r\n\treturn"
|
||||||
"0.0, 1.0) * C;\r\n #else\r\n\treturn 1.0 - fzero;\r\n #endif\r\n}\r\n\r\n"
|
" 1.0 - fzero;\r\n #endif\r\n}\r\n\r\n#if defined(USE_SPECULARMAP)\r\nfloat"
|
||||||
"#if defined(USE_SPECULARMAP)\r\nfloat CalcSpecular(float NH, float NL, floa"
|
" CalcSpecular(float NH, float NL, float NE, float EH, float fzero, float sh"
|
||||||
"t NE, float EH, float fzero, float shininess)\r\n{\r\n #if defined(USE_BLI"
|
"ininess)\r\n{\r\n #if defined(USE_BLINN) || defined(USE_TRIACE) || defined"
|
||||||
"NN) || defined(USE_TRIACE) || defined(USE_TORRANCE_SPARROW)\r\n\tfloat blin"
|
"(USE_TORRANCE_SPARROW)\r\n\tfloat blinn = pow(NH, shininess);\r\n #endif\r"
|
||||||
"n = pow(NH, shininess);\r\n #endif\r\n\r\n #if defined(USE_BLINN)\r\n\tre"
|
"\n\r\n #if defined(USE_BLINN)\r\n\treturn blinn;\r\n #endif\r\n\r\n #if "
|
||||||
"turn blinn;\r\n #endif\r\n\r\n #if defined(USE_COOK_TORRANCE) || defined "
|
"defined(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE"
|
||||||
"(USE_TRIACE) || defined (USE_TORRANCE_SPARROW)\r\n\tfloat fresnel = fzero +"
|
"_SPARROW)\r\n\tfloat fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r"
|
||||||
" (1.0 - fzero) * pow(1.0 - EH, 5);\r\n #endif\r\n\r\n #if defined(USE_COO"
|
"\n #endif\r\n\r\n #if defined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_"
|
||||||
"K_TORRANCE) || defined(USE_TORRANCE_SPARROW)\r\n\tfloat geo = 2.0 * NH * mi"
|
"SPARROW)\r\n\tfloat geo = 2.0 * NH * min(NE, NL);\r\n\tgeo /= max(EH, geo);"
|
||||||
"n(NE, NL);\r\n\tgeo /= max(EH, geo);\r\n #endif \r\n\r\n #if defined(USE"
|
"\r\n #endif \r\n\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloat m = sqrt("
|
||||||
"_COOK_TORRANCE)\r\n\tfloat m = sqrt(2.0 / shininess);\r\n\r\n\tfloat m_sq ="
|
"2.0 / max(shininess, EPSILON));\r\n\r\n\tfloat m_sq = m * m;\r\n\tfloat NH_"
|
||||||
" m * m;\r\n\tfloat NH_sq = NH * NH;\r\n\tfloat beckmann = exp((NH_sq - 1.0)"
|
"sq = NH * NH;\r\n\tfloat beckmann = exp((NH_sq - 1.0) / max(m_sq * NH_sq, E"
|
||||||
" / max(m_sq * NH_sq, EPSILON)) / max(4.0 * m_sq * NH_sq * NH_sq, EPSILON);"
|
"PSILON)) / max(4.0 * m_sq * NH_sq * NH_sq, EPSILON);\r\n\r\n\treturn fresne"
|
||||||
"\r\n\r\n\treturn fresnel * geo * beckmann / max(NE, EPSILON);\r\n #endif\r"
|
"l * geo * beckmann / max(NE, EPSILON);\r\n #endif\r\n\r\n #if defined(USE"
|
||||||
"\n\r\n #if defined(USE_TRIACE)\r\n\tfloat scale = 0.1248582 * shininess + "
|
"_TRIACE)\r\n\tfloat scale = 0.1248582 * shininess + 0.2691817;\r\n\r\n\tret"
|
||||||
"0.2691817;\r\n\r\n\treturn fresnel * scale * blinn / max(max(NL, NE), EPSIL"
|
"urn fresnel * scale * blinn / max(max(NL, NE), EPSILON);\r\n #endif\r\n "
|
||||||
"ON);\r\n #endif\r\n \r\n #if defined(USE_TORRANCE_SPARROW)\r\n\tfloat sc"
|
"\r\n #if defined(USE_TORRANCE_SPARROW)\r\n\tfloat scale = 0.125 * shinines"
|
||||||
"ale = 0.125 * shininess + 1.0;\r\n\r\n\treturn fresnel * geo * scale * blin"
|
"s + 1.0;\r\n\r\n\treturn fresnel * geo * scale * blinn / max(NE, EPSILON);"
|
||||||
"n / max(NE, EPSILON);\r\n #endif\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r"
|
"\r\n #endif\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r\n#if defined(USE_DELU"
|
||||||
"\n#if defined(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * texture2D(u_Delux"
|
"XEMAP)\r\n\tvec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_LightTex).xy"
|
||||||
"eMap, var_LightTex).xyz - vec3(1.0);\r\n\t//worldLight += var_WorldLight * "
|
"z - vec3(1.0);\r\n\t//worldLight += var_WorldLight * 0.0001;\r\n#elif defin"
|
||||||
"0.0001;\r\n#elif defined(USE_LIGHT)\r\n\tvec3 worldLight = var_WorldLight;"
|
"ed(USE_LIGHT)\r\n\tvec3 worldLight = var_WorldLight;\r\n#endif\r\n\r\n#if d"
|
||||||
"\r\n#endif\r\n\r\n#if defined(USE_LIGHTMAP)\r\n\tvec4 lightSample = texture"
|
"efined(USE_LIGHTMAP)\r\n\tvec4 lightSample = texture2D(u_LightMap, var_Ligh"
|
||||||
"2D(u_LightMap, var_LightTex).rgba;\r\n #if defined(RGBE_LIGHTMAP)\r\n\tlig"
|
"tTex).rgba;\r\n #if defined(RGBE_LIGHTMAP)\r\n\tlightSample.rgb *= exp2(li"
|
||||||
"htSample.rgb *= exp2(lightSample.a * 255.0 - 128.0);\r\n #endif\r\n\tvec3 "
|
"ghtSample.a * 255.0 - 128.0);\r\n #endif\r\n\tvec3 directedLight = lightSa"
|
||||||
"directedLight = lightSample.rgb;\r\n#elif defined(USE_LIGHT_VECTOR)\r\n #i"
|
"mple.rgb;\r\n#elif defined(USE_LIGHT_VECTOR)\r\n #if defined(USE_FAST_LIGH"
|
||||||
"f defined(USE_FAST_LIGHT)\r\n\tvec3 directedLight = var_VectLight;\r\n #el"
|
"T)\r\n\tvec3 directedLight = var_VectLight;\r\n #else\r\n #if defined(U"
|
||||||
"se\r\n #if defined(USE_INVSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(wor"
|
"SE_INVSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, worldLight);\r"
|
||||||
"ldLight, worldLight);\r\n #else\r\n\tfloat intensity = clamp((1.0 - dot("
|
"\n #else\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, worldLight)"
|
||||||
"worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0"
|
" / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #endif\r\n "
|
||||||
");\r\n #endif\r\n #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 = text"
|
" #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 = textureCube(u_ShadowMap, wo"
|
||||||
"ureCube(u_ShadowMap, worldLight).rgb;\r\n\tfloat dist = dot(dist3, vec3(1.0"
|
"rldLight).rgb;\r\n\tfloat dist = dot(dist3, vec3(1.0 / (256.0 * 256.0), 1.0"
|
||||||
" / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tintensity "
|
" / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tintensity *= clamp(sign(dist - le"
|
||||||
"*= clamp(sign(dist - length(worldLight)), 0.0, 1.0);\r\n #endif\r\n\tvec"
|
"ngth(worldLight)), 0.0, 1.0);\r\n #endif\r\n\tvec3 directedLight = u_Dir"
|
||||||
"3 directedLight = u_DirectedLight * intensity;\r\n\tvec3 ambientLight = u_"
|
"ectedLight * intensity;\r\n\tvec3 ambientLight = u_AmbientLight;\r\n #end"
|
||||||
"AmbientLight;\r\n #endif\r\n#elif defined(USE_LIGHT_VERTEX)\r\n\tvec3 dire"
|
"if\r\n#elif defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLight = var_Color.r"
|
||||||
"ctedLight = var_Color.rgb;\r\n#endif\r\n\t\r\n#if defined(USE_NORMALMAP) ||"
|
"gb;\r\n#endif\r\n\t\r\n#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && "
|
||||||
" defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tvec3 SampleToView = no"
|
"!defined(USE_FAST_LIGHT)\r\n\tvec3 SampleToView = normalize(var_SampleToVie"
|
||||||
"rmalize(var_SampleToView);\r\n#endif\r\n\tvec2 tex = var_DiffuseTex;\r\n\r"
|
"w);\r\n#endif\r\n\tvec2 tex = var_DiffuseTex;\r\n\r\n\tfloat ambientDiff = "
|
||||||
"\n\tfloat ambientDiff = 1.0;\r\n\r\n#if defined(USE_NORMALMAP)\r\n #if def"
|
"1.0;\r\n\r\n#if defined(USE_NORMALMAP)\r\n #if defined(USE_VERT_TANGENT_SP"
|
||||||
"ined(USE_VERT_TANGENT_SPACE)\r\n vec3 tangent = normalize(var_Tangent)"
|
"ACE)\r\n vec3 tangent = normalize(var_Tangent);\r\n\tvec3 bitangent = "
|
||||||
";\r\n\tvec3 bitangent = normalize(var_Bitangent);\r\n #else\r\n\tvec3 q0 "
|
"normalize(var_Bitangent);\r\n #else\r\n\tvec3 q0 = dFdx(var_Position.xyz)"
|
||||||
"= dFdx(var_Position.xyz);\r\n\tvec3 q1 = dFdy(var_Position.xyz);\r\n\tvec2"
|
";\r\n\tvec3 q1 = dFdy(var_Position.xyz);\r\n\tvec2 st0 = dFdx(tex);\r\n\tv"
|
||||||
" st0 = dFdx(tex);\r\n\tvec2 st1 = dFdy(tex);\r\n\r\n\tvec3 tangent = -nor"
|
"ec2 st1 = dFdy(tex);\r\n\r\n\tvec3 tangent = -normalize( q0 * st1.t - q1 "
|
||||||
"malize( q0 * st1.t - q1 * st0.t);\r\n\tvec3 bitangent = -normalize(-q0 * st"
|
"* st0.t);\r\n\tvec3 bitangent = -normalize(-q0 * st1.s + q1 * st0.s);\r\n "
|
||||||
"1.s + q1 * st0.s);\r\n #endif\r\n\r\n\tmat3 tangentToWorld = mat3(tangent,"
|
"#endif\r\n\r\n\tmat3 tangentToWorld = mat3(tangent, bitangent, normalize(va"
|
||||||
" bitangent, normalize(var_Normal.xyz));\r\n\r\n #if defined(USE_PARALLAXMA"
|
"r_Normal.xyz));\r\n\r\n #if defined(USE_PARALLAXMAP)\r\n\tvec3 offsetDir ="
|
||||||
"P)\r\n\tvec3 offsetDir = normalize(SampleToView * tangentToWorld);\r\n #"
|
" normalize(SampleToView * tangentToWorld);\r\n #if 0\r\n float height"
|
||||||
"if 0\r\n float height = SampleHeight(u_NormalMap, tex);\r\n\tfloat pdist"
|
" = SampleHeight(u_NormalMap, tex);\r\n\tfloat pdist = 0.05 * height - (0.05"
|
||||||
" = 0.05 * height - (0.05 / 2.0);\r\n #else\r\n\toffsetDir.xy *= 0.02 / o"
|
" / 2.0);\r\n #else\r\n\toffsetDir.xy *= 0.02 / offsetDir.z;\r\n\tfloat p"
|
||||||
"ffsetDir.z;\r\n\tfloat pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u"
|
"dist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);\r\n #end"
|
||||||
"_NormalMap);\r\n #endif\t\r\n\ttex += offsetDir.xy * pdist;\r\n #endif"
|
"if\t\r\n\ttex += offsetDir.xy * pdist;\r\n #endif\r\n #if defined(SWIZZLE"
|
||||||
"\r\n #if defined(SWIZZLE_NORMALMAP)\r\n\tvec3 normal = 2.0 * texture2D(u_N"
|
"_NORMALMAP)\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0;"
|
||||||
"ormalMap, tex).agb - 1.0;\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_N"
|
"\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0;"
|
||||||
"ormalMap, tex).rgb - 1.0;\r\n #endif\r\n\tnormal.z = sqrt(clamp(1.0 - dot("
|
"\r\n #endif\r\n\tnormal.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0."
|
||||||
"normal.xy, normal.xy), 0.0, 1.0));\r\n\tvec3 worldNormal = tangentToWorld *"
|
"0, 1.0));\r\n\tvec3 worldNormal = tangentToWorld * normal;\r\n #if defined"
|
||||||
" normal;\r\n #if defined(r_normalAmbient)\r\n\tambientDiff = 0.781341 * no"
|
"(r_normalAmbient)\r\n\tambientDiff = 0.781341 * normal.z + 0.218659;\r\n #"
|
||||||
"rmal.z + 0.218659;\r\n #endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;"
|
"endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;\r\n#endif\r\n\r\n\tvec4 "
|
||||||
"\r\n#endif\r\n\r\n\tvec4 diffuse = texture2D(u_DiffuseMap, tex);\r\n\r\n#if"
|
"diffuse = texture2D(u_DiffuseMap, tex);\r\n\r\n#if defined(USE_LIGHT) && de"
|
||||||
" defined(USE_LIGHT) && defined(USE_FAST_LIGHT)\r\n\tdiffuse.rgb *= directed"
|
"fined(USE_FAST_LIGHT)\r\n\tdiffuse.rgb *= directedLight;\r\n#elif defined(U"
|
||||||
"Light;\r\n#elif defined(USE_LIGHT)\r\n\tworldNormal = normalize(worldNormal"
|
"SE_LIGHT)\r\n\tworldNormal = normalize(worldNormal);\r\n\tworldLight = norm"
|
||||||
");\r\n\tworldLight = normalize(worldLight);\r\n\r\n #if defined(USE_LIGHTM"
|
"alize(worldLight);\r\n\r\n #if defined(USE_LIGHTMAP) || defined(USE_LIGHT_"
|
||||||
"AP) || defined(USE_LIGHT_VERTEX)\r\n\tdirectedLight /= max(dot(normalize(va"
|
"VERTEX)\r\n\tdirectedLight /= max(dot(normalize(var_Normal), worldLight), 0"
|
||||||
"r_Normal), worldLight), 0.004);\r\n\r\n #if defined(r_normalAmbient)\r\n"
|
".004);\r\n\r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientLight = dir"
|
||||||
"\tvec3 ambientLight = directedLight * r_normalAmbient;\r\n\tdirectedLight -"
|
"ectedLight * r_normalAmbient;\r\n\tdirectedLight -= ambientLight;\r\n #e"
|
||||||
"= ambientLight;\r\n #else\r\n\tvec3 ambientLight = vec3(0);\r\n #endi"
|
"lse\r\n\tvec3 ambientLight = vec3(0);\r\n #endif\r\n #endif\r\n\r\n\tfl"
|
||||||
"f\r\n #endif\r\n\r\n\tfloat NL = clamp(dot(worldNormal, worldLight), 0."
|
"oat NL = clamp(dot(worldNormal, worldLight), 0.0, 1.0);\r\n\tfloat NE = "
|
||||||
"0, 1.0);\r\n\tfloat NE = clamp(dot(worldNormal, SampleToView), 0.0, 1.0);"
|
"clamp(dot(worldNormal, SampleToView), 0.0, 1.0);\r\n\t\r\n\tfloat fzero = "
|
||||||
"\r\n #if defined(USE_SPECULARMAP)\r\n\tfloat fzero = u_SpecularReflectance"
|
"u_MaterialInfo.x;\r\n\tfloat shininess = u_MaterialInfo.y;\r\n #if defined"
|
||||||
";\r\n #else\r\n\tfloat fzero = 0.0;\r\n #endif\r\n\tfloat directedDiff = "
|
"(USE_SPECULARMAP)\r\n\tvec4 specular = texture2D(u_SpecularMap, tex);\r\n\t"
|
||||||
"NL * CalcDiffuse(worldNormal, worldLight, SampleToView, NE, NL, fzero, u_Di"
|
"//specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0);\r\n\tshinines"
|
||||||
"ffuseRoughness);\r\n\tdiffuse.rgb *= directedLight * directedDiff + ambient"
|
"s *= specular.a;\r\n #endif\r\n\tfloat directedDiff = NL * CalcDiffuse(wor"
|
||||||
"Diff * ambientLight;\r\n \r\n #if defined(USE_SPECULARMAP)\r\n\tvec4 spec"
|
"ldNormal, worldLight, SampleToView, NE, NL, fzero, shininess);\r\n\tdiffuse"
|
||||||
"ular = texture2D(u_SpecularMap, tex);\r\n\t//specular.rgb = clamp(specular."
|
".rgb *= directedLight * directedDiff + ambientDiff * ambientLight;\r\n \r"
|
||||||
"rgb - diffuse.rgb, 0.0, 1.0);\r\n\tfloat shininess = specular.a * 255 + 1.0"
|
"\n #if defined(USE_SPECULARMAP)\r\n\tvec3 halfAngle = normalize(worldLight"
|
||||||
";\r\n\r\n\tvec3 halfAngle = normalize(worldLight + SampleToView);\r\n\r\n\t"
|
" + SampleToView);\r\n\r\n\tfloat EH = clamp(dot(SampleToView, halfAngle), 0"
|
||||||
"float EH = clamp(dot(SampleToView, halfAngle), 0.0, 1.0);\r\n\tfloat NH = c"
|
".0, 1.0);\r\n\tfloat NH = clamp(dot(worldNormal, halfAngle), 0.0, 1.0);\r"
|
||||||
"lamp(dot(worldNormal, halfAngle), 0.0, 1.0);\r\n\r\n\tfloat directedSpec ="
|
"\n\r\n\tfloat directedSpec = NL * CalcSpecular(NH, NL, NE, EH, fzero, shini"
|
||||||
" NL * CalcSpecular(NH, NL, NE, EH, fzero, shininess);\r\n \r\n #if defi"
|
"ness);\r\n \r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientHalf = no"
|
||||||
"ned(r_normalAmbient)\r\n\tvec3 ambientHalf = normalize(var_Normal + SampleT"
|
"rmalize(var_Normal + SampleToView);\r\n\tfloat ambientSpec = max(dot(ambien"
|
||||||
"oView);\r\n\tfloat ambientSpec = max(dot(ambientHalf, worldNormal) + 0.5, 0"
|
"tHalf, worldNormal) + 0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.44;\r"
|
||||||
".0);\r\n\tambientSpec *= ambientSpec * 0.44;\r\n\tambientSpec = pow(ambient"
|
"\n\tambientSpec = pow(ambientSpec, shininess) * fzero;\r\n\tspecular.rgb *="
|
||||||
"Spec, shininess) * fzero;\r\n #if defined(USE_TRIACE)\r\n\tambientSpec"
|
" directedSpec * directedLight + ambientSpec * ambientLight;\r\n #else\r"
|
||||||
" *= 0.1248582 * shininess + 0.2691817;\r\n #endif \r\n\tspecular.rg"
|
"\n\tspecular.rgb *= directedSpec * directedLight;\r\n #endif\r\n #endif"
|
||||||
"b *= directedSpec * directedLight + ambientSpec * ambientLight;\r\n #els"
|
"\r\n#endif\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined(USE_SPECULAR"
|
||||||
"e\r\n\tspecular.rgb *= directedSpec * directedLight;\r\n #endif\r\n #en"
|
"MAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tgl_FragColor.rg"
|
||||||
"dif\r\n#endif\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined(USE_SPECU"
|
"b += specular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tgl_"
|
||||||
"LARMAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tgl_FragColor"
|
"FragColor *= var_Color;\r\n#endif\r\n}\r\n";
|
||||||
".rgb += specular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\t"
|
|
||||||
"gl_FragColor *= var_Color;\r\n#endif\r\n}\r\n";
|
|
||||||
|
|
||||||
static const char *fallbackShadowfillShader_vp =
|
static const char *fallbackShadowfillShader_vp =
|
||||||
"attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\nattribute"
|
"attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\nattribute"
|
||||||
|
@ -1876,8 +1874,7 @@ void GLSL_InitGPUShaders(void)
|
||||||
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_LIGHTORIGIN, "u_LightOrigin", GLSL_VEC4);
|
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_LIGHTORIGIN, "u_LightOrigin", GLSL_VEC4);
|
||||||
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_LIGHTRADIUS, "u_LightRadius", GLSL_FLOAT);
|
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_LIGHTRADIUS, "u_LightRadius", GLSL_FLOAT);
|
||||||
|
|
||||||
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SPECULARREFLECTANCE, "u_SpecularReflectance", GLSL_FLOAT);
|
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_MATERIALINFO, "u_MaterialInfo", GLSL_VEC2);
|
||||||
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_DIFFUSEROUGHNESS, "u_DiffuseRoughness", GLSL_FLOAT);
|
|
||||||
|
|
||||||
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_BASECOLOR, "u_BaseColor", GLSL_VEC4);
|
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_BASECOLOR, "u_BaseColor", GLSL_VEC4);
|
||||||
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_VERTCOLOR, "u_VertColor", GLSL_VEC4);
|
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_VERTCOLOR, "u_VertColor", GLSL_VEC4);
|
||||||
|
|
|
@ -449,8 +449,7 @@ typedef struct {
|
||||||
stageType_t type;
|
stageType_t type;
|
||||||
struct shaderProgram_s *glslShaderGroup;
|
struct shaderProgram_s *glslShaderGroup;
|
||||||
int glslShaderIndex;
|
int glslShaderIndex;
|
||||||
float specularReflectance;
|
vec2_t materialInfo;
|
||||||
float diffuseRoughness;
|
|
||||||
} shaderStage_t;
|
} shaderStage_t;
|
||||||
|
|
||||||
struct shaderCommands_s;
|
struct shaderCommands_s;
|
||||||
|
@ -864,8 +863,7 @@ enum
|
||||||
GENERIC_UNIFORM_MODELVIEWPROJECTIONMATRIX,
|
GENERIC_UNIFORM_MODELVIEWPROJECTIONMATRIX,
|
||||||
GENERIC_UNIFORM_TIME,
|
GENERIC_UNIFORM_TIME,
|
||||||
GENERIC_UNIFORM_VERTEXLERP,
|
GENERIC_UNIFORM_VERTEXLERP,
|
||||||
GENERIC_UNIFORM_SPECULARREFLECTANCE,
|
GENERIC_UNIFORM_MATERIALINFO,
|
||||||
GENERIC_UNIFORM_DIFFUSEROUGHNESS,
|
|
||||||
GENERIC_UNIFORM_COUNT
|
GENERIC_UNIFORM_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -803,8 +803,7 @@ static void ForwardDlight( void ) {
|
||||||
|
|
||||||
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_LIGHTRADIUS, radius);
|
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_LIGHTRADIUS, radius);
|
||||||
|
|
||||||
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_SPECULARREFLECTANCE, pStage->specularReflectance);
|
GLSL_SetUniformVec2(sp, GENERIC_UNIFORM_MATERIALINFO, pStage->materialInfo);
|
||||||
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_DIFFUSEROUGHNESS, pStage->diffuseRoughness);
|
|
||||||
|
|
||||||
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
|
// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
|
||||||
// where they aren't rendered
|
// where they aren't rendered
|
||||||
|
@ -1147,8 +1146,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
||||||
|
|
||||||
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, backEnd.or.transformMatrix);
|
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, backEnd.or.transformMatrix);
|
||||||
|
|
||||||
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_SPECULARREFLECTANCE, pStage->specularReflectance);
|
GLSL_SetUniformVec2(sp, GENERIC_UNIFORM_MATERIALINFO, pStage->materialInfo);
|
||||||
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_DIFFUSEROUGHNESS, pStage->diffuseRoughness);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// do multitexture
|
// do multitexture
|
||||||
|
|
|
@ -907,7 +907,8 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
|
||||||
else if(!Q_stricmp(token, "specularMap"))
|
else if(!Q_stricmp(token, "specularMap"))
|
||||||
{
|
{
|
||||||
stage->type = ST_SPECULARMAP;
|
stage->type = ST_SPECULARMAP;
|
||||||
stage->specularReflectance = 0.04f;
|
stage->materialInfo[0] = 0.04f;
|
||||||
|
stage->materialInfo[1] = 256.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -926,20 +927,20 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
|
||||||
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for specular reflectance in shader '%s'\n", shader.name );
|
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for specular reflectance in shader '%s'\n", shader.name );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
stage->specularReflectance = atof( token );
|
stage->materialInfo[0] = atof( token );
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// diffuseRoughness <value>
|
// specularExponent <value>
|
||||||
//
|
//
|
||||||
else if (!Q_stricmp(token, "diffuseroughness"))
|
else if (!Q_stricmp(token, "specularexponent"))
|
||||||
{
|
{
|
||||||
token = COM_ParseExt(text, qfalse);
|
token = COM_ParseExt(text, qfalse);
|
||||||
if ( token[0] == 0 )
|
if ( token[0] == 0 )
|
||||||
{
|
{
|
||||||
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for diffuse roughness in shader '%s'\n", shader.name );
|
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for specular exponent in shader '%s'\n", shader.name );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
stage->diffuseRoughness = atof( token );
|
stage->materialInfo[1] = atof( token );
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// rgbGen
|
// rgbGen
|
||||||
|
@ -2189,7 +2190,8 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
|
||||||
{
|
{
|
||||||
//ri.Printf(PRINT_ALL, ", specularmap %s", specular->bundle[0].image[0]->imgName);
|
//ri.Printf(PRINT_ALL, ", specularmap %s", specular->bundle[0].image[0]->imgName);
|
||||||
diffuse->bundle[TB_SPECULARMAP] = specular->bundle[0];
|
diffuse->bundle[TB_SPECULARMAP] = specular->bundle[0];
|
||||||
diffuse->specularReflectance = specular->specularReflectance;
|
diffuse->materialInfo[0] = specular->materialInfo[0];
|
||||||
|
diffuse->materialInfo[1] = specular->materialInfo[1];
|
||||||
defs |= LIGHTDEF_USE_SPECULARMAP;
|
defs |= LIGHTDEF_USE_SPECULARMAP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue