Quantcast
Channel: Questions in topic: "hlsl"
Viewing all articles
Browse latest Browse all 206

Make my volumetric cloud code cast shadows

$
0
0
Hi, I have a cloud rendering shader that uses 3d noise and raymarching. It's a screen-wide frag shader, base on this tutorial: https://www.youtube.com/watch?v=4QOcCGI6xOU ---------- Currently, I illuminate the clouds using yet more raymarching. I have two problems with that, first it's expensive, second my clouds don't cast any shadows. ---------- I want to basically tell Unity to write to the dynamic lightmap, and use it to abort the lightmarching if I know I'm the shadow of the cloud. I have little idea on how to do that, except vaguely that adding a shadow pass to the shader will tell unity to do that. Here's my current code structure, minus the very long raymarching code: Shader "Jupiter/Clouds" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { // No culling or depth Cull Off ZWrite Off ZTest Always Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #include "Assets/Scripts/Clouds/Shaders/CloudDebug.cginc" // vertex input: position, UV struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float3 viewVector : TEXCOORD1; }; v2f vert (appdata v) { v2f output; output.pos = UnityObjectToClipPos(v.vertex); output.uv = v.uv; // Camera space matches OpenGL convention where cam forward is -z. In unity forward is positive z. // (https://docs.unity3d.com/ScriptReference/Camera-cameraToWorldMatrix.html) float3 viewVector = mul(unity_CameraInvProjection, float4(v.uv * 2 - 1, 0, -1)); output.viewVector = mul(unity_CameraToWorld, float4(viewVector,0)); return output; } // Textures Texture3D NoiseTex; Texture3D DetailNoiseTex; Texture2D WeatherMap; Texture2D BlueNoise; SamplerState samplerNoiseTex; SamplerState samplerDetailNoiseTex; SamplerState samplerWeatherMap; SamplerState samplerBlueNoise; sampler2D _MainTex; sampler2D _CameraDepthTexture; //tons of parameters float4 frag (v2f i) : SV_Target { //blablabla return float4(col,0); } ENDCG } } }

Viewing all articles
Browse latest Browse all 206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>