Comments (3)
I made some changes recently that should have reduced register usage, if you still have a shader that has problems can you share the code, or a cut down version of the shader that has the same issue so I can investigate it?
from glsl2agal.
Hi Alex, here's the sample code that doesn't compile with latest swc.
#define float4 vec4
#define float3 vec3
#define float2 vec2
#define frac fract
uniform mat4 g_ViewMatrixInv;
uniform mat4 g_ShadowMapMatrix;
uniform float4 g_CameraPosition;
uniform float4 g_LightDirection;
uniform float4 g_LightColor;
uniform float4 g_AmbientSHR;
uniform float4 g_AmbientSHG;
uniform float4 g_AmbientSHB;
uniform float4 g_ParametersPS;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform sampler2D shadowmap;
uniform sampler2D randommap;
uniform float4 g_DecodeShadowDepthValues;
uniform float4 g_DecodeGBufferParameters;
uniform float4 g_TexCoordHelpers;
uniform float4 g_Helpers;
#define positionES tempD
void main()
{
// First we read the gbuffer, then we decode it since is attributes are packed tight
float4 gb0= texture2D(gbuffer0, gl_TexCoord[0].xy);
float4 gb1= texture2D(gbuffer1, gl_TexCoord[0].xy);
float4 tempA = texture2D(shadowmap, gl_TexCoord[0].xy);
//float shadowValue = tempA.x;//dot(tempA.xyzw, tempA.xyzw);
float4 tempB;
// GBuffer attributes to decode
float4 albedo;
float4 normalWS;
float4 positionWS;
//float specularPower = 32;
//float specularFactor = 1;
// Lets decode the normal in World Space
normalWS.xyz = gb0.xyz * g_DecodeGBufferParameters.xxx - g_DecodeGBufferParameters.yyy;
normalWS.w= g_DecodeGBufferParameters.y;
// Lets decode the Albedo and specular attributes
// The Albedo is packed using the lower 6 bits of rgb gbuffer1 channel
// The specular factor and power use the higher 2 bits of gbuffer1 rgb channels
// The specular factor is split between rg and the power is on the blue channel
albedo.rgb= fract(gb1.rgb * g_DecodeGBufferParameters.www);
//float3 specAux = tempA.rgb - albedo.rgb;
//specularPower = specAux.r + specAux.g * g_Helpers.w;
//specularFactor = specAux.b;
// Lets reconstruct the fragment world position using the encoded depth
tempA.w = gb0.w + gb1.w * g_DecodeShadowDepthValues.y;
tempB.x = gl_TexCoord[1].x * tempA.w;
tempB.y = gl_TexCoord[1].y * tempA.w;
tempB.z = gl_TexCoord[1].z * tempA.w;
tempB.w = g_DecodeGBufferParameters.y;
positionWS = tempB * g_ViewMatrixInv;
// Calculate Shadows
tempB= positionWS * g_ShadowMapMatrix;
//tempA.xy = texture2D(randommap, gl_TexCoord[0].zw).xy * g_TexCoordHelpers.zw;
tempB.xy = (tempB.xy / tempB.w) * g_TexCoordHelpers.xy + g_TexCoordHelpers.xx;// + tempA.xy;
float4 sm = texture2D(shadowmap, tempB.xy);
float smDepth = dot(sm.xyz, g_DecodeShadowDepthValues.xyz);
float shadowValue = 1;//smDepth - tempB.z;//smDepth;
if(smDepth < tempB.z) shadowValue = 0;
// Now that we have all the GBuffer attributes decoded now lets do the lighting and shading stuff
float NdotL = dot(g_LightDirection.xyz, normalWS.xyz);
NdotL *= shadowValue;
// Accumulate lighting
tempA.xyz = NdotL * g_LightColor.xyz;
tempA.x+= dot(normalWS, g_AmbientSHR);
tempA.y+= dot(normalWS, g_AmbientSHG);
tempA.z+= dot(normalWS, g_AmbientSHB);
float3 finalColor;
finalColor.rgb = albedo.rgb * tempA.xyz;
// Calculate the eye and half vector
tempA.w= dot(normalize(normalize(g_CameraPosition.xyz - positionWS.xyz).xyz + g_LightDirection.xyz), normalWS.xyz);
gl_FragColor = finalColor.rgbg + vec4(pow(tempA.w, 32));
};
from glsl2agal.
As a temporary workaround you can replace this:
tempA.x+= dot(normalWS, g_AmbientSHR);
tempA.y+= dot(normalWS, g_AmbientSHG);
tempA.z+= dot(normalWS, g_AmbientSHB);
with:
tempA.xyz += vec3(
dot(normalWS, g_AmbientSHR),
dot(normalWS, g_AmbientSHG),
dot(normalWS, g_AmbientSHB));
But some work on the optimizer should be able to fix this
from glsl2agal.
Related Issues (20)
- Flascc compiler error? (java.lang.NullPointerException) HOT 1
- Swizzling not working like in AGALMiniAssembler HOT 5
- Instruction node present twice in ir tree HOT 2
- Possible to overwrite existing GLSL functions, end up with invalid AGAL
- Combining multiple non-vec4 constants HOT 2
- Multiple y per register? HOT 1
- Using dot production results in unexpected AGAL code HOT 1
- In Stage3d the only way to configure the sampler seems to be through agal. How do we deal we that ? HOT 3
- Code generation problem HOT 1
- Feature request: Support for AGAL MRT HOT 3
- Possible sat optimisation?
- Many matrix operations are translated into illegal AGAL code
- Optimization throws exception
- length, distance, normalize return wrong result for certain vectors.
- Can't compile shader with struct uniform
- conditional branching
- floor() seems to be broken as well
- vertex attribute order be changed
- Is this fork still active?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glsl2agal.