Skip to content

Commit

Permalink
Merge pull request #112 from stephengtuggy/textureLod
Browse files Browse the repository at this point in the history
Fix some of the errors encountered in the fragment programs and vertex programs on macOS
  • Loading branch information
stephengtuggy authored May 3, 2024
2 parents 7ed4563 + 4605324 commit 271e91b
Show file tree
Hide file tree
Showing 20 changed files with 289 additions and 285 deletions.
10 changes: 5 additions & 5 deletions programs/cel.fp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3
vec3 envMapping(in vec2 coord, in vec4 specmap)
{
float envLod = shininess2Lod(gl_FrontMaterial.shininess);
return texture2DLod(envMap, coord, envLod).rgb * specmap.rgb * envColor.rgb * 2.0;
return textureLod(envMap, coord, envLod).rgb * specmap.rgb * envColor.rgb * 2.0;
}

void main()
void main()
{
// Sample textures
vec4 damagecolor = texture2D(damageMap , gl_TexCoord[0].xy);
Expand All @@ -42,15 +42,15 @@ void main()
vec4 glowcolor = texture2D(glowMap , gl_TexCoord[0].xy);
vec4 diffusemap = lerp(damage.x, diffusecolor, damagecolor);
vec4 specmap = speccolor;

vec3 d = diffusemap.rgb * gl_Color.rgb;
vec3 s = specmap.rgb * gl_SecondaryColor.rgb;
vec3 e = envMapping(gl_TexCoord[1].xy, specmap);
vec3 g = glowcolor.rgb;

vec4 rv;
rv.rgb = cel(d + s + g, ambientLevel) + cel(e, 0.0);
rv.a = diffusemap.a * gl_Color.a;

gl_FragColor = rv * cloaking.rrrg;
}
20 changes: 10 additions & 10 deletions programs/cinemut_opaque.fp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ vec2 EnvMapGen(vec3 f) {

vec3 envMappingLOD( in vec3 direction, in float LoD )
{
vec4 result = texture2DLod( envMap, EnvMapGen(direction), LoD );
vec4 result = textureLod( envMap, EnvMapGen(direction), LoD );
return result.rgb * result.a * 2.0;
}

Expand Down Expand Up @@ -262,11 +262,11 @@ float prt_sample( in vec3 dir, in vec3 prtp, in vec3 prtn )
//float prt_diff_shadow( in vec3 dir, in vec3 prtp, in vec3 prtn, in float hardness, in float biasfactor )
float prt_diff_shadow( in vec3 dir, in vec3 nor, in vec3 prtp, in vec3 prtn, in float ao )
{
//float ihardness = 1.0 + 4.0*hardness;
//hardness = 0.125 * hardness * biasfactor;
//return clamp( (prt_sample( dir, prtp, prtn ) - hardness) * ihardness, 0.0, 1.0 );
vec3 VUT = normalize( dir );
vec3 PRT = prtp - prtn;
vec3 NPRT = normalize( PRT );
Expand Down Expand Up @@ -407,7 +407,7 @@ void perlite
// (1-fresnel_blend*fresnel reflection), also, and
// metallic shininess phong. And we also multiply by the
// shininess, as smaller spots get more light concentration
MSacc += ( pow(RdotL,ltd_Mgloss) * clamp( ltd_Mgloss, 0.0, gloss_mul_lim ) );
MSacc += ( pow(RdotL,ltd_Mgloss) * clamp( ltd_Mgloss, 0.0, gloss_mul_lim ) );
// * FS - fresnel specularity: Doesn't need fresnel, really,
// as the only fresnel applicable is view-vector-dependent,
// which can be applied afterwards, to the accumulated value;
Expand Down Expand Up @@ -442,7 +442,7 @@ vec3 multibounce_color( in vec3 color, in float refl_factor )
The formula is: *= (c-refL*c)/(1-refL*c), where refL is the fresnel reflectivity and
c is the color of the material under the dielectric coating. But blended materials,
such as plastics, are only partially covered by a specular dielectric layer, so we do
have to allow some pure color reflectivity; thus the "blend" thing...
have to allow some pure color reflectivity; thus the "blend" thing...
Update: blend factor can just be pre-multiplied with the refl_factor; blend removed.*/
vec3 temp = color * refl_factor;
return (color-temp)/(vec3(1.0)-temp);
Expand Down Expand Up @@ -530,22 +530,22 @@ void main()
//SPC_in4 = vec4(0.0);
SPC_in4.a += (0.25*SPC_in4.r);
SPC_in4.r = (0.8*SPC_in4.r+0.1);

//static light bake specular experiment
float ts = 1.0/777.7; //ts = "texture stride"
vec2 Uplus = texcoords2+vec2(ts,0.0);
vec2 Uminu = texcoords2+vec2(-ts,0.0);
vec2 Vplus = texcoords2+vec2(0.0,ts);
vec2 Vminu = texcoords2+vec2(0.0,-ts);
vec3 Glo_dU = texture2DLod( glowMap, Uplus, 2.345 ).rgb - texture2DLod( glowMap, Uminu, 2.345 ).rgb;
vec3 Glo_dV = -texture2DLod( glowMap, Vplus, 2.345 ).rgb + texture2DLod( glowMap, Vminu, 2.345 ).rgb;
vec3 Glo_dU = textureLod( glowMap, Uplus, 2.345 ).rgb - textureLod( glowMap, Uminu, 2.345 ).rgb;
vec3 Glo_dV = -textureLod( glowMap, Vplus, 2.345 ).rgb + textureLod( glowMap, Vminu, 2.345 ).rgb;
Glo_dU *= 17.7;
Glo_dV *= 17.7;
vec3 redlite_dir = normalize( vec3( Glo_dU.r, Glo_dV.r, GLO_in4.r ));
vec3 grnlite_dir = normalize( vec3( Glo_dU.g, Glo_dV.g, GLO_in4.g ));
vec3 blulite_dir = normalize( vec3( Glo_dU.b, Glo_dV.b, GLO_in4.b ));


//UNPACK:
//we use a macro table to ease possible future changes to the texture packing:
#define _matcolor_in_ ((COL_in4.rgb))
Expand Down
22 changes: 13 additions & 9 deletions programs/mac.fp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,26 @@ float shininess2Lod(float shininess) { return max(0.0,7.0-log2(shininess+1.0))+3

vec3 envMapping(in vec3 reflection, in float shininess, in vec4 specmap)
{
float envLod = shininess2Lod(shininessMap(shininess,specmap));
return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * envColor.rgb;
float envLod = shininess2Lod(shininessMap(shininess,specmap));
// Turn into bias
if (envLod <= 1.0) {
envLod = -10.0;
}
return texture(envMap, EnvMapGen(reflection), envLod - 1.0).rgb * specmap.rgb * envColor.rgb;
}


void main() {
//begin bumpmapping

vec3 iNormal=tc1.xyz;
vec3 iTangent=tc2.xyz;
vec3 iBinormal=tc3.xyz;
//download matrix and dont recompute (as below you might... slightly higher precision, no visual diff)
iBinormal=vec3(gl_ModelViewMatrix[2][0],gl_ModelViewMatrix[2][1],gl_ModelViewMatrix[2][2]);
iTangent=normalize(cross(iBinormal,iNormal));
iBinormal=normalize(cross(iNormal,iTangent));


vec3 iLightVec=tc5.xyz;
vec3 pos=vec3(tc0.z,tc0.w,tc1.w);
Expand All @@ -68,7 +72,7 @@ void main() {
vec3 half1Angle=normalize(eyeDir+light1Dir);
vec3 normal;//=normalize(expand(texture2D(normalMap,tc0.xy).wyz));
//transform normal from normalMap to world space
normal=normalize(imatmul(iTangent,iBinormal,iNormal,normalize(expand(texture2D(normalMap,tc0.xy).wyz))));
normal=normalize(imatmul(iTangent,iBinormal,iNormal,normalize(expand(texture(normalMap,tc0.xy).wyz))));
//begin shading
//compute half angle dot with light (not used)
float nDotH0=dot(normal,half0Angle);
Expand All @@ -87,14 +91,14 @@ void main() {
float lDotR0=dot(light0Dir,reflection);
float lDotR1=dot(light1Dir,reflection);
//get damaged and undamaged colors
vec4 undamagedcolor=texture2D(diffuseMap,tc0.xy);
vec4 damagecolor=texture2D(damageMap,tc0.xy);
vec4 undamagedcolor=texture(diffuseMap,tc0.xy);
vec4 damagecolor=texture(damageMap,tc0.xy);
//mix the colors based on damage... if you had detail maps, these would go here
vec4 diffsurface=
mix(undamagedcolor,damagecolor,damage.x);
// +texture2D(detail0Map,tc0.xy);//do not support yet
//have a specular surface unless the damage color is quite bright (maybe dark!?)
vec4 specsurface=texture2D(specMap,tc0.xy)*(1.0-damagecolor*damage.x*2.0);
vec4 specsurface=texture(specMap,tc0.xy)*(1.0-damagecolor*damage.x*2.0);
float shininess=shininessMap(gl_FrontMaterial.shininess,specsurface);
//add in lights 1..8 and ambient terms
vec4 ambient=gl_Color;
Expand All @@ -109,5 +113,5 @@ void main() {
if (light_enabled[1]!=0)
specularity+=selfShadow1*pow(max(lDotR1,0.0),shininess)*gl_FrontLightProduct[1].specular;
//sum everything up including glow from surface...and if cloaking, fade it out :-)
gl_FragColor=(ambient*diffsurface+specularity*specsurface+texture2D(glowMap,tc0.xy))*cloaking.rrrg;
gl_FragColor=(ambient*diffsurface+specularity*specsurface+texture(glowMap,tc0.xy))*cloaking.rrrg;
}
16 changes: 8 additions & 8 deletions programs/planet/atmo_arbfp1.fp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ float cosAngleToDepth(float fNDotV)
vec2 res = vec2(1.0) / vec2(1024.0,128.0);
vec2 mn = res * 0.5;
vec2 mx = vec2(1.0)-res * 0.5;
return expandPrecision(texture2DLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
return expandPrecision(textureLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
}

float cosAngleToAlpha(float fNDotV)
Expand Down Expand Up @@ -67,14 +67,14 @@ vec4 atmosphericScatter(vec3 ambient, float fNDotV, float fNDotL, float fLDotV)
float ldepth = cosAngleToLDepth(scaleAndOffset(fNDotL));
float ralpha = cosAngleToAlpha(fNDotV);
ralpha = saturatef(pow(ralpha,fAtmosphereExtrusionSteepness));

vec3 labsorption = pow(fAtmosphereAbsorptionColor.rgb,vec3(fAtmosphereAbsorptionColor.a*ldepth*0.5*fSelfShadowFactor));
vec3 lscatter = gl_LightSource[0].diffuse.rgb
* fAtmosphereScatterColor.rgb

vec3 lscatter = gl_LightSource[0].diffuse.rgb
* fAtmosphereScatterColor.rgb
* labsorption
* (fMinScatterFactor+min(fMaxScatterFactor*4.0-fMinScatterFactor,4.0*vdepth*ralpha));

vec4 rv;
rv.rgb = regamma( ambient + atmosphereLighting(scaleAndOffset(fNDotL))*lscatter );
rv.a = ralpha;
Expand All @@ -87,10 +87,10 @@ vec3 ambientMapping( in vec3 direction )
}

void main()
{
{
vec3 L = normalize(varTSLight);
vec3 V = normalize(varTSView);

vec4 rv = atmosphericScatter( ambientMapping(varWSNormal), V.z, L.z, dot(L,V) );
gl_FragColor.rgb = (rv.rgb);
gl_FragColor.a = rv.a;
Expand Down
18 changes: 9 additions & 9 deletions programs/planet/atmo_gas_arbfp1.fp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ float cosAngleToDepth(float fNDotV)
vec2 res = vec2(1.0) / vec2(1024.0,128.0);
vec2 mn = res * 0.5;
vec2 mx = vec2(1.0)-res * 0.5;
return expandPrecision(texture2DLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
return expandPrecision(textureLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
}

float cosAngleToAlpha(float fNDotV)
Expand Down Expand Up @@ -74,13 +74,13 @@ vec4 atmosphericScatter(vec3 ambient, vec3 dif, float fNDotV, float fNDotL, floa
float ldepth = cosAngleToLDepth(fNDotL);
float ralpha = cosAngleToAlpha(fNDotV);
ralpha = saturatef(pow(ralpha,fAtmosphereExtrusionSteepness));

vec3 labsorption = pow(fAtmosphereAbsorptionColor.rgb,vec3(fAtmosphereAbsorptionColor.a*ldepth*0.5*fSelfShadowFactor));
vec3 lscatter = gl_LightSource[0].diffuse.rgb
* dif * labsorption

vec3 lscatter = gl_LightSource[0].diffuse.rgb
* dif * labsorption
* (fMinScatterFactor+min(fMaxScatterFactor*2.0-fMinScatterFactor,2.0*vdepth*ralpha));

vec4 rv;
rv.rgb = regamma( ambient * dif * 0.5
+ atmosphereLighting(scaleAndOffset(fNDotL))
Expand All @@ -96,12 +96,12 @@ vec3 ambientMapping( in vec3 direction )
}

void main()
{
{
vec3 L = normalize(varTSLight);
vec3 V = normalize(varTSView);

vec3 dif = texture2D(baseMap, gl_TexCoord[0].xy, 4.0).rgb;

gl_FragColor = atmosphericScatter( ambientMapping(varWSNormal), dif, V.z, L.z, dot(L,V) );
}

Expand Down
14 changes: 7 additions & 7 deletions programs/planet/atmo_gas_ps2.0.fp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ float cosAngleToDepth(float fNDotV)
vec2 res = vec2(1.0) / vec2(1024.0,128.0);
vec2 mn = res * 0.5;
vec2 mx = vec2(1.0)-res * 0.5;
return expandPrecision(texture2DLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
return expandPrecision(textureLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
}

float cosAngleToAlpha(float fNDotV)
Expand Down Expand Up @@ -74,13 +74,13 @@ vec4 atmosphericScatter(vec3 ambient, vec3 dif, float fNDotV, float fNDotL, floa
float ldepth = cosAngleToLDepth(fNDotL);
float ralpha = cosAngleToAlpha(fNDotV);
ralpha = saturatef(pow(ralpha,fAtmosphereExtrusionSteepness));

vec3 labsorption = pow(fAtmosphereAbsorptionColor.rgb,vec3(fAtmosphereAbsorptionColor.a*ldepth*0.5*fSelfShadowFactor));

vec3 lscatter = gl_LightSource[0].diffuse.rgb
vec3 lscatter = gl_LightSource[0].diffuse.rgb
* dif * labsorption
* (fMinScatterFactor+soft_min(fMaxScatterFactor-fMinScatterFactor,vdepth*ralpha));

vec4 rv;
rv.rgb = regamma( ambient * dif * 0.5
+ atmosphereLighting(scaleAndOffset(fNDotL))
Expand All @@ -96,12 +96,12 @@ vec3 ambientMapping( in vec3 direction )
}

void main()
{
{
vec3 L = normalize(varTSLight);
vec3 V = normalize(varTSView);

vec3 dif = texture2D(baseMap, gl_TexCoord[0].xy, 4.0).rgb;

gl_FragColor = atmosphericScatter( ambientMapping(varWSNormal), dif, V.z, L.z, dot(L,V) );
}

Expand Down
16 changes: 8 additions & 8 deletions programs/planet/atmo_ps2.0.fp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ float cosAngleToDepth(float fNDotV)
vec2 res = vec2(1.0) / vec2(1024.0,128.0);
vec2 mn = res * 0.5;
vec2 mx = vec2(1.0)-res * 0.5;
return expandPrecision(texture2DLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
return expandPrecision(textureLod(cosAngleToDepth_20,clamp(vec2(fNDotV,fAtmosphereHaloType),mn,mx),0.0)) * fAtmosphereHaloThickness;
}

float cosAngleToAlpha(float fNDotV)
Expand Down Expand Up @@ -71,14 +71,14 @@ vec4 atmosphericScatter(vec3 ambient, float fNDotV, float fNDotL, float fLDotV)
float ldepth = cosAngleToLDepth(scaleAndOffset(fNDotL));
float ralpha = cosAngleToAlpha(fNDotV);
ralpha = saturatef(pow(ralpha,fAtmosphereExtrusionSteepness));

vec3 labsorption = pow(fAtmosphereAbsorptionColor.rgb,vec3(fAtmosphereAbsorptionColor.a*ldepth*0.5*fSelfShadowFactor));
vec3 vabsorption = pow(fAtmosphereAbsorptionColor.rgb,vec3(fAtmosphereAbsorptionColor.a*vadepth));
vec3 lscatter = gl_LightSource[0].diffuse.rgb
* fAtmosphereScatterColor.rgb
* labsorption
vec3 lscatter = gl_LightSource[0].diffuse.rgb
* fAtmosphereScatterColor.rgb
* labsorption
* (fMinScatterFactor+soft_min(fMaxScatterFactor*4.0-fMinScatterFactor,4.0*vdepth*ralpha));

vec4 rv;
rv.rgb = regamma( ambient
+ atmosphereLighting(scaleAndOffset(fNDotL))
Expand All @@ -94,10 +94,10 @@ vec3 ambientMapping( in vec3 direction )
}

void main()
{
{
vec3 L = normalize(varTSLight);
vec3 V = normalize(varTSView);

vec4 rv = atmosphericScatter( ambientMapping(varWSNormal), V.z, L.z, dot(L,V) );
gl_FragColor.rgb = (rv.rgb);
gl_FragColor.a = rv.a;
Expand Down
Loading

0 comments on commit 271e91b

Please sign in to comment.