Updated deferred-shading shaders to new format 64/318164/2
authorDavid Steele <david.steele@samsung.com>
Mon, 13 Jan 2025 17:07:07 +0000 (17:07 +0000)
committerDavid Steele <david.steele@samsung.com>
Tue, 21 Jan 2025 13:56:44 +0000 (13:56 +0000)
Issues: Multiple outputs in frag shader are not well supported by
the shader parser. If there is no OUTPUT, then it inserts
gl_FragColor, which is not desired here. So, the first output is
replaced with OUTPUT, and the remaining outputs are left as-is.

Change-Id: Icff6499ded0cea8f4c67459685e99b55ce5edef0
Signed-off-by: David Steele <david.steele@samsung.com>
examples/deferred-shading/shaders/deferred-shading-mainpass.frag
examples/deferred-shading/shaders/deferred-shading-mainpass.vert
examples/deferred-shading/shaders/deferred-shading-prepass.frag
examples/deferred-shading/shaders/deferred-shading-prepass.vert

index 00568618189c8343803b511558583c6f9bc2d921..d7b3372c4efbda9eabba074976bf4aa228906926 100644 (file)
@@ -1,4 +1,4 @@
-#version 300 es
+//@version 100
 
 precision mediump float;
 
@@ -9,12 +9,15 @@ const float kAttenuationLinear = .1f;
 const float kAttenuationQuadratic = .15f;
 
 // G-buffer
-uniform sampler2D uTextureNormal;
-uniform sampler2D uTexturePosition;
-uniform sampler2D uTextureColor;
+UNIFORM sampler2D uTextureNormal;
+UNIFORM sampler2D uTexturePosition;
+UNIFORM sampler2D uTextureColor;
 
-uniform mat4 uInvProjection;
-uniform vec3 uDepth_InvDepth_Near;
+UNIFORM_BLOCK FragBuffer
+{
+  UNIFORM mat4 uInvProjection;
+  UNIFORM vec3 uDepth_InvDepth_Near;
+};
 
 #define DEPTH uDepth_InvDepth_Near.x
 #define INV_DEPTH uDepth_InvDepth_Near.y
@@ -28,10 +31,12 @@ struct Light
   vec3 color;
 };
 
-uniform Light uLights[kMaxLights];
+UNIFORM_BLOCK LightsBuffer
+{
+UNIFORM Light uLights[kMaxLights];
+};
 
-in vec2 vUv;
-out vec4 oColor;
+INPUT vec2 vUv;
 
 vec4 Unmap(vec4 m)  // texture -> projection
 {
@@ -66,7 +71,7 @@ vec3 CalculateLighting(vec3 pos, vec3 normal)
 
 void main()
 {
-  vec3 normSample = texture(uTextureNormal, vUv).xyz;
+  vec3 normSample = TEXTURE(uTextureNormal, vUv).xyz;
   if (dot(normSample, normSample) == 0.f)
   {
     discard;  // if we didn't write this texel, don't bother lighting it.
@@ -74,11 +79,11 @@ void main()
 
   vec3 normal = normalize(normSample - .5f);
 
-  vec4 posSample = texture(uTexturePosition, vUv);
+  vec4 posSample = TEXTURE(uTexturePosition, vUv);
   vec3 pos = (uInvProjection * Unmap(posSample)).xyz;
 
-  vec3 color = texture(uTextureColor, vUv).rgb;
+  vec3 color = TEXTURE(uTextureColor, vUv).rgb;
   vec3 finalColor = color * CalculateLighting(pos, normal);
 
-  oColor = vec4(finalColor, 1.f);
+  gl_FragColor = vec4(finalColor, 1.f);
 }
index 57544d9d68f5d04c6cbde65fd145d36fc3ba11ed..5ee3036bde58bcb6225c7de8f2d0de6e4eb47042 100644 (file)
@@ -1,14 +1,18 @@
-#version 300 es
+//@version 100
+
 precision mediump float;
 
 // DALI uniforms
-uniform mat4 uMvpMatrix;
-uniform vec3 uSize;
+UNIFORM_BLOCK VertBuffer
+{
+UNIFORM mat4 uMvpMatrix;
+UNIFORM vec3 uSize;
+};
 
-in vec3 aPosition;
-in vec2 aTexCoord;
+INPUT vec3 aPosition;
+INPUT vec2 aTexCoord;
 
-out vec2 vUv;
+OUTPUT vec2 vUv;
 
 void main()
 {
index 82f7c3bdd47d54198ed31fb5c77bf52dd8b34a47..7c01ebad8fef71cbd818fdfd830a80fb1537e0d0 100644 (file)
@@ -1,16 +1,20 @@
-#version 300 es
+//@version 100
+
 precision mediump float;
 
 // DALI uniform
-uniform vec4 uColor;
+UNIFORM_BLOCK FragBuffer
+{
+  UNIFORM vec4 uColor;
+};
 
-in vec4 vPosition;
-in vec3 vNormal;
+INPUT vec4 vPosition;
+INPUT vec3 vNormal;
 
 // These are our outputs.
-layout(location = 0) out vec3 oNormal;
-layout(location = 1) out vec4 oPosition;
-layout(location = 2) out vec3 oColor;
+OUTPUT vec3 oNormal;
+layout(location=1) out vec4 oPosition;
+layout(location=2) out vec3 oColor;
 
 void main()
 {
index cb61ce9096fc7eb0888b4e726826efa8b261c42e..cc963cfa1ee351a379be3fd2035940a8facf0972 100644 (file)
@@ -1,23 +1,25 @@
-#version 300 es
+//@version 100
 
 precision mediump float;
 
 // DALI uniforms
-uniform mat4 uMvpMatrix;
-uniform mat3 uNormalMatrix;
-uniform vec3 uSize;
-
-uniform vec3 uDepth_InvDepth_Near;
+UNIFORM_BLOCK VertBuffer
+{
+UNIFORM mat4 uMvpMatrix;
+UNIFORM mat3 uNormalMatrix;
+UNIFORM vec3 uSize;
 
+UNIFORM vec3 uDepth_InvDepth_Near;
+};
 #define DEPTH uDepth_InvDepth_Near.x
 #define INV_DEPTH uDepth_InvDepth_Near.y
 #define NEAR uDepth_InvDepth_Near.z
 
-in vec3 aPosition;
-in vec3 aNormal;
+INPUT vec3 aPosition;
+INPUT vec3 aNormal;
 
-out vec4 vPosition;
-out vec3 vNormal;
+OUTPUT vec4 vPosition;
+OUTPUT vec3 vNormal;
 
 vec4 Map(vec4 v) // projection space -> texture
 {