- Home /
Where Is UNITY_POSITION(pos) Defined?
Hi All,
I was hoping to copy and modify the following fragment shader in UnityStandardCoreForwardSimple.cginc:
half4 fragForwardBaseSimpleInternal (VertexOutputBaseSimple i)
{
UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy);
FragmentCommonData s = FragmentSetupSimple(i);
UnityLight mainLight = MainLightSimple(i, s);
#if !defined(LIGHTMAP_ON) && defined(_NORMALMAP)
half ndotl = saturate(dot(s.tangentSpaceNormal, i.tangentSpaceLightDir));
#else
half ndotl = saturate(dot(s.normalWorld, mainLight.dir));
#endif
//we can't have worldpos here (not enough interpolator on SM 2.0) so no shadow fade in that case.
half shadowMaskAttenuation = UnitySampleBakedOcclusion(i.ambientOrLightmapUV, 0);
half realtimeShadowAttenuation = SHADOW_ATTENUATION(i);
half atten = UnityMixRealtimeAndBakedShadows(realtimeShadowAttenuation, shadowMaskAttenuation, 0);
half occlusion = Occlusion(i.tex.xy);
half rl = dot(REFLECTVEC_FOR_SPECULAR(i, s), LightDirForSpecular(i, mainLight));
UnityGI gi = FragmentGI (s, occlusion, i.ambientOrLightmapUV, atten, mainLight);
half3 attenuatedLightColor = gi.light.color * ndotl;
half3 c = BRDF3_Indirect(s.diffColor, s.specColor, gi.indirect, PerVertexGrazingTerm(i, s), PerVertexFresnelTerm(i));
c += BRDF3DirectSimple(s.diffColor, s.specColor, s.smoothness, rl) * attenuatedLightColor;
c += Emission(i.tex.xy);
UNITY_APPLY_FOG(i.fogCoord, c);
return OutputForward (half4(c, 1), s.alpha);
}
But I get an error stating it doesn't recognize VertexOutputBaseSimple
. If I include that it reads, "unrecognized identifier UNITY_POSITION(pos)
".
If anyone can point me in the correct direction I would greatly appreciate it!
Thanks,
Answer by Bunny83 · Jul 20, 2017 at 09:33 AM
"UNITY_POSITION" doesn't exist in any cg include that is shipped with Unity. You can't just copy a single method out of an include file. You can of course copy and paste the method into your own shader and "rename" that method. In addition you should simply include that file in your shader (that's the main point of include files -.-)
So do a
#include "UnityStandardCoreForwardSimple.cginc"
at the top of your CG code and keep in mind when you copy that method in order to apply some changes to it, you should rename it.
Hi @Bunny83 , yeah I tried that earlier and it spawned more errors including tangentToWorldAndPackedData
from the s.posWorld = IN_WORLDPOS(i);
line in the file (function: FragmentCommonData FragmentSetupSimple(VertexOutputBaseSimple i) { ... }
).
I was hoping to basically just pull over the fragment and write a modification into the standard shader but I'm encountering some hurdles I can't leap so I was just hoping someone could point me toward a direction I could move in.
Your answer
![](https://koobas.hobune.stream/wayback/20220612130702im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Access to svPosition in fragment shader 1 Answer
Projected Texture Shader Issues 1 Answer
how to approach instanceID in shader? 0 Answers
How do you change Point Size in Direct3d 11 shader? 1 Answer