OpenGL在Android模拟器上出现了顶点着色器问题,期望类型名。

huangapple go评论59阅读模式
英文:

Open GL problem with vertex shader on android emulator, typename expected

问题

我对着色器了解很少,而且这不是我的代码。它无法在我的模拟器上加载,并生成一个日志文件中的错误。为了更详细地说明问题,我正在使用DS游戏的Drastic模拟器,这只是一个用于该模拟器的滤镜或着色器,但似乎无法加载。

日志文件显示:
0:18: L0001: 期望类型名称,找到 '\'

因此,我正在寻找问题所在...

我尝试了很少,因为我了解得很少:
首先,我尝试稍微更改代码,日志之前显示找到 "if",所以我将它移到下面看看是否会有所作为,结果是找到 "\ ",现在我不知道了,因为我很愚蠢...
代码保存在扩展名为 .dsd 的文件中,如下所示:

<vertex>

attribute vec2 a_vertex_coordinate;
attribute vec2 a_texture_coordinate;
	
uniform vec4 u_texture_size;
varying vec4 v_texture_coordinate;
varying vec4 v_texture_coordinate_1;

void main()
{
	vec2 ps = vec2(1.0 / u_texture_size.z, 1.0 / u_texture_size.w);
	float dx = ps.x;
	float dy = ps.y;
	gl_Position = vec4(a_vertex_coordinate.xy, 0.0, 1.0);
	v_texture_coordinate = a_texture_coordinate.xyxy;
	v_texture_coordinate_1.xy = vec2(0.0,-dy); // B
	v_texture_coordinate_1.zw = vec2(-dx,0.0); // D
}
</vertex>
<fragment>
	const vec3 dtt = vec3(65536.0, 255.0, 1.0);

	float reduce(vec3 color) {
		return dot(color, dtt);
	}
uniform sampler2D u_texture;
uniform vec4 u_texture_size;
varying vec4 v_texture_coordinate;
varying vec4 v_texture_coordinate_1;

#define FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, C1, I4, I5, N15, N14, N11, F, H)
\
	if ( PE!=PH &amp;&amp; ((PH==PF &amp;&amp; ( (PE!=PI &amp;&amp; (PE!=PB || PE!=PD || PB==C1 &amp;&amp; PD==G0 || PF!=PB &amp;&amp; PF!=PC || PH!=PD &amp;&amp; PH!=PG)) \
	   || (PE==PG &amp;&amp; (PI==PH || PE==PD || PH!=PD)) \
	   || (PE==PC &amp;&amp; (PI==PH || PE==PB || PF!=PB)) ))\
	   || (PE!=PF &amp;&amp; (PE==PC &amp;&amp; (PF!=PI &amp;&amp; (PH==PI &amp;&amp; PF!=PB || PE!=PI &amp;&amp; PF==C4) || PE!=PI &amp;&amp; PE==PG)))) ) \
                 {\
	                N11 = (N11+F)*0.5;\
        	        N14 = (N14+H)*0.5;\
                	N15 = F;\
                 }\
	else if (PE!=PH &amp;&amp; PE!=PF &amp;&amp; (PH!=PI &amp;&amp; PE==PG &amp;&amp; (PF==PI &amp;&amp; PH!=PD || PE!=PI &amp;&amp; PH==G5)))\
	{\
                N11 = (N11+H)*0.5;\
                N14 = N11;\
                N15 = H;\
	}\
	
void main()
{
	vec2 fp = fract(v_texture_coordinate.xy * u_texture_size.zw);
	
	vec2 g1 = v_texture_coordinate_1.xy * (step(0.5,fp.x) + step(0.5, fp.y) - 1.0) + v_texture_coordinate_1.zw * (step(0.5,fp.x) - step(0.5, fp.y));
	vec2 g2 = v_texture_coordinate_1.xy * (step(0.5,fp.y) - step(0.5, fp.x)) + v_texture_coordinate_1.zw * (step(0.5,fp.x) + step(0.5, fp.y) - 1.0);
		
	vec3 A = texture2D(u_texture, v_texture_coordinate.xy + g1 + g2 ).xyz;
	vec3 B = texture2D(u_texture, v_texture_coordinate.xy + g1      ).xyz;
	vec3 C = texture2D(u_texture, v_texture_coordinate.xy + g1 - g2 ).xyz;
	vec3 D = texture2D(u_texture, v_texture_coordinate.xy      + g2 ).xyz;
	vec3 E = texture2D(u_texture, v_texture_coordinate.xy           ).xyz;
	vec3 F = texture2D(u_texture, v_texture_coordinate.xy      - g2 ).xyz;
	vec3 G = texture2D(u_texture, v_texture_coordinate.xy - g1 + g2 ).xyz;
	vec3 H = texture2D(u_texture, v_texture_coordinate.xy - g1      ).xyz;
	vec3 I = texture2D(u_texture, v_texture_coordinate.xy - g1 - g2 ).xyz;
	
	vec3 A1 = texture2D(u_texture, v_texture_coordinate.xy + 2.0 * g1 + g2 ).xyz;
	vec3 C1 = texture2D(u_texture, v_texture_coordinate.xy + 2.0 * g1 - g2 ).xyz;
	vec3 A0 = texture2D(u_texture, v_texture_coordinate.xy + g1 + 2.0 * g2 ).xyz;
	vec3 G0 = texture2D(u_texture, v_texture_coordinate.xy - g1 + 2.0 * g2 ).xyz;
	vec3 C4 = texture2D(u_texture, v_texture_coordinate.xy + g1 - 2.0 * g2 ).xyz;
	vec3 I4 = texture2D(u_texture, v_texture_coordinate.xy - g1 - 2.0 * g2 ).xyz;
	vec3 G5 = texture2D(u_texture, v_texture_coordinate.xy - 2.0 * g1 + g2 ).xyz;
	vec3 I5 = texture2D(u_texture, v_texture_coordinate.xy - 2.0 * g1 - g2 ).xyz;
		
	vec3 E11 = E;
	vec3 E14 = E;
	vec3 E15 = E;
		
	float a = reduce(A);	
	float b = reduce(B);
	float c = reduce(C);
	float d = reduce(D);
	float e = reduce(E);
	float f = reduce(F);
	float g = reduce(G);
	float h = reduce(H);
	float i = reduce(I);
		
	float  a1 = reduce

<details>
<summary>英文:</summary>

I have very little understanding about shaders and this one is not mine. It just can&#39;t be loaded on my emulator and it gives me an error in the form of a log file. To elaborate more on the problem: i&#39;m using the Drastic emulator for DS games, this is only a filter o shader for such emulator but i doesn&#39;t seem to load. 
The log file says:
0:18: L0001: Typename expected, found &#39;\\&#39;
So i&#39;m asking to see where the problem is... 

I tried very little, since i know very little:
First i tried changing a bit the code, before the log said it found &quot;if&quot; so i moved it down to see if it would do something and it resulted in founding &quot;\\&quot; and now i don&#39;t know anymore since i&#39;m stupid... 
The code is in a file with the extension .dsd and is the following:

<vertex>

attribute vec2 a_vertex_coordinate;
attribute vec2 a_texture_coordinate;

uniform vec4 u_texture_size;
varying vec4 v_texture_coordinate;
varying vec4 v_texture_coordinate_1;

void main()
{
vec2 ps = vec2(1.0 / u_texture_size.z, 1.0 / u_texture_size.w);
float dx = ps.x;
float dy = ps.y;
gl_Position = vec4(a_vertex_coordinate.xy, 0.0, 1.0);
v_texture_coordinate = a_texture_coordinate.xyxy;
v_texture_coordinate_1.xy = vec2(0.0,-dy); // B
v_texture_coordinate_1.zw = vec2(-dx,0.0); // D
}
</vertex>
<fragment>
const vec3 dtt = vec3(65536.0, 255.0, 1.0);

float reduce(vec3 color) {
return dot(color, dtt);
}

uniform sampler2D u_texture;
uniform vec4 u_texture_size;
varying vec4 v_texture_coordinate;
varying vec4 v_texture_coordinate_1;

#define FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, C1, I4, I5, N15, N14, N11, F, H)

if ( PE!=PH && ((PH==PF && ( (PE!=PI && (PE!=PB || PE!=PD || PB==C1 && PD==G0 || PF!=PB && PF!=PC || PH!=PD && PH!=PG))
|| (PE==PG && (PI==PH || PE==PD || PH!=PD))
|| (PE==PC && (PI==PH || PE==PB || PF!=PB)) ))
|| (PE!=PF && (PE==PC && (PF!=PI && (PH==PI && PF!=PB || PE!=PI && PF==C4) || PE!=PI && PE==PG)))) )
{
N11 = (N11+F)*0.5;
N14 = (N14+H)*0.5;
N15 = F;
}
else if (PE!=PH && PE!=PF && (PH!=PI && PE==PG && (PF==PI && PH!=PD || PE!=PI && PH==G5)))
{
N11 = (N11+H)*0.5;
N14 = N11;
N15 = H;
}\

void main()
{
vec2 fp = fract(v_texture_coordinate.xy * u_texture_size.zw);

vec2 g1 = v_texture_coordinate_1.xy * (step(0.5,fp.x) + step(0.5, fp.y) - 1.0) + v_texture_coordinate_1.zw * (step(0.5,fp.x) - step(0.5, fp.y));
vec2 g2 = v_texture_coordinate_1.xy * (step(0.5,fp.y) - step(0.5, fp.x)) + v_texture_coordinate_1.zw * (step(0.5,fp.x) + step(0.5, fp.y) - 1.0);
vec3 A = texture2D(u_texture, v_texture_coordinate.xy + g1 + g2 ).xyz;
vec3 B = texture2D(u_texture, v_texture_coordinate.xy + g1      ).xyz;
vec3 C = texture2D(u_texture, v_texture_coordinate.xy + g1 - g2 ).xyz;
vec3 D = texture2D(u_texture, v_texture_coordinate.xy      + g2 ).xyz;
vec3 E = texture2D(u_texture, v_texture_coordinate.xy           ).xyz;
vec3 F = texture2D(u_texture, v_texture_coordinate.xy      - g2 ).xyz;
vec3 G = texture2D(u_texture, v_texture_coordinate.xy - g1 + g2 ).xyz;
vec3 H = texture2D(u_texture, v_texture_coordinate.xy - g1      ).xyz;
vec3 I = texture2D(u_texture, v_texture_coordinate.xy - g1 - g2 ).xyz;
vec3 A1 = texture2D(u_texture, v_texture_coordinate.xy + 2.0 * g1 + g2 ).xyz;
vec3 C1 = texture2D(u_texture, v_texture_coordinate.xy + 2.0 * g1 - g2 ).xyz;
vec3 A0 = texture2D(u_texture, v_texture_coordinate.xy + g1 + 2.0 * g2 ).xyz;
vec3 G0 = texture2D(u_texture, v_texture_coordinate.xy - g1 + 2.0 * g2 ).xyz;
vec3 C4 = texture2D(u_texture, v_texture_coordinate.xy + g1 - 2.0 * g2 ).xyz;
vec3 I4 = texture2D(u_texture, v_texture_coordinate.xy - g1 - 2.0 * g2 ).xyz;
vec3 G5 = texture2D(u_texture, v_texture_coordinate.xy - 2.0 * g1 + g2 ).xyz;
vec3 I5 = texture2D(u_texture, v_texture_coordinate.xy - 2.0 * g1 - g2 ).xyz;
vec3 E11 = E;
vec3 E14 = E;
vec3 E15 = E;
float a = reduce(A);	
float b = reduce(B);
float c = reduce(C);
float d = reduce(D);
float e = reduce(E);
float f = reduce(F);
float g = reduce(G);
float h = reduce(H);
float i = reduce(I);
float  a1 = reduce( A1);
float  c1 = reduce( C1);
float  a0 = reduce( A0);
float  g0 = reduce( G0);
float  c4 = reduce( C4);
float  i4 = reduce( I4);
float  g5 = reduce( G5);
float  i5 = reduce( I5);
FILTRO(e, i, h, f, g, c, d, b, a, g5, c4, g0, c1, i4, i5, E15, E14, E11, F, H);
gl_FragColor.rgb = (fp.x &lt; 0.50) ? ((fp.x &lt; 0.25) ? ((fp.y &lt; 0.25) ? E15: (fp.y &lt; 0.50) ? E11: (fp.y &lt; 0.75) ? E14: E15) : ((fp.y &lt; 0.25) ? E14: (fp.y &lt; 0.50) ? E  : (fp.y &lt; 0.75) ? E  : E11)) : ((fp.x &lt; 0.75) ? ((fp.y &lt; 0.25) ? E11: (fp.y &lt; 0.50) ? E  : (fp.y &lt; 0.75) ? E   : E14) : ((fp.y &lt; 0.25) ? E15: (fp.y &lt; 0.50) ? E14: (fp.y &lt; 0.75) ? E11 : E15));

}
</fragment>


This code is used from the .dfx file if i&#39;m not mistaken, so here&#39;s also the dfx:

<options>
name=4XBR v1.1 Low configuration
textures=1
</options>

<fheader>
#if GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
</fheader>

<texture:0>
input=framebuffer
min_filter=GL_NEAREST
mag_filter=GL_NEAREST
</texture>

<pass>
shader=4XBR_v1.1_Low configuration.dsd
sampler:u_texture=0
</pass>

This should be everything i have gone through, if anyone can help me it would be immensely appreciated, thanks! 
</details>
# 答案1
**得分**: 0
根据所使用的命名,此着色器使用OpenGL ES 2.0着色器语言(`#version 100`)。在ESSL 1.0中不支持行继续,因此此着色器依赖供应商扩展或超出规范的行为。
在OpenGL ES 3.0着色器语言中(`#version 300 es`)添加了行继续支持,但如果启用它,您需要修复着色器的其余部分的输入和输出声明,以使用新的样式(使用`in`而不是`varying`,显式的`out`变量而不是`gl_FragCoord`),并需要ES 3.0上下文。
解决方法是将`FILTRO()`宏展开为单行,以避免行继续(在Mali离线编译器上进行本地测试,它可以成功编译)。
<details>
<summary>英文:</summary>
Based on the naming used this shader is using the OpenGL ES 2.0 shader language (`#version 100`). Line continuation isn&#39;t supported in ESSL 1.0, so this shader is relying on a vendor extension or out-of-spec behavior. 
Line continuation support was added in OpenGL ES 3.0 shader language (#version 300 es), but if you enable that you need to fix the rest of the shader input and output declarations to use the new style (`in` rather than `varying`, explicit `out` variable rather than `gl_FragCoord`), and need an ES 3.0 context.
The workaround would be to flatten the `FILTRO()` macro to be a single line to avoid the line continuations (tested locally here on the Mali Offline Compiler and it compiles OK).
</details>

huangapple
  • 本文由 发表于 2023年2月14日 20:30:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75447856.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定