Skip to content

Commit

Permalink
[rend2] Fixing local position based rgb and tc Gens
Browse files Browse the repository at this point in the history
  • Loading branch information
SomaZ committed Apr 17, 2024
1 parent b688bdf commit 433837f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions shared/rd-rend2/glsl/generic.glsl
Expand Up @@ -283,7 +283,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED:
{
vec3 viewer = normalize(u_ViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).yz;
tex.s = ref.x * -0.5 + 0.5;
tex.t = ref.y * 0.5 + 0.5;
Expand All @@ -292,7 +293,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED_SP:
{
vec3 viewer = normalize(u_ViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).xy;
tex.s = ref.x * -0.5;
tex.t = ref.y * -0.5;
Expand Down Expand Up @@ -379,7 +381,8 @@ vec4 CalcColor(vec3 position, vec3 normal)
return color;
}

vec3 viewer = u_ViewOrigin - position;
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = localOrigin - position;

if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
{
Expand Down Expand Up @@ -441,7 +444,7 @@ void main()
gl_Position = u_viewProjectionMatrix * wsPosition;

#if defined(USE_TCGEN)
vec2 tex = GenTexCoords(u_TCGen0, wsPosition.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
#else
vec2 tex = attr_TexCoord0.st;
#endif
Expand All @@ -464,7 +467,7 @@ void main()
else
{
#if defined(USE_RGBAGEN)
var_Color = CalcColor(wsPosition.xyz, normal);
var_Color = CalcColor(position.xyz, normal);
#else
var_Color = u_VertColor * attr_Color + u_BaseColor;
#endif
Expand Down
8 changes: 5 additions & 3 deletions shared/rd-rend2/glsl/lightall.glsl
Expand Up @@ -157,7 +157,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED:
{
vec3 viewer = normalize(u_ViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).yz;
tex.s = ref.x * -0.5 + 0.5;
tex.t = ref.y * 0.5 + 0.5;
Expand All @@ -166,7 +167,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED_SP:
{
vec3 viewer = normalize(u_ViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).xy;
tex.s = ref.x * -0.5;
tex.t = ref.y * -0.5;
Expand Down Expand Up @@ -259,7 +261,7 @@ void main()
vec4 wsPosition = u_ModelMatrix * vec4(position, 1.0);

#if defined(USE_TCGEN)
vec2 texCoords = GenTexCoords(u_TCGen0, wsPosition.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
vec2 texCoords = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
#else
vec2 texCoords = attr_TexCoord0.st;
#endif
Expand Down

0 comments on commit 433837f

Please sign in to comment.