Good afternoon.
I have a GI system using Enlighten, however the reflexes are getting into the wrong positions in relation to the world. I believe it is a problem with some position matrix I am using.
GI:
float3 SampleEnvironment (Surface surfaceWS, BRDF brdf) {
float3 uvw = reflect(-surfaceWS.viewDirection, surfaceWS.normal);
float mip = PerceptualRoughnessToMipmapLevel(brdf.perceptualRoughness);
float4 environment = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, uvw, mip);
return DecodeHDREnvironment(environment, unity_SpecCube0_HDR);
}
Shader:
struct Attributes {
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
float2 baseUV : TEXCOORD0;
float2 lightmapUV: TEXCOORD1;
float2 dynamicLightmapUV : TEXCOORD2;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings {
float4 positionCS : SV_POSITION;
float3 positionWS : VAR_POSITION;
float3 normalWS : VAR_NORMAL;
float4 tangentWS : VAR_TANGENT;
float2 baseUV : VAR_BASE_UV;
//#if defined(LIGHTMAP_ON)
float2 lightmapUV : TEXCOORD4;
//#endif
//#if defined(DYNAMICLIGHTMAP_ON)
float2 dynamicLightmapUV : TEXCOORD5;
//#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings LitPassVertex (Attributes input) {
UNITY_SETUP_INSTANCE_ID(input);
Varyings output;
output.lightmapUV = input.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
output.dynamicLightmapUV = input.dynamicLightmapUV * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
output.positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(output.positionWS);
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
output.baseUV = input.baseUV;
return output;
}
Pixel Shader:
float4 NmapSec = SAMPLE_TEXTURE2D(_NormalSecond, sampler_NormalSecond, NormalSecUV);
float scaleSec = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _NormalSecondStrength);
float3 normalSec = DecodeNormal(NmapSec, scaleSec);
water.metallic = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Metallic);
water.smoothness = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Smoothness);
float3 normal = BlendNormalRNM(normalMain, normalSec);
water.normal = NormalTangentToWorld(normal, input.normalWS, input.tangentWS);
water.fresnelStrength = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Fresnel);
water.color = lerp(UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _WaterDistanceColor),
lerp(UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _WaterBaseColor), UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _WaterBlendColor),
Fresnel(water.fresnelStrength, NormalTangentToWorld(water.normal, input.normalWS, input.tangentWS), normalize(_WorldSpaceCameraPos - input.positionWS))),
input.baseUV.y);
water.interpolatedNormal = input.normalWS;
water.viewDirection = normalize(_WorldSpaceCameraPos - input.positionWS);
I am also having a similar problem with Fresnel.